Blitz3D+ Command Reference

RotateMesh mesh,pitch#,yaw#,roll#

Parameters

mesh - mesh handle
pitch# - rotation around the x axis, in degrees
yaw# - rotation around the y axis, in degrees
roll# - rotation around the z axis, in degrees

Description

Rotates every vertex of a mesh around the entity's pivot by the given angles.

Unlike RotateEntity or TurnEntity, this permanently modifies the geometry: the entity's own orientation stays at whatever it was, but the shape inside it is turned. Vertex normals are rotated along with the positions, so lighting stays correct.

The everyday use is fixing a model exported facing the wrong way - RotateMesh model,0,180,0 turns it round once at load time, and from then on MoveEntity's "forward" matches the model's nose. Doing this with RotateEntity instead would fight every rotation you apply during play.

See also: RotateEntity, TurnEntity, PositionMesh, ScaleMesh.

Example

; RotateMesh Example
; ------------------

; RotateMesh spins the VERTICES inside a mesh; the entity's own
; orientation is untouched. RotateEntity/TurnEntity rotate the entity
; itself, carrying children (and collision) along with it.
; Both drums below appear to spin - but only the left one really
; rotates as an entity: watch the red cubes.

Graphics3D 640,480
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,0,-5

light=CreateLight()
RotateEntity light,30,40,0

; Load a drum and fit it into a 2-unit box centred on its origin
drum_entity=LoadMesh("media/oil-drum/oildrum.3ds")
FitMesh drum_entity,-1,-1,-1,2,2,2,1
PositionEntity drum_entity,-1.5,0,0

; CopyMesh gives the second drum INDEPENDENT geometry, so RotateMesh
; on it will not touch the first drum
drum_mesh=CopyMesh(drum_entity)
PositionEntity drum_mesh,1.5,0,0

; A red cube child on the front of each drum
hat1=CreateCube()
ScaleEntity hat1,0.15,0.15,0.15
EntityColor hat1,255,60,60
EntityFX hat1,1
PositionEntity hat1,-1.5,0,-1.2
EntityParent hat1,drum_entity

hat2=CreateCube()
ScaleEntity hat2,0.15,0.15,0.15
EntityColor hat2,255,60,60
EntityFX hat2,1
PositionEntity hat2,1.5,0,-1.2
EntityParent hat2,drum_mesh

While Not KeyDown(1)

    ; Left drum: rotate the ENTITY - its child cube orbits with it
    TurnEntity drum_entity,0,1,0

    ; Right drum: rotate only the MESH - the documented command.
    ; The entity (and so its child cube) never turns.
    RotateMesh drum_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,"Arrow keys: move camera   Esc: exit"
    Text 0,20,"Left: TurnEntity - the child cube orbits"
    Text 0,40,"Right: RotateMesh - vertices spin, entity (and child) stay put"

    Flip

Wend

End

Index