Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,449 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
rotate camera around center #404933
07/19/12 10:37
07/19/12 10:37
Joined: Apr 2011
Posts: 40
germany
W
Wollez Offline OP
Newbie
Wollez  Offline OP
Newbie
W

Joined: Apr 2011
Posts: 40
germany
Hi guys,

I'm currently working on a third-person game and want to rotate the camera around my player with the mouse.
This is how my script looks at the moment:
Code:
ANGLE vAng;
VECTOR vec_cam;
	        vAng.pan -= mouse_force.x;
                camera .pan -= mouse_force.x;
		vec_rotate(vec_cam, vAng);
		camera.x = ent_for_camera.x + vec_cam.x;
		camera.y = ent_for_camera.y + vec_cam.y;
		camera.z = ent_for_camera.z + vec_cam.z;


but the camera flies around the model all the time, not just when I move the mouse and the pan doesn't seem to chane either
thanks:D

Re: rotate camera around center [Re: Wollez] #404934
07/19/12 10:46
07/19/12 10:46
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline
Serious User
Rackscha  Offline
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
which values are set for vec_cam? cant see an initialization.


MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development

Re: rotate camera around center [Re: Rackscha] #404935
07/19/12 10:58
07/19/12 10:58
Joined: Apr 2011
Posts: 40
germany
W
Wollez Offline OP
Newbie
Wollez  Offline OP
Newbie
W

Joined: Apr 2011
Posts: 40
germany
sorry, I cut that out, but I have it in my actual script, I just set it to zero, same with vAng;)

Re: rotate camera around center [Re: Wollez] #405215
07/26/12 03:50
07/26/12 03:50
Joined: Apr 2005
Posts: 3,076
Germany, NRW
rvL_eXile Offline

3D Artist
rvL_eXile  Offline

3D Artist

Joined: Apr 2005
Posts: 3,076
Germany, NRW
play a bit with this snippet:

Code:
var current_angle = 10;
var rotation_active = 0;

Function Camera_fnc
{
     Var Temp_var;
     Temp_Var=current_angle+360;
     
      camera.x = sin(current_angle) * 3500;
      camera.y = cos(current_angle) * 3500;
      camera.z = 2030;
      vec_diff(temp,midpoint_ent.x,camera.x);
      vec_to_angle(camera.pan,temp);
      
      
     while (mouse_middle==1)
     {
      current_angle = min(current_angle + mouse_force.x*time_step*6,temp_var);
      
      camera.x = sin(current_angle) * 3500;
      camera.y = cos(current_angle) * 3500;
      camera.z = 2030;
      
      vec_diff(temp,midpoint_ent.x,camera.x);
      vec_to_angle(camera.pan,temp);      
      wait(1);
     }


   wait(1);
 
}

on_mouse_middle=camera_fnc();




Tutorials:
[Blender]Terrain creation ENG/GER
[Blender]Low Poly Tree Modeling
[GIMP]Create a Texture for Terrains
CLICK HERE


Re: rotate camera around center [Re: Wollez] #405583
08/02/12 17:11
08/02/12 17:11
Joined: Jul 2002
Posts: 3,208
Germany
Error014 Offline
Expert
Error014  Offline
Expert

Joined: Jul 2002
Posts: 3,208
Germany
Originally Posted By: Wollez
sorry, I cut that out, but I have it in my actual script, I just set it to zero, same with vAng;)


See, there's a problem.

Try to imagine what we're doing. We have your entity somewhere, and then, we want to place the camera at some distance to that, right? And in what direction should be dependant on vAng.

However, we can rotate vec_cam all we want - if you set it to zero, it's the nullvector. That one will stay (0,0,0), no matter how you rotate it. And that does make sense, doesn't it? Imagine you ROTATING an arrow - it keeps it's length. If it was length 5 before, it'll be length 5 after rotating. And if it was length 0, well... the arrow will still be of length zero.
So if you later add zeros to your entities' position, nothing will happen.

So, let's correct that:

Code:
[...]
//We're probably in a while() { .. wait(1); } loop here
	        vAng.pan -= mouse_force.x*time_step*10;
                camera .pan -= mouse_force.x*time_step*10;
//set vec_cam to a default value
		vec_set(vec_cam,vector(-100,0,0));
		vec_rotate(vec_cam, vAng);
		vec_set(camera.x,ent_for_camera.x);
		vec_add(camera.x,vec_cam); //A little shorter
		//But really, it's just the same as that:
//		camera.x = ent_for_camera.x + vec_cam.x;
//		camera.y = ent_for_camera.y + vec_cam.y;
//		camera.z = ent_for_camera.z + vec_cam.z;



100 is the distance of the camera to the entity (in quants) - you'll have to play with that value, since I don't know the scale of your level. It's negative here - because we want to move BEHIND the entity (we want to see it!).

Notice the other change - I've added *10*time_step. time_step is a value that depends on your framerate - for high framerate, time_step will be low, and vice versa. The reason to add this is that you want the game to "feel" and control the same, whether its running at 60 or 200 fps. But in the latter case, such a "while(..) { .. wait(1); }" loop will run 200 times in one second, and thus, we'll actually add/subtract much higher values from camera.pan than we were intending to.


A final note, unless you really need vAng to be different from camera.pan, there's probably no reason for you to use it -- you could use camera.pan directly in vec_rotate.




Last, but not least, a word to rvL_exile's script. Typos aside (like the "()" at the very bottom (since you want to assign the function to on_middle_mouse, NOT the return value), or the "Var" in the first line of the function), you would be able to rotate the camera, but about the origin of the level (0,0,0). Compare with the snippet above - note how we set the camera first to the entities' position, and THEN added the rotated vector? The result is, then:

campos = entity.pos + rotatedVector

but here, it's just

campos = rotatedVector

which is really just the same as if entity.pos was all zeros.
To make up for that, we rotate the camera's angle to look at the player. It's a very different kind of camera behaviour, but there's still a lot one can learn from that snippet!

It's not using vec_rotate, but rather does the same thing "by hand". It also isn't affected by the tilt-value, so the rotation will only ever be in the x-y-plane (and never change z). So, well, not quite the same thing, then!
The whole thing can be written as a multiplication with a rotational matrix - and it's not as complicated as it sounds here. Still, I think I've written enough for the moment. Feel free to ask questions, if you still have any!



Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!

Gamestudio download | 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