Pro Android with Kotlin


CHAPTER 9: User Interface


Download 5.42 Mb.
Pdf ko'rish
bet185/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   181   182   183   184   185   186   187   188   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile



227
CHAPTER 9: User Interface
Applying projection to three-dimensional objects makes more sense. As a general 
assumption for such 3D objects, we expect the following:

Vertex coordinates in four-dimensional homogeneous coordinates

RGBA colors assigned to vertices

Face normals assigned to vertices
Using four coordinate values instead of the usual three (x, y, z) helps for perspective 
projection. Colors assigned to vertices can be used from inside the shader code to apply a 
coloring scheme. But it can also be ignored or used for noncoloring purposes. This is totally 
up to the shader code. The normals help for a realistic lighting.
The renderer gets just new shader code, as shown here:
val vertexShaderCode = """
attribute vec4 vPosition;
attribute vec4 vNorm;
attribute vec4 vColor;
varying vec4 fColor;
varying vec4 fNorm;
uniform mat4 uMVPMatrix;
void main() {
gl_Position = uMVPMatrix * vPosition;
fColor = vColor;
fNorm = vNorm;
}
""".trimIndent()
val fragmentShaderCode = """
precision mediump float;
varying vec4 fColor;
varying vec4 fNorm;
void main() {
gl_FragColor = fColor;
}
""".trimIndent()
As a sample 3D object, I present a cube with an interpolated coloring according to the vertex 
colors and the normals ignored for now.
class Cube(val program: Int?, val vertBuf:Int,
val idxBuf:Int) {
val vertexBuffer: FloatBuffer
val drawListBuffer: ShortBuffer



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   181   182   183   184   185   186   187   188   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling