3D Mouse Probs
Blitz3D Forums/Blitz3D Programming/3D Mouse Probs
| ||
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 :) |
| ||
K im still stuck with this can some body plz help me on this ive been stuck on this for about a week lol i just need the camera to follow the cube and not snap to the locataion i click ive tried pointentity cam,cube but it goes wrong ive also tried other pointentity combo's but it still dont seem to work as soon as this is fixed i will put it up in the code database for anybody to use it could be used for a level editor or an RPG or wotever plz some one help me Thanks GIMPY :) |
| ||
Not sure what specific effect you are after but if you want the camera to follow the cube make the camera a child of the cube: Global cam=CreateCamera(cube) |
| ||
Thanks Shambler that might just do it :) ill give it a go Thanks GIMPY :) |
| ||
Try using 2 pivots... Make 2 pivots children of ur cube: One where you want the camera to sit on the cube, One just in front of the cube's "nose" so you can point the camera forward. To move the camera from "birds eye" mode to 1sr person: Use some variables to store where your birds eye camera is positioned at and which way it is facing. Use EntityParent to parent the camera to your cube's camera pivots, then simply EntityPosition your camera on top of it. Now use PointEntity to point the camera at your cube's nose pivot. To put the camera back to birds eye position, ParentEntity it to nothing then EntityPosition again using your stored variables and then point it back to the ground. You might have to play around in order to get the best results (you may have to reset your camera zoom when on the cube etc). Hope that makes some sense. |
| ||
Thanks Sainfohi ill play about with ur method also Thanks GIMPY :) |