VertexNX# ( surface,index )
Parameters
|
surface - surface handle index - index of the vertex, from 0 to CountVertices( surface )-1 |
Description
|
Returns the x component of a vertex's normal. The normal is the direction the vertex faces for lighting - set by the model file, by VertexNormal, or calculated by UpdateNormals. Vertices you add yourself start with a normal of 0,0,0 until one of those happens. Reading normals back is useful for effects that push vertices "outwards" along their normals, such as shell or inflate effects. See also: VertexNY, VertexNZ, VertexNormal, UpdateNormals. |
Example
; VertexNX Example ; ---------------- ; Every vertex stores a position, a normal, a colour and a set of ; uv texture coordinates. VertexNX reads back the x component of one vertex normal. ; Space steps the magenta marker through the pyramid's five vertices. Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,1,-4 light=CreateLight() RotateEntity light,45,45,0 ; A small pyramid: base corners v0-v3 and apex v4 mesh=CreateMesh() surf=CreateSurface(mesh) v0=AddVertex(surf,-1,0,-1,0,1) v1=AddVertex(surf,1,0,-1,1,1) v2=AddVertex(surf,1,0,1,1,0) v3=AddVertex(surf,-1,0,1,0,0) v4=AddVertex(surf,0,1.5,0,0.5,0.5) EntityColor mesh,230,170,80 ; Sides then base, wound clockwise seen from outside AddTriangle surf,v0,v4,v1 AddTriangle surf,v1,v4,v2 AddTriangle surf,v2,v4,v3 AddTriangle surf,v3,v4,v0 AddTriangle surf,v2,v1,v0 AddTriangle surf,v3,v2,v0 ; Calculate outward-facing normals from the triangle shapes UpdateNormals mesh ; A marker sphere parented to the mesh highlights the queried vertex marker=CreateSphere() ScaleEntity marker,0.1,0.1,0.1 EntityColor marker,255,0,255 EntityFX marker,1 EntityParent marker,mesh index=0 While Not KeyDown(1) ; Space cycles through vertices 0-4 If KeyHit(57) Then index=(index+1) Mod 5 ; Query the highlighted vertex - the documented command value#=VertexNX(surf,index) ; Park the marker on the queried vertex (local mesh coordinates) PositionEntity marker,VertexX(surf,index),VertexY(surf,index),VertexZ(surf,index) TurnEntity mesh,0,1,0 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Space: next vertex Arrow keys: move camera Esc: exit" Text 0,20,"VertexNX(surf,"+index+") = "+value Text 0,40,"Normals here were calculated by UpdateNormals" Flip Wend End
Index