Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 20:05
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
3 registered members (Grant, dr_panther, AndrewAMD), 1,379 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Isometric camera - need some help! #173832
12/19/07 20:09
12/19/07 20:09
Joined: May 2007
Posts: 34
California
DrGonzo Offline OP
Newbie
DrGonzo  Offline OP
Newbie

Joined: May 2007
Posts: 34
California
Hi,

I could use some help scripting a 3rd person isometric camera. I've looked at several tutorials
as well as tips posted in this forum, but I'm having a hard time pulling it all together.
I need an actual code sniplet that I can more or less paste into my main script, rather
than some general "Well! Have you looked at this tutorial???" advice. Thanks!

I'd like to be able to orbit the camera around the viewpoint/center of the screen
with the middle mouse button, and zoom in and out with the wheel.
The right mouse button should pan the viewpoint/center in X and Y.

Any help is very, very, very, very much appreciated!

Re: Isometric camera - need some help! [Re: DrGonzo] #173833
12/20/07 11:18
12/20/07 11:18
Joined: Aug 2005
Posts: 1,558
HK
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

Joined: Aug 2005
Posts: 1,558
HK
You're lucky, I've a little free time today.
Here is the code :
Code:

var speed = 5; // play with 5
var worldCentre;

function main()
{
level_load("yourLevel.wmb");
wait(2);

vec_set(worldCentre,vector(0,0,0));
mouse_mode = 1;

while(1)
{
mouse_pos.x = pointer.x;
mouse_pos.y = pointer.y;

vec_to_angle(camera.pan,vec_diff(temp,worldCentre,camera.x));

// zoom in/out
camera.arc += mickey.z * speed * time_step;
camera.arc = clamp(camera.arc,10,100);

// pan left/right
if (mouse_right)
{
vec_rotate(camera.x,vector(mouse_force.x * speed,0,0));
vec_add(camera.x,worldCentre);
}

// Orbit? don't know how do you achieve this,
// so this part maybe not exactly what you want.
// The camera will orbit around the world center vertically.
if (mouse_middle)
{
vec_rotate(camera.x,vector(0,speed * time_step,0));
vec_add(camera.x,worldCentre);
}

wait(1);
}
}



Hope this helps!

Re: Isometric camera - need some help! [Re: vlau] #173834
12/20/07 18:38
12/20/07 18:38
Joined: May 2007
Posts: 34
California
DrGonzo Offline OP
Newbie
DrGonzo  Offline OP
Newbie

Joined: May 2007
Posts: 34
California
Quote:

You're lucky, I've a little free time today.



Thanks vlau,
I tried your code but it didn't quite work for me.

Here's what I've hacked together so far:

Code:
var worldCenter;

function main
{

level_load ("cam.wmb");
wait(2);
vec_set(worldCenter,vector(-205, 0, 42));
mouse_mode = 1;

while(1)
{

if(mouse_middle == 1) // Orbit with middle mouse
{
camera.pan += mouse_force.x * 20 * time_step; // mouse movement changes PAN
camera.tilt += mouse_force.y * 20 * time_step; // mouse movement changes TILT
}

if(mouse_right == 1) // Pan with right mouse
{
worldCenter.x -= mouse_force.y * 40 * time_step;
worldCenter.y += mouse_force.x * 40 * time_step;
camera.x = worldCenter.x;
camera.y = worldCenter.y;
}

if(mickey.z != 0) // zoom with mouse wheel
{
vec_diff(temp,target.x,camera.x);
vec_scale(temp,((mickey.z * 1)/480));
vec_add(camera.x,temp);

worldCenter.x = camera.x;
worldCenter.y = camera.y;
worldCenter.z = camera.z;
}

mouse_pos.x = mouse_cursor.x; // update mouse position.
mouse_pos.y = mouse_cursor.y; // update mouse position.

wait(1);
}
}


This works pretty good, except that the pan directions are all screwed up
after a camera rotation.

Here are my goals again:
After pressing the middle mouse button, the camera should freely rotate around
the current center of the screen (focal point), following the mouse movements.
The zoom wheel should zoom in and out towards that center.
After pressing the right mouse button, the camera and the center of the screen
(or the focal point) should pan in x and y, following the mouse movements.

This is a great 3rd person camera movement and I would really like to get some
help in figuring out on how to code this.

Thanks!

Re: Isometric camera - need some help! [Re: DrGonzo] #173835
12/20/07 18:58
12/20/07 18:58
Joined: Aug 2005
Posts: 1,558
HK
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

Joined: Aug 2005
Posts: 1,558
HK
EDIT
----
Quote:


