Force Camera to View?

Posted By: RealSerious3D

Force Camera to View? - 04/17/11 16:00

Currently I have, thanks to all that have helped me, code that enables me to rotate an entity via LMB click-drag. Here's the code I am using:

Code:
action rotate()
{
	while(1)
	{
		if (mouse_left){
			my.pan += mouse_force.x;	
			my.tilt += mouse_force.y;
		}
		wait(1);
	}
}



Now what I would like to do is add a means to click some buttons and go to a particular view of that model. In other words, I would like to have buttons that read:

- front
- back
- side
- top
- Bottom

So I would need five buttons and clicking on one would snap the model to that view.

I think this could be done in two ways:

Moving the actual model

In this, the code would instantly rotate the model to face the camera depending on which button was pressed.

Setting up 5 cameras/positions and moving to the appropriate view

In this, a click on a button would switch the view to a preset camera/position. I would set up five cameras (front, back, side, top and bottom) and clicking the back button, for example, would switch to that position.

Now, I have the base idea, but am lost about how to implement it. Does anyone have any pointers?

Thanks in advance.

<edit>

Doing it via the camera/position is preferred now that I think about it, though doing it both ways would teach me more.

Thanks again.
Posted By: painkiller

Re: Force Camera to View? - 04/17/11 16:26

front -> my.pan=0 my.tilt=0
back -> my.pan=180 my.tilt=0
side -> my.pan=90 my.tilt=0
top -> my.pan=0 my.tilt=-90
bottom-> my.pan=0 my.tilt=90
Posted By: Superku

Re: Force Camera to View? - 04/17/11 16:26

Quote:
Doing it via the camera/position is preferred

Then you should move the camera instead of rotating the model.

The following code should give you a good start:

Code:
BMAP* bmp_view_button1 = "filename here";
...

void view_button(var num) {

	if(player) {

		switch(num) {
			
			case 1:
			vec_set(player.pan,vector(180,0,0)); // front
			break;
			
			case 2:
			vec_set(player.pan,vector(0,0,0)); // back
			break;
			
			case 3:
			vec_set(player.pan,vector(90,0,0)); // side
			break;
			
			case 4:
			vec_set(player.pan,vector(0,90,0)); // top
			break;
			
			case 5:
			vec_set(player.pan,vector(0,-90,0)); // bottom
			
		}

		
	}
}

PANEL* pnl_view_buttons = {
	
	button(0,0,bmp_view_button1,bmp_view_button1,bmp_view_button1,view_button,NULL,NULL);
	...
	button(0,4 * your button height,bmp_view_button5,bmp_view_button5,bmp_view_button5,view_button,NULL,NULL);
	
	flags = SHOW;
	
}

action rotate()
{
	player = me;
	mouse_mode = 1;
	while(1)
	{
		if (mouse_left){
			my.pan += mouse_force.x;	
			my.tilt += mouse_force.y;
		}
		
		vec_set(mouse_pos,mouse_cursor);
		
		wait(1);
	}
}



I've assumed that your camera is at 0,0,0 and your model is in front of the camera, that means its position is x,0,0 (in WED).
Posted By: RealSerious3D

Re: Force Camera to View? - 04/17/11 16:37

You guys are great! Slowly, slowly I am starting to understand this. I used to be a bit afraid of programming, convincing myself that I could not do it. Now it is getting fun.

Thanks for the help!
Posted By: RealSerious3D

Re: Force Camera to View? - 04/17/11 17:28

Thanks Superku! That gave me just what I needed! Here's my working code:

Code:
//Rotate View Around Object Test

//Images
BMAP* top_view_button = "top_button.jpg";
BMAP* bottom_view_button = "bottom_button.jpg";
BMAP* front_view_button = "front_button.jpg";
BMAP* back_view_button = "back_button.jpg";
BMAP* side_view_button = "side_button.jpg";

//View Button
void view_button(var num) {
	if(player){
		switch(num){
			case 1:
			vec_set(player.pan,vector(0,90,0)); //top view
			break;
			case 2:
			vec_set(player.pan,vector(0,-90,0)); //bottom view
			break;
			case 3:
			vec_set(player.pan,vector(180,0,0)); //front view
			break;
			case 4:
			vec_set(player.pan,vector(0,0,0)); //back view
			break;
			case 5:
			vec_set(player.pan,vector(90,0,0)); //side view
			break;
	}
	}
}

//Panel
PANEL* buttons = {
	button(0,0,top_view_button,top_view_button,top_view_button,view_button,null,null);
	button(94,0,bottom_view_button,bottom_view_button,bottom_view_button,view_button,null,null);
	button(188,0,front_view_button,front_view_button,front_view_button,view_button,null,null);
	button(282,0,back_view_button,back_view_button,back_view_button,view_button,null,null);
	button(376,0,side_view_button,side_view_button,side_view_button,view_button,null,null);
	Flags = SHOW;
}

//Rotate Action
action rotate()
{
	player = me;
	mouse_mode = 1;
	while(1)
	{
		if (mouse_left){
			my.pan += mouse_force.x;	// mouse movement changes PAN 
			//my.pan = clamp(my.pan,-189,189);
			my.tilt += mouse_force.y;	// mouse movement changes TILT
			//my.tilt = clamp(my.tilt,-89,89); 
		}
		vec_set(mouse_pos,mouse_cursor);
		wait(1);
	}
}



I'll play with mouse overs and all that later. I am just happy to have working buttons that do what I want them to. This opens up a lot of things to me.

Thanks again!
Posted By: RealSerious3D

Re: Force Camera to View? - 04/17/11 17:57

What would be the command for setting the camera/position to a different DISTANCE from the object? I want to set up buttons for various distances, but don't know the command. I am guessing that I would replace "player.pan" with the command and then enter the proper arguments with the parenthesis that follow. I'm looking through the help docs, but having problems finding what I need.
Posted By: FoxHound

Re: Force Camera to View? - 04/17/11 18:06

How did you set up the view? IF it's like

camera.x = player.x + 200 * cos blah blah blah


Then swap the 200 for

var dist = 200;// im a global var

camera.x = player.x + dist

Then allow dist to be changed by anything, say the mouse wheel.
Posted By: RealSerious3D

Re: Force Camera to View? - 04/17/11 18:08

I set up the view by placing a POSITION in WED. So I am not sure what to do in this case.
Posted By: Superku

Re: Force Camera to View? - 04/17/11 18:09

Simply modify your view_button function and add more states (that is cases in the switch branch). There you could change the x-distance of the player to the camera. Example:

BMAP* close_button = "far_button.jpg";

case 6: // close
player.x = 50;
break;

case 7: // normal
player.x = 100;
break;

case 8: // far
player.x = 150;
break;


...
button(376,0,side_view_button,side_view_button,side_view_button,view_button,null,null);
button(xxx,0,close_button,....
Posted By: RealSerious3D

Re: Force Camera to View? - 04/17/11 18:13

Hi Superku,

Right, I figured that, but did not know the command. However, I don't have a "player" but just a POSITION that I set in WED. Do I have to set up a player (since it will never walk around)? Or can I move the actual POSITION item via code?

<edit>

Never mind. It works. Very simple. And that was what I was looking for.

Thanks.
Posted By: RealSerious3D

Re: Force Camera to View? - 04/17/11 18:26

Okay. Code now looks like this:

Code:
//Rotate View Around Object Test
//View Object from Different Distances

//Images
BMAP* top_view_button = "top_button.jpg";
BMAP* bottom_view_button = "bottom_button.jpg";
BMAP* front_view_button = "front_button.jpg";
BMAP* back_view_button = "back_button.jpg";
BMAP* side_view_button = "side_button.jpg";
BMAP* d0_view_button = "d0_button.jpg";
BMAP* d1_view_button = "d1_button.jpg";
BMAP* d2_view_button = "d2_button.jpg";
BMAP* d3_view_button = "d3_button.jpg";

//View Button
void view_button(var num) {
	if(player){
		switch(num){
			case 1:
			vec_set(player.pan,vector(0,90,0)); //top view
			break;
			case 2:
			vec_set(player.pan,vector(0,-90,0)); //bottom view
			break;
			case 3:
			vec_set(player.pan,vector(180,0,0)); //front view
			break;
			case 4:
			vec_set(player.pan,vector(0,0,0)); //back view
			break;
			case 5:
			vec_set(player.pan,vector(90,0,0)); //side view
			break;
			case 6:
			player.x = 56; //d1 view
			break;
			case 7:
			player.x = 100; //d1 view
			break;
			case 8:
			player.x = 150; //d1 view
			break;
			case 9:
			player.x = 200; //d1 view
			break;
			
	}
	}
}

//Panel
PANEL* buttons = {
	button(0,0,top_view_button,top_view_button,top_view_button,view_button,null,null);
	button(0,36,bottom_view_button,bottom_view_button,bottom_view_button,view_button,null,null);
	button(0,72,front_view_button,front_view_button,front_view_button,view_button,null,null);
	button(0,108,back_view_button,back_view_button,back_view_button,view_button,null,null);
	button(0,144,side_view_button,side_view_button,side_view_button,view_button,null,null);
	button(0,180,d0_view_button,d0_view_button,d0_view_button,view_button,null,null);
	button(0,216,d1_view_button,d1_view_button,d1_view_button,view_button,null,null);
	button(0,252,d2_view_button,d2_view_button,d2_view_button,view_button,null,null);
	button(0,288,d3_view_button,d3_view_button,d3_view_button,view_button,null,null);
	Flags = SHOW;
}

//Rotate Action
action rotate()
{
	player = me;
	mouse_mode = 1;
	while(1)
	{
		if (mouse_left){
			my.pan += mouse_force.x;	// mouse movement changes PAN 
			//my.pan = clamp(my.pan,-189,189);
			my.tilt += mouse_force.y;	// mouse movement changes TILT
			//my.tilt = clamp(my.tilt,-89,89); 
		}
		vec_set(mouse_pos,mouse_cursor);
		wait(1);
	}
}



Now, that moves the object that the action is attached to (when it comes to the distance) and that's fine for this. However, is there a way to move the position? Or if I had a player instead of a POSITION in WED, could I move that instead of the entity being viewed?

Later, what I want to do is set up several different positions around an entity and then, via clicking a button, have the camera jump to this position.

<edit>

Just had an idea: Can I set up several POSITIONS in WED and then have my distance buttons switch the view to the appropriate position?

In other words, I have pos_000 and pos_001. How could I have one button force the view to pos_000 and another to pos_001?

Thanks! laugh
Posted By: FoxHound

Re: Force Camera to View? - 04/17/11 22:32

A position is just a vector. So set up your positions and record the positions and have the player choose them using the buttons.
© 2024 lite-C Forums