2 registered members (AndrewAMD, 7th_zorro),
1,285
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
vlau
Serious User
|
Serious User
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
OP
Newbie
|
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
vlau
Serious User
|
Serious User
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
OP
Newbie
|
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
vlau
Serious User
|
Serious User
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
vlau
Serious User
|
Serious User
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
OP
Newbie
|
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?
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|