edit: Problems solved and fixed code is in this post. Only leaving this here in case someone else finds it usefull.
> part of original post.....
Can someone please help with this? I'm really close to what I'm trying to do, but I've got a few things I don't know how to fix. What I'm trying to do is create a viewer/editor for some of my files, and I want my camera to be able to orbit around and zoom in on selected items.
Controls are as follows,... hold down alt and click the left button to orbit,... hold down the middle button to pan. The mouse wheel zooms in and out. The right button allows to select an object, and the camera will center on that object.
> Questions removed since problem was solved.
Thanks.
> part of original post.....
Can someone please help with this? I'm really close to what I'm trying to do, but I've got a few things I don't know how to fix. What I'm trying to do is create a viewer/editor for some of my files, and I want my camera to be able to orbit around and zoom in on selected items.
Controls are as follows,... hold down alt and click the left button to orbit,... hold down the middle button to pan. The mouse wheel zooms in and out. The right button allows to select an object, and the camera will center on that object.
> Questions removed since problem was solved.
Thanks.
Graphics3D 800,600,0,2 ;create the camera rig Global mxs,mys ;for saving mouse x and y speed Global current_pick ;for saving current picked object Global campiv_h=CreatePivot() ;This is the master camera pivot,... it controls position and horizontal rotation Global campiv_v=CreatePivot(campiv_h) ;This controls vertical rotation Global cam=CreateCamera(campiv_v) Global hor_rot# = -45 ;Set horizontal orbit Global ver_rot# = 20 ;set Vert orbit MoveEntity cam,0,0,-20 ;move the camera back a bit RotateEntity campiv_h,0,hor_rot,0 RotateEntity campiv_v,ver_rot,0,0 ;hide windows cursor and create a crosshair cursor HidePointer() Global cursor=CreateImage(16,16) SetBuffer ImageBuffer(cursor) Line 1,7,15,7 Line 1,9,15,9 Line 7,1,7,15 Line 9,1,9,15 SetBuffer BackBuffer() ;############### ; create an axis icon Global axis_center = CreatePivot() axis1 = CreateCube(axis_center) ScaleEntity axis1,.05,.05,10 EntityColor axis1,0,0,255 axis2 = CreateCube(axis_center) ScaleEntity axis2,.05,10,.05 EntityColor axis2,0,255,0 axis3 = CreateCube(axis_center) ScaleEntity axis3,10,.05,.05 EntityColor axis3,255,0,0 ;############### ;create a few cubes to pick cube=CreateCube() EntityColor cube,255,100,100 EntityPickMode cube,2 ; allow to be picked (poly pick) Dim cubes(20) ;create an array of 20 cubes to pick For i=1 To 20 cubes(i)=CopyEntity (cube) PositionEntity cubes(i),Rnd(50)-25,0,Rnd(50)-25 ;position randomly EntityColor cubes(i),Rnd(255),Rnd(255),Rnd(255) Next light=CreateLight(2) MoveEntity light,500,800,0 ;******************************************************************************** ;Main loop While Not KeyDown(1) mxs=MouseXSpeed() ; store mouse x and y speeds mys=MouseYSpeed() If KeyDown(56) And MouseDown(1) Then orbit_cam() ;if alt and middle mouse button pressed,... do orbit If MouseDown(3) Then Pan_cam() ;if middle mouse button pressed,... do pan If MouseHit(2) Then pick_object() ; if an object is right clicked, move the camera to that object MoveEntity cam,0,0,MouseZSpeed()*2 ; move the camera back/forth based on mouse wheel UpdateWorld() RenderWorld() ;Print out some misc junk Text 50,10,"Selected Object: "+Str(current_pick) Text 50,25,"x:"+PickedX() Text 50,40,"y:"+PickedY() Text 50,55,"z:"+PickedZ() If PickedEntity() Then Text 50,70,"Name:"+EntityName$(PickedEntity()) DrawImage cursor,MouseX(),MouseY() Flip Wend ; end main loop End ; end program ;******************************************************************************** Function orbit_cam() hor_rot=(hor_rot - (mxs*.5) ) ; get the mouse x and y speed,... adjust sensitivity by half ver_rot=(ver_rot + (mys*.5) ) RotateEntity campiv_h,0,hor_rot,0 ; update the new camera pivot rotations RotateEntity campiv_v,ver_rot,0,0 End Function ;############### Function pan_cam() MoveEntity campiv_h,-mxs*.1,0,mys*.1 PositionEntity axis_center,EntityX(campiv_h),EntityY(campiv_h),EntityZ(campiv_h) ;position the axis at the camera pivot End Function ;############### Function pick_object() current_pick = CameraPick (cam,MouseX(),MouseY()) ; do a pick at the mouse location If PickedEntity() >0 Then ; if an object was picked,... move the camera center to that location PositionEntity campiv_h,EntityX(current_pick),EntityY(current_pick),EntityZ(current_pick) PositionEntity axis_center,EntityX(campiv_h),EntityY(campiv_h),EntityZ(campiv_h) ;position the axis at the camera pivot ;PositionEntity campiv_h,PickedX(),PickedY(),PickedZ() ;PositionEntity axis_center,PickedX(),PickedY(),PickedZ() EndIf End Function