Code archives/3D Graphics - Misc/Compass
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
| Very simple example of implementing a compass. Hope you learn something from it! | |||||
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
light=CreateLight()
RotateEntity light,90,0,0
cube=CreateCube()
PositionEntity cube,0,0,5
compass = CreateSprite()
ScaleSprite compass,1,.1
PositionEntity compass,0,2,3
tex=CreateTexture(128,18)
SetBuffer TextureBuffer(tex)
ClsColor 50,50,50
Cls
font=LoadFont("verdana",19)
SetFont font
Color 255,255,255
Text 0,0,"N | E | S | W |"
EntityTexture compass,tex
SetBuffer BackBuffer()
While Not KeyDown(1)
compassrot# = EntityYaw(cube)
If compassrot# < 0 Then compassrot# = compassrot# + 360
PositionTexture tex,compassrot#/360,0
TurnEntity cube,0,-MouseXSpeed(),0
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
RenderWorld()
Flip
Wend
End |
Comments
| ||
| Nice try, but it's inherently flawed due to the different sizes of character spacing withing "N E S W" so the fact that the texturewidth being 128pixels, does not divide by 360 accurately in terms of the position of the N, E ,S and W markers or the | separtators. Whilst the 'current' face direction appears to be correct, the 45-degree markers and other directions often slip out of sync occasionally between the four main points. |
Code Archives Forum