|
Force Camera to View?
#367749
04/17/11 16:00
04/17/11 16:00
|
Joined: Oct 2010
Posts: 346 USA
RealSerious3D
OP
Senior Member
|
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:
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 modelIn 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 viewIn 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
Serious User
|
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
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
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:
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: RealSerious3D]
#367757
04/17/11 17:28
04/17/11 17:28
|
Joined: Oct 2010
Posts: 346 USA
RealSerious3D
OP
Senior Member
|
OP
Senior Member
Joined: Oct 2010
Posts: 346
USA
|
Thanks Superku! That gave me just what I needed! Here's my working 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]
#367761
04/17/11 18:06
04/17/11 18:06
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
Expert
|
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: RealSerious3D]
#367763
04/17/11 18:09
04/17/11 18:09
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
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
OP
Senior Member
|
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.
|
|
|
|