After pressing the right mouse button, the camera and the center of the screen
(or the focal point) should pan in x and y, following the mouse movements.





I've read this sentence several times still don't really get what you
want. Is it move the camera left/right/forward/backward and still looking at
worldCenter?

Have you already solved the problem of zoom in/out and orbit the camera?

Sorry if I'm misunderstanding you, it's been 3:00AM here, I need
some sleep.













Last edited by vlau; 12/20/07 19:28.
Re: Isometric camera - need some help! [Re: vlau] #173836
12/20/07 19:55
12/20/07 19:55
Joined: May 2007
Posts: 34
California
DrGonzo Offline OP
Newbie
DrGonzo  Offline OP
Newbie

Joined: May 2007
Posts: 34
California
Get some rest, brother!

After pressing the right mouse button, the level should scroll left/right
forward/backward following the mouse movements. So the camera should pan
over the level and not be fixed on the "old" center of the screen.

Zooming and rotating works OK, although I haven't used any of the "fancy"
sinus, cosinus or vec_to_angle stuff in there.
I've been writing programs for over 20 years, but I just can't get my head
around this vector stuff..

Maybe this graphic might help explaining myself?



Last edited by DrGonzo; 12/20/07 20:47.
Re: Isometric camera - need some help! [Re: DrGonzo] #173837
12/21/07 09:30
12/21/07 09:30
Joined: Aug 2005
Posts: 1,558
HK
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

Joined: Aug 2005
Posts: 1,558
HK
Morning Nice diagram also.

This should work :
Code:

if(mouse_right == 1) // Pan with right mouse
{
camera.x -= mouse_force.y * 40 * time_step;
camera.y += mouse_force.x * 40 * time_step;
}



One more thing is stored the camera default position,
if you go too far in the level, you may press SPACEBAR
and return there at anytime.

Code:

var camPos;
.....
.....
vec_set(camPos,camera.x);
while(1)
{
......
......

if (key_SPACE)
{
vec_set(camera.x,camPos);
}
}



Re: Isometric camera - need some help! [Re: vlau] #173838
12/21/07 10:23
12/21/07 10:23
Joined: Aug 2005
Posts: 1,558
HK
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

Joined: Aug 2005
Posts: 1,558
HK
As I re-read your right mouse code, it seems that you want to
move the worldCenter also while keeping the camera at certain
distance, if yes.....

Code:

if(mouse_right == 1) // Pan with right mouse
{
vec_diff(temp,worldCenter.x,camera.x);
camera.x -= mouse_force.y * 40 * time_step;
camera.y += mouse_force.x * 40 * time_step;

worldCenter.x = camera.x + temp.x;
worldCenter.y = camera.y + temp.y;
worldCenter.z = camera.z + temp.z;
}



If not, just ignore it.

Re: Isometric camera - need some help! [Re: vlau] #173839
12/21/07 16:11
12/21/07 16:11
Joined: May 2007
Posts: 34
California
DrGonzo Offline OP
Newbie
DrGonzo  Offline OP
Newbie

Joined: May 2007
Posts: 34
California
Quote:

Morning Nice diagram also.



Thanks!

Ok, I thought of a good example of the kind of camera movement
I was hoping to achieve:

The 3D view in WED!
The camera control in there is almost(!) exactly what I'm looking
for. (Should've thought about that sooner..)

When you press the right MB, the camera pans left/right (and for some
reason up/down instead of along the Y direction).
When you press the right MB + ALT, the camera rotates around the center
of the screen.
That's what I'm looking for (except using the middle MB for rotation
and panning with the right MB along X and Y).
The wheel should zoom in/out.

The reason why I need help with this is that most of the camera tutorials I
looked at always have the camera following a player entity, and that's just
not what I'm looking for.

This can't be that hard to code, can it?

Re: Isometric camera - need some help! [Re: DrGonzo] #173840
12/21/07 16:39
12/21/07 16:39
Joined: Aug 2005
Posts: 1,558
HK
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

Joined: Aug 2005
Posts: 1,558
HK
Sure, and I think you can write the rest of
the code yourself, just change the line
if(mouse_right==1) to if(mouse_right==1 && key_alt).

Re: Isometric camera - need some help! [Re: vlau] #173841
12/22/07 09:52
12/22/07 09:52
Joined: May 2007
Posts: 34
California
DrGonzo Offline OP
Newbie
DrGonzo  Offline OP
Newbie

Joined: May 2007
Posts: 34
California
That's some help you get in here..

Page 1 of 2 1 2

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