K
i need some help on this code u will need a couple of media files (grass3.bmp/heightmap_256.bmp) or any files will do
U use the mouse to control a cube on a terrain
Left mouse selects a destination point for the cube to goto
Right mouse rotates around the cube
Middle mouse zooms in
wot im after is when i click the terrain to make the destination point i need the camera to lock on the cube like a 3rd person type of view so the camera follows the cube to the destination point
ive nearly got it but wot is happening now with this code is this
when i click the camera seems to snap to the destination point and the cube can sometimes be off screen
can any one help me on this problem
Graphics3D 800,600
SetBuffer BackBuffer()
AppTitle "3D-Mouse", "Are you sure?"
Const n_trees=200
Type player
Field x#,y#,z#
Field ang#,speed#
End Type
Global me.player=New player
Global clickedx#,clickedz#
light=CreateLight()
LightColor light,156,156,156
TurnEntity light,60,60,0
;Collisions 3,2,1,1
Collisions 3,1,2,3
Collisions 2,1,1,3
Collisions 3,4,1,1
Global piv=CreatePivot()
Global pointer = CreateCube(piv)
ScaleEntity pointer,.5,.5,.5
EntityColor pointer,0,256,0
EntityType pointer,2
Global cubepiv=CreatePivot()
Global cube=CreateCube(cubepiv)
EntityRadius cube,2,2
EntityType cube,3
PositionEntity cube,20,1,20
Global campiv=CreatePivot()
Global cam=CreateCamera(campiv)
CameraRange cam,.1,1000
RotateEntity cam,45,0,0
EntityType cam,2
PositionEntity cam,0,80,-80
EntityType campiv,4
;CameraViewport cam,0,0,GraphicsWidth(),500
Global terrain = LoadTerrain ("heightmap_256.bmp")
ScaleEntity terrain, 5,100,5
TerrainShading terrain, True
TerrainDetail terrain, 2500,True
grass=LoadTexture( "grass3.bmp" )
ScaleTexture grass,30,30
EntityTexture terrain,grass
EntityType terrain,1
EntityPickMode terrain,2
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
;set up fps counter
fps_milli=MilliSecs(): fps_counter=0: update_frequency=10
While Not KeyHit(1)
mx#=-MouseXSpeed()*1
CameraPick (cam,MouseX(),MouseY())
PositionEntity pointer,PickedX#(),PickedY#(),PickedZ#()
If MouseHit(1)
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
PositionEntity campiv,PickedX#(),PickedY#(),PickedZ#()
me\speed=.6
EndIf
If MouseDown(2)
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
PointEntity cam,cube
TurnEntity campiv,0,mx#,0
EndIf
moveplayer()
If MouseDown(3)=True
zoom#=zoom#+1
EndIf
If MouseDown(3)=0
zoom#=zoom#-1
EndIf
If zoom#<1 Then zoom#=1
If zoom#>2 Then zoom#=2
MoveEntity cube,me\x,me\y,me\z+me\speed
CameraZoom cam,zoom#
UpdateWorld
RenderWorld
; fps counter
fps_counter=fps_counter+1
If fps_counter=update_frequency
fps=1000/Float(((MilliSecs()-fps_milli))/update_frequency)
fps_milli=MilliSecs()
fps_counter=0
EndIf
; print fps
Text 0,0,"FPS: "+fps
Text 80,0,"MouseX: "+MouseX()
Text 180,0,"MouseY: "+MouseY()
Text 0,20,"EntityX: "+EntityX(cube)
Text 0,40,"EntityY: "+EntityY(cube)
Text 0,60,"EntityZ: "+EntityZ(cube)
Text 680,0,"Time: "+CurrentTime()
Text 600,15,"Triangles Rendered: "+TrisRendered()
Flip
Wend
End
Function moveplayer()
x#=EntityX(cube)
y#=EntityY(cube)
z#=EntityZ(cube)
terry#=TerrainY(terrain,x#,y#,z#)
PositionEntity cubepiv,me\x,terry#,me\z
PointEntity cube,campiv
RotateEntity cube,0,EntityYaw#(cube),0
End Function
please feel free to use this code if it is any good lol
Thanks
GIMPY :)
i need some help on this code u will need a couple of media files (grass3.bmp/heightmap_256.bmp) or any files will do
U use the mouse to control a cube on a terrain
Left mouse selects a destination point for the cube to goto
Right mouse rotates around the cube
Middle mouse zooms in
wot im after is when i click the terrain to make the destination point i need the camera to lock on the cube like a 3rd person type of view so the camera follows the cube to the destination point
ive nearly got it but wot is happening now with this code is this
when i click the camera seems to snap to the destination point and the cube can sometimes be off screen
can any one help me on this problem
Graphics3D 800,600
SetBuffer BackBuffer()
AppTitle "3D-Mouse", "Are you sure?"
Const n_trees=200
Type player
Field x#,y#,z#
Field ang#,speed#
End Type
Global me.player=New player
Global clickedx#,clickedz#
light=CreateLight()
LightColor light,156,156,156
TurnEntity light,60,60,0
;Collisions 3,2,1,1
Collisions 3,1,2,3
Collisions 2,1,1,3
Collisions 3,4,1,1
Global piv=CreatePivot()
Global pointer = CreateCube(piv)
ScaleEntity pointer,.5,.5,.5
EntityColor pointer,0,256,0
EntityType pointer,2
Global cubepiv=CreatePivot()
Global cube=CreateCube(cubepiv)
EntityRadius cube,2,2
EntityType cube,3
PositionEntity cube,20,1,20
Global campiv=CreatePivot()
Global cam=CreateCamera(campiv)
CameraRange cam,.1,1000
RotateEntity cam,45,0,0
EntityType cam,2
PositionEntity cam,0,80,-80
EntityType campiv,4
;CameraViewport cam,0,0,GraphicsWidth(),500
Global terrain = LoadTerrain ("heightmap_256.bmp")
ScaleEntity terrain, 5,100,5
TerrainShading terrain, True
TerrainDetail terrain, 2500,True
grass=LoadTexture( "grass3.bmp" )
ScaleTexture grass,30,30
EntityTexture terrain,grass
EntityType terrain,1
EntityPickMode terrain,2
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
;set up fps counter
fps_milli=MilliSecs(): fps_counter=0: update_frequency=10
While Not KeyHit(1)
mx#=-MouseXSpeed()*1
CameraPick (cam,MouseX(),MouseY())
PositionEntity pointer,PickedX#(),PickedY#(),PickedZ#()
If MouseHit(1)
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
PositionEntity campiv,PickedX#(),PickedY#(),PickedZ#()
me\speed=.6
EndIf
If MouseDown(2)
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
PointEntity cam,cube
TurnEntity campiv,0,mx#,0
EndIf
moveplayer()
If MouseDown(3)=True
zoom#=zoom#+1
EndIf
If MouseDown(3)=0
zoom#=zoom#-1
EndIf
If zoom#<1 Then zoom#=1
If zoom#>2 Then zoom#=2
MoveEntity cube,me\x,me\y,me\z+me\speed
CameraZoom cam,zoom#
UpdateWorld
RenderWorld
; fps counter
fps_counter=fps_counter+1
If fps_counter=update_frequency
fps=1000/Float(((MilliSecs()-fps_milli))/update_frequency)
fps_milli=MilliSecs()
fps_counter=0
EndIf
; print fps
Text 0,0,"FPS: "+fps
Text 80,0,"MouseX: "+MouseX()
Text 180,0,"MouseY: "+MouseY()
Text 0,20,"EntityX: "+EntityX(cube)
Text 0,40,"EntityY: "+EntityY(cube)
Text 0,60,"EntityZ: "+EntityZ(cube)
Text 680,0,"Time: "+CurrentTime()
Text 600,15,"Triangles Rendered: "+TrisRendered()
Flip
Wend
End
Function moveplayer()
x#=EntityX(cube)
y#=EntityY(cube)
z#=EntityZ(cube)
terry#=TerrainY(terrain,x#,y#,z#)
PositionEntity cubepiv,me\x,terry#,me\z
PointEntity cube,campiv
RotateEntity cube,0,EntityYaw#(cube),0
End Function
please feel free to use this code if it is any good lol
Thanks
GIMPY :)