Blitz3D+ Command Reference

VertexY# ( surface,index )

Parameters

surface - surface handle
index - index of the vertex, from 0 to CountVertices( surface )-1

Description

Returns the y coordinate of a vertex.

The position is in the mesh's own space, relative to the entity's pivot - ScaleEntity and PositionEntity don't change it. Use TFormPoint to convert a vertex position into world space.

Together with VertexX and VertexZ this lets you read geometry back - for example, reading a height before applying a wave offset with VertexCoords.

See also: VertexX, VertexZ, VertexCoords, CountVertices, TFormPoint.

Example

; VertexY Example
; ---------------

; Every vertex stores a position, a normal, a colour and a set of
; uv texture coordinates. VertexY reads back the y coordinate of one vertex.
; 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)

; One colour per vertex (EntityFX 2 displays vertex colours)
VertexColor surf,v0,255,0,0
VertexColor surf,v1,0,255,0
VertexColor surf,v2,0,0,255
VertexColor surf,v3,255,255,0
VertexColor surf,v4,255,255,255
EntityFX mesh,2

; 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

; 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#=VertexY(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,"VertexY(surf,"+index+") = "+value
    Text 0,40,"The marker sphere sits on the queried vertex"

    Flip

Wend

End

Index