Free Cameral Selection

Posted By: Wayne

Free Cameral Selection - 04/14/09 12:41

Hi all, I am new to gaming, so sorry if I am missing something very simple here. I am trying to design a 3d room. I have all the models set up with all the textures. I would like to use 1 free camera to navigate around freely, but also have the ability to move to a preconfigured position by pressing 1 through to 9. Has anyone done this before or could anyone advise me where I should be focusing my time.

Am I correct in thinking you can only have 1 free camera per map or can this be achieved by adding several free cameras to different entity’s?

Regards

Wayne
Posted By: Germanunkol

Re: Free Cameral Selection - 04/14/09 13:07

Well, there is the predefined view called "camera" which can be moved by altering camera.x,camera.y and camera.z. Then you can also define more "views" (see 'view' in the manual) which can be displayed on different parts of the screen and which can show different parts of the level (for example: your camera looks into the direction your player car is facing, and then you define another view called "rearview" which will be displayed at the top of your screen and which, in your level, always is at that camera's position but facing backwards.
Try this: (call moveCamera(); in your "main" function, after a level is loaded)
Code:
var camPos1[3] = {100,0,0};		//define these at the beginning of your script. change the 100,0,0 to the positions you want the camera to
var camPos2[3] = {-100,0,0};		//be at when you press 1 to 9
var camPos3[3] = {1000,0,0};
var camPos4[3] = {300,0,0};
var camPos5[3] = {0,400,0};
var camPos6[3] = {100,0,100};
var camPos7[3] = {100,35,0};
var camPos8[3] = {0,0,23};
var camPos9[3] = {100,1,0};


void moveCamera()
{
	mouse_mode = 4;
	while(1)
	{
		camera.pan += mouse_force.x*time_step*5;
		camera.tilt += mouse_forc.y*time_step*5;
		
		vec_set(temp,vector((key_w-key_s)*time_step*10,(key_d-key_a)*time_step*10,0));
		vec_rotate(temp,camera.pan);
		vec_add(camera.x,temp);
		
		if(key_1 == on)			//if key 1 is pressed, move the camera to the position defined before as camPos1
		vec_set(camera.x,camPos1);
		if(key_2 == on)
		vec_set(camera.x,camPos3);
		if(key_3 == on)
		vec_set(camera.x,camPos3);
		if(key_4 == on)
		vec_set(camera.x,camPos4);
		if(key_5 == on)
		vec_set(camera.x,camPos5);
		if(key_6 == on)
		vec_set(camera.x,camPos6);
		if(key_7 == on)
		vec_set(camera.x,camPos7);
		if(key_8 == on)
		vec_set(camera.x,camPos8);
		if(key_9 == on)
		vec_set(camera.x,camPos9);
		wait(1);	
	}
}

Posted By: Wayne

Re: Free Cameral Selection - 04/14/09 15:38

Thank you, I will give this a go and see how we go.

Many thanks againa
Posted By: Galen

Re: Free Cameral Selection - 11/07/09 20:03

Anyone have a script (or script idea) for converting this to iterate through a collection of camera positions by hitting one key only? I was thinking of setting up a list of camera positions as shown here, but then using just one key to jump from one position to the next (I plan on having several dozen, so 0-9 keys wouldn't be enough).
Posted By: darkinferno

Re: Free Cameral Selection - 11/07/09 20:42

[untested and because am lazy]

current_cam; //this is the current cam, default 0

function next_cam()
{
current_cam++; //go to next cam
current_cam%=9; //cycle between 9 cams
}

and in some other function or your main function, you can have:

on_c=next_cam;

now ofcourse you'll have to have each camera set to a number, for example:

if (current_cam==0)vec_set(camera.x,pos1.x); //set cam to position 1
if (current_cam==1)vec_set(camera.x,pos2.x); //so on and so forth

hope it helps... later
Posted By: Galen

Re: Free Cameral Selection - 11/07/09 21:36

Thanks. Wasn't working for me though.

Trying to figure out why the following won't work:
var i = 0;
void moveCamera()
{

var camPos0[3] = {30,71,1405};
var camPos1[3] = {-120,71,1405};
var camPos2[3] = {-270,71,1405};
var camPos3[3] = {-390,71,1405};
var camPos4[3] = {-510,71,1405};
var camPos5[3] = {-630,71,1405};
var camPos6[3] = {-750,71,1405};






STRING* camPosF = "camPos" + i;
vec_set(camera.x,camPosF);
i = (i + 1);
}

Posted By: Galen

Re: Free Cameral Selection - 11/07/09 21:57

*bump* anyone?
Posted By: Galen

Re: Free Cameral Selection - 11/07/09 23:09

Okay, I almost have it working. When I hit "p" (the button I assigned for changing the camera view), I briefly see the new camera position flash on the screen, but then I just end up back at my camera's starting position. Anyone have any idea what I may be doing wrong?

Here's my latest code: (orange for camera movement, blue for the rest of my default camera code):

int i = 0;

void moveCamera()
{
mouse_mode = 4;
var camPos0[3] = {30,71,1405};
var camPos1[3] = {-120,71,1405};
var camPos2[3] = {-270,71,1405};
var camPos3[3] = {-390,71,1405};
var camPos4[3] = {-510,71,1405};
var camPos5[3] = {-630,71,1405};
var camPos6[3] = {-750,71,1405};






if (i == 0) {vec_set(camera.x,camPos0);}
if (i == 1) {vec_set(camera.x,camPos1);}
if (i == 2) {vec_set(camera.x,camPos2);}
if (i == 3) {vec_set(camera.x,camPos3);}
if (i == 4) {vec_set(camera.x,camPos4);}
if (i == 5) {vec_set(camera.x,camPos5);}
if (i == 6) {vec_set(camera.x,camPos6);}


i = (i + 1);

}



action free_camera()
{
// c_setminmax(my);

//video_switch(11,32,1); //1024x768 in fullscreen mode
video_set(1920,1200,0,1);
d3d_antialias = 9;


//camera.clip_near = 5;


//camera.clip_far = 20000;


VECTOR camera_force;
set(my,INVISIBLE|POLYGON);
// set(my,PASSABLE);

camera_force.z = 0;
vec_set(camera.x,my.x);
vec_set(camera.pan,my.pan);
my.pan = 340;
my.tilt = 250;
//my.roll = 340;

camera.flags |= ISOMETRIC;
camera.arc = 10;


while(1)
{
camera_force.x = (key_w - key_s)*50*time_step;
camera_force.y = (key_a - key_d)*50*time_step;
vec_add(my.pan,vector(mouse_force.x*(-6)*time_step,mouse_force.y*6*time_step,0));

c_move(my,camera_force,nullvector,GLIDE+IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_PUSH);
vec_set(camera.x,vector(my.x,my.y,my.z));
vec_set(camera.pan,my.pan);



wait(1);
}





}

Posted By: darkinferno

Re: Free Cameral Selection - 11/07/09 23:21

remove i-(i+1)l from your moveCamera() function...

now i want you to add a new function:

function change_Cam()
{
i++;
i%=6; //cycle between 6 views
}

now somewhere in your main function, add:

on_c=change_Cam;

you should be calling your void moveCamera() function from inside the while loop though, that or put all its instructions within a while loop
Posted By: Galen

Re: Free Cameral Selection - 11/07/09 23:33

Thanks for the reply!

I tried that, but it crashes acknex.exe--here's the code as I have it:

int i = 0;


action free_camera()
{
// c_setminmax(my);

//video_switch(11,32,1); //1024x768 in fullscreen mode
video_set(1920,1200,0,1);
d3d_antialias = 9;


//camera.clip_near = 5;


//camera.clip_far = 20000;


VECTOR camera_force;
set(my,INVISIBLE|POLYGON);
// set(my,PASSABLE);

camera_force.z = 0;
vec_set(camera.x,my.x);
vec_set(camera.pan,my.pan);
my.pan = 340;
my.tilt = 250;
//my.roll = 340;

camera.flags |= ISOMETRIC;
camera.arc = 10;


while(1)
{
camera_force.x = (key_w - key_s)*50*time_step;
camera_force.y = (key_a - key_d)*50*time_step;
vec_add(my.pan,vector(mouse_force.x*(-6)*time_step,mouse_force.y*6*time_step,0));

c_move(my,camera_force,nullvector,GLIDE+IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_PUSH);
vec_set(camera.x,vector(my.x,my.y,my.z));
vec_set(camera.pan,my.pan);



wait(1);

void moveCamera()
{
mouse_mode = 4;
var camPos0[3] = {30,71,1405};
var camPos1[3] = {-120,71,1405};
var camPos2[3] = {-270,71,1405};
var camPos3[3] = {-390,71,1405};
var camPos4[3] = {-510,71,1405};
var camPos5[3] = {-630,71,1405};
var camPos6[3] = {-750,71,1405};






if (i == 0) {vec_set(camera.x,camPos0);}
if (i == 1) {vec_set(camera.x,camPos1);}
if (i == 2) {vec_set(camera.x,camPos2);}
if (i == 3) {vec_set(camera.x,camPos3);}
if (i == 4) {vec_set(camera.x,camPos4);}
if (i == 5) {vec_set(camera.x,camPos5);}
if (i == 6) {vec_set(camera.x,camPos6);}




}

function change_Cam()
{
i++;
i%=6; //cycle between 6 views
}

}





}

Posted By: Galen

Re: Free Cameral Selection - 11/07/09 23:42

I got it!!!!

I adjusted the code a little bit more (namely moved the "wait" and removed the cameraMove function/brackets) and now it works!!!

Here's my code as it is working now:

int i = 0;



function change_Cam()
{
i++;
i%=6; //cycle between 6 views
}





action free_camera()
{
// c_setminmax(my);

//video_switch(11,32,1); //1024x768 in fullscreen mode
video_set(1920,1200,0,1);
d3d_antialias = 9;


//camera.clip_near = 5;


//camera.clip_far = 20000;


VECTOR camera_force;
set(my,INVISIBLE|POLYGON);
// set(my,PASSABLE);

camera_force.z = 0;
vec_set(camera.x,my.x);
vec_set(camera.pan,my.pan);
my.pan = 340;
my.tilt = 250;
//my.roll = 340;

camera.flags |= ISOMETRIC;
camera.arc = 10;


while(1)
{
camera_force.x = (key_w - key_s)*50*time_step;
camera_force.y = (key_a - key_d)*50*time_step;
vec_add(my.pan,vector(mouse_force.x*(-6)*time_step,mouse_force.y*6*time_step,0));

c_move(my,camera_force,nullvector,GLIDE+IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_PUSH);
vec_set(camera.x,vector(my.x,my.y,my.z));
vec_set(camera.pan,my.pan);






// mouse_mode = 4;
var camPos0[3] = {30,71,1405};
var camPos1[3] = {-120,71,1405};
var camPos2[3] = {-270,71,1405};
var camPos3[3] = {-390,71,1405};
var camPos4[3] = {-510,71,1405};
var camPos5[3] = {-630,71,1405};
var camPos6[3] = {-750,71,1405};






if (i == 0) {vec_set(camera.x,camPos0);}
if (i == 1) {vec_set(camera.x,camPos1);}
if (i == 2) {vec_set(camera.x,camPos2);}
if (i == 3) {vec_set(camera.x,camPos3);}
if (i == 4) {vec_set(camera.x,camPos4);}
if (i == 5) {vec_set(camera.x,camPos5);}
if (i == 6) {vec_set(camera.x,camPos6);}




wait(1);



}





}


Thanks man, you really helped me out!
© 2024 lite-C Forums