Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, 7th_zorro), 719 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Simple freeflight code #176643
01/05/08 20:47
01/05/08 20:47
Joined: Jan 2003
Posts: 4,305
Damocles Offline OP
Expert
Damocles  Offline 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: Damocles] #176644
01/05/08 21:32
01/05/08 21:32
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
Thanks for this great piece of code
Here is a Lite-C version of it:
Code:

//simple freeflight without collision detection
void tools_camera_freeflight1()
{
var tools_movespeed=20; //how fast to move
var tools_movecam[3];

while(1)
{

//turn the camera
camera.pan -= mouse_force.x*15*time_step;
camera.tilt += mouse_force.y*15*time_step;
camera.tilt = clamp(camera.tilt,-90,90);

vec_set(tools_movecam[0],nullvector); //reset movement vector

//ket wasd or cursor movment
if(key_w||key_cuu){tools_movecam[0] = tools_movespeed*time_step;}
if(key_s||key_cud){tools_movecam[0] = -tools_movespeed*time_step;}
if(key_a||key_cul){tools_movecam[1] = tools_movespeed*time_step;}
if(key_d||key_cur){tools_movecam[1] = -tools_movespeed*time_step;}

//rotate by camera heading
vec_rotate(tools_movecam[0],camera.pan);

//move the camera
vec_add(camera.x,tools_movecam[0]);

wait(1);
}
}



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 Offline
Expert
frazzle  Offline
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: frazzle] #176646
01/05/08 22:27
01/05/08 22:27
Joined: Jan 2003
Posts: 4,305
Damocles Offline OP
Expert
Damocles  Offline OP
Expert

Joined: Jan 2003
Posts: 4,305
Slin, thanks for the adaption of the code to Lite-C.
(my code has insertions with tabs, but the forumsoftware somehow always removes them)

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 Offline
Expert
Joozey  Offline
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 Offline OP
Expert
Damocles  Offline 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);
}
}




Re: Simple freeflight code [Re: Damocles] #176649
01/05/08 23:36
01/05/08 23:36
Joined: Mar 2003
Posts: 4,264
Wellington
Nems Offline

.
Nems  Offline

.

Joined: Mar 2003
Posts: 4,264
Wellington
Cool codes, thanks.

Edit* already done.

Last edited by Nems; 01/06/08 03:37.

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1