2 registered members (AndrewAMD, 7th_zorro),
719
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Simple freeflight code
#176643
01/05/08 20:47
01/05/08 20:47
|
Joined: Jan 2003
Posts: 4,305
Damocles
OP
Expert
|
OP
Expert
Joined: Jan 2003
Posts: 4,305
|
this code is a fast to implement code to make a freeflight camera It works better than the "0-key" freeflight of the engine. Just insert the code, and start "tools_camera_freeflight1();" Code:
//simple freeflight without collision detection function tools_camera_freeflight1() {
fps_max=80; //limititing the framerate to overcome some calculation problems
var tools_movespeed=20; //how fast to move var tools_movecam[3]; var tools_cam_turnspeed=20;
while(1) { //turn the camera camera.pan-=mouse_force.x*tools_cam_turnspeed*time; camera.tilt+=mouse_force.y*tools_cam_turnspeed*time; camera.tilt=max(-90,min(camera.tilt,90)); vec_set(tools_movecam.x,nullvector); //reset movement vector //get wasd or cursor movment if(key_w||key_cuu){tools_movecam.x=tools_movespeed*time;} if(key_s||key_cud){tools_movecam.x=-tools_movespeed*time;} if(key_a||key_cul){tools_movecam.y=tools_movespeed*time;} if(key_d||key_cur){tools_movecam.y=-tools_movespeed*time;} //rotate by camera heading vec_rotate(tools_movecam,camera.pan); //move the camera vec_add(camera.x,tools_movecam.x); wait(1); } }
Edit: I have inserted an FPS_Max and a timed input of mouse_force to adjust to framerate dependencies
|
|
|
Re: Simple freeflight code
[Re: Slin]
#176645
01/05/08 21:46
01/05/08 21:46
|
Joined: Mar 2006
Posts: 2,758 Antwerp,Belgium
frazzle
Expert
|
Expert
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
|
@ Damocles: Nice code man, clean and smooth indeed @ Slin: Thanks once again for the effort Cheers Frazzle
Antec® Case Intel® X58 Chipset Intel® i7 975 Quad Core 8 GB RAM DDR3 SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB NVIDIA® GeForce GTX 295 Memory 1795GB
|
|
|
Re: Simple freeflight code
[Re: Damocles]
#176647
01/05/08 22:42
01/05/08 22:42
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
Quote:
(my code has insertions with tabs, but the forumsoftware somehow always removes them)
Not if you put it between code tags .
Thanx for this contribution, and I'm amazed that it works properly in both fullscreen and windowed mode, as I have had much trouble with speed differences in other movement codes when using time_step.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: Simple freeflight code
[Re: Joozey]
#176648
01/05/08 23:17
01/05/08 23:17
|
Joined: Jan 2003
Posts: 4,305
Damocles
OP
Expert
|
OP
Expert
Joined: Jan 2003
Posts: 4,305
|
Ok, never seen that tag here a code for a classical RTS camera with static ISO view and smoothed zooming Code:
//a simple RTS like ISO camera, like in Warcraft3, without turning the camera.pan //movement of the camera with cursorkeys, and touching the side of the screen //zooming with the mouseweel function tools_camera_RTS_1() { var tools_movespeed=50; //movespeed of the camera var tools_lowest_cam_z=0; //range of the camera for zooming var tools_highest_cam_z=800; var tools_zoomhight=600; var tools_zoomspeed=.6; //value between .99 and .01 var tools_timed_fraction; var high_tilt=-60; //standard tile of the camera (should be a negative number between -90 and 0) var low_tilt=-30; //tilt when reching a low position var tilt_switch_hight=500; //hight when to switch to lower tilt of camera var tilt_diff;tilt_diff=tilt_switch_hight-tools_lowest_cam_z; camera.z+=tools_zoomhight; //hight of the camera above ground camera.pan=90; //to have the same view as in WED camera.tilt=high_tilt; //ISO looking down while(1) { //re-position camera according to inputdata form mouse-pointer or cursor-keys if((key_cur)||(mouse_cursor.x>screen_size.x-2)){camera.x+=tools_movespeed*time;} if((key_cul)||(mouse_cursor.x<2)){camera.x-=tools_movespeed*time;} if((key_cuu)||(mouse_cursor.y<2)){camera.y+=tools_movespeed*time;} if((key_cud)||(mouse_cursor.y>screen_size.y-2)){camera.y-=tools_movespeed*time;} tools_timed_fraction=tools_zoomspeed*time; tools_zoomhight+=mickey.z*.5; tools_zoomhight=min(max(tools_lowest_cam_z,tools_zoomhight),tools_highest_cam_z); camera.z=camera.z*(1-tools_timed_fraction)+tools_zoomhight*tools_timed_fraction; camera.z=min(max(tools_lowest_cam_z,camera.z),tools_highest_cam_z); if(camera.z>tilt_switch_hight){camera.tilt=high_tilt;} //use standard tilt above tilt_switch_hight else{camera.tilt=high_tilt-(((tilt_switch_hight-camera.z)/tilt_diff)*(high_tilt-low_tilt));} //calculate a tilt depending on hight od camera wait(1); } }
|
|
|
|