Hi All,
I have a strange issue that I cannot quite identify.
I have created a camera in the style of Homeworld. It works using an object with 2 limbs. The object can move about. Limb 1 handles left/right rotation and Limb 2 (which is linked to Limb 1) handles the up/down rotation.
I have done this so I don't have to work out the maths and have a system easy for me to follow and use. If I am doing this in a silly way then feel free to tell me.
I have it set up so you click on the right mouse button to rotate around and use the mousez() wheel to move in and out of the model.
The strange behaviour I see is that as I zoom in and out using the mouse wheel very occasionally I see the object flicker on the screen (as if surviving for 1 frame update or so), but in an orientation that suggests that the camera has jumped directly above it...
Rem Created: Friday, September 06, 2013
Rem ***** Main Source File *****
sync on : sync rate 0 : backdrop off : autocam off
`if check display mode(1366, 768, 32)=1 then set display mode 1366, 768, 32
if check display mode(1024, 768, 32)=1 then set display mode 1024, 768, 32
set image colorkey 255,0,255
global g_root_directory$ as string : g_root_directory$ = get dir$()
`disable escapekey
`hide mouse
set window position 0,0
DEFINE_Constants()
DEFINE_Variables()
Setup_Game()
Load_Objects()
Main_Code()
end
function DEFINE_Constants()
#constant c_OBJNUM_TempMesh 12
#constant c_OBJNUM_TempMesh2 13
#constant c_CAMERA_ObjNum 13
#constant c_CAMFREE_y_camera_rotation_speed 10
endfunction
function DEFINE_Variables()
dim fps_movement_correction#(0) as float
` INPUT VARIABLES
`Mouse Variables
global g_mousez_value as integer : g_mousez_value = mousez()
dim g_mouseclick(4) as integer
dim mouse_click(2) as integer
`RTS Camera
global g_CAMFREE_mouse_oldx as integer
global g_CAMFREE_mouse_oldy as integer
global g_CAMERA_Offset as integer: g_CAMERA_Offset = 100
global g_CAMFREE_limb_angle# as float : g_CAMFREE_limb_angle# = 60
endfunction
function Setup_Game()
`Create Temp Mesh
make object cube 1, 20
make mesh from object c_OBJNUM_TempMesh, 1
delete object 1
make object plain 1, 0.1, 0.1
make mesh from object c_OBJNUM_TempMesh2, 1
delete object 1
`Make Camera Object
make object cube c_CAMERA_ObjNum, 20
add limb c_CAMERA_ObjNum, 1, c_OBJNUM_TempMesh
add limb c_CAMERA_ObjNum, 2, c_OBJNUM_TempMesh2
offset limb c_CAMERA_ObjNum, 2, 0, g_CAMERA_Offset, 0
link limb c_CAMERA_ObjNum, 1, 2
rotate limb c_CAMERA_ObjNum, 1, 90, 0, 0
endfunction
function Load_Objects()
make object box 99, 100, 10, 50
position object 99, 0,0,0
endfunction
function Main_Code()
do
` Set the variable for regulating movement and game time against FPS per main program loop
if screen fps() > 0
fps_movement_correction#(0) = 100.0 / screen fps()
if fps_movement_correction#(0) > 10
fps_movement_correction#(0) = 1
endif
else
fps_movement_correction#(0) = 1
endif
CAMERA_RTS_Engine()
position camera limb position x(c_CAMERA_ObjNum, 2), limb position y(c_CAMERA_ObjNum, 2), limb position z(c_CAMERA_ObjNum, 2)
point camera object position x(c_CAMERA_ObjNum), object position y(c_CAMERA_ObjNum), object position z(c_CAMERA_ObjNum)
sync
loop
endfunction
function CAMERA_RTS_Engine()
`Mouse Wheel Zoom
if mousez() > g_mousez_value
dec g_CAMERA_Offset, 20
g_mousez_value = mousez()
offset limb c_CAMERA_ObjNum, 2, o, g_CAMERA_Offset, 0
endif
if mousez() < g_mousez_value
inc g_CAMERA_Offset, 20
g_mousez_value = mousez()
offset limb c_CAMERA_ObjNum, 2, 0, g_CAMERA_Offset, 0
endif
FREECAM_INPUT_Mouse_Button2()
endfunction
function FREECAM_INPUT_Mouse_Button2()
`1st click of the Number 2 mouse button
if mouseclick() = 2 and mouse_click(2) = -1
mouse_click(2) = 1
g_CAMFREE_mouse_oldx = mousex()
g_CAMFREE_mouse_oldy = mousey()
endif
if mouseclick() = 0 and mouse_click(2) <> -1
mouse_click(2) = -1
endif
`Follow on - holding down the Number 2 mouse button
if mouse_click(2) = 1
if mousey() > g_CAMFREE_mouse_oldy : `up
if wrapvalue(limb angle x(c_CAMERA_ObjNum, 1)) < (170 - 3)
EZro_SetEuler limb angle x(c_CAMERA_ObjNum, 1), limb angle y(c_CAMERA_ObjNum, 1), limb angle z(c_CAMERA_ObjNum, 1)
EZro_LX (3) : EZro_FindEuler
rotate limb c_CAMERA_ObjNum, 1, EZro_GetEulerX(), EZro_GetEulerY(), EZro_GetEulerZ()
endif
endif
if mousey() < g_CAMFREE_mouse_oldy : `down
if wrapvalue(limb angle x(c_CAMERA_ObjNum, 1)) > 15 + 3
EZro_SetEuler limb angle x(c_CAMERA_ObjNum, 1), limb angle y(c_CAMERA_ObjNum, 1), limb angle z(c_CAMERA_ObjNum, 1)
EZro_LX (0-3) : EZro_FindEuler
rotate limb c_CAMERA_ObjNum, 1, EZro_GetEulerX(), EZro_GetEulerY(), EZro_GetEulerZ()
endif
endif
if mousex() < g_CAMFREE_mouse_oldx: `left
l_CAMObj_Limb_Y = object angle y(c_CAMERA_ObjNum) - 3
rotate object c_CAMERA_ObjNum, object angle x(c_CAMERA_ObjNum), l_CAMObj_Limb_Y, object angle z(c_CAMERA_ObjNum)
endif
if mousex() > g_CAMFREE_mouse_oldx : `right
l_CAMObj_Limb_Y = object angle y(c_CAMERA_ObjNum) + 3
rotate object c_CAMERA_ObjNum, object angle x(c_CAMERA_ObjNum), l_CAMObj_Limb_Y, object angle z(c_CAMERA_ObjNum)
endif
g_CAMFREE_mouse_oldx = mousex()
g_CAMFREE_mouse_oldy = mousey()
endif
endfunction