Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (EternallyCurious, Quad, vicknick), 700 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Force Camera to View? #367749
04/17/11 16:00
04/17/11 16:00
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
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.

Last edited by RealSerious3D; 04/17/11 16:03.
Re: Force Camera to View? [Re: RealSerious3D] #367750
04/17/11 16:26
04/17/11 16:26
Joined: Aug 2009
Posts: 1,438
Spain
painkiller Offline
Serious User
painkiller  Offline
Serious User

Joined: Aug 2009
Posts: 1,438
Spain
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

Last edited by painkiller; 04/17/11 16:28.

3D Gamestudio A8 Pro
AMD FX 8350 4.00 Ghz
16GB RAM
Gigabyte GeForce GTX 960 4GB
Re: Force Camera to View? [Re: RealSerious3D] #367751
04/17/11 16:26
04/17/11 16:26
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
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).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Force Camera to View? [Re: Superku] #367753
04/17/11 16:37
04/17/11 16:37
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
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!

Re: Force Camera to View? [Re: RealSerious3D] #367757
04/17/11 17:28
04/17/11 17:28
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
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!

Re: Force Camera to View? [Re: RealSerious3D] #367759
04/17/11 17:57
04/17/11 17:57
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
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.

Re: Force Camera to View? [Re: RealSerious3D] #367761
04/17/11 18:06
04/17/11 18:06
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline
Expert
FoxHound  Offline
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
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.


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: Force Camera to View? [Re: FoxHound] #367762
04/17/11 18:08
04/17/11 18:08
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
I set up the view by placing a POSITION in WED. So I am not sure what to do in this case.

Re: Force Camera to View? [Re: RealSerious3D] #367763
04/17/11 18:09
04/17/11 18:09
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
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,....


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Force Camera to View? [Re: Superku] #367764
04/17/11 18:13
04/17/11 18:13
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
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.

Last edited by RealSerious3D; 04/17/11 18:15.
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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