[gameprogrammer] Re: "scrolling" a camera in 3d

  • From: Alan Wolfe <alan.wolfe@xxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Tue, 20 Mar 2012 11:01:29 -0700

Oh i see.

So is it that no matter what way the camera is rotated / facing on the
plane in your rotated isometric view, that you want to be able to say "move
forward" (or backwards) and that it will move forward (or backwards) in a
camera relative way, but preserve it's distance from the map plane? (and be
able to do the same for left and right)

If so, assuming the map is X,Z the general idea is...

for handling forward, backwards movement:
1) get the forward vector of the camera
2) set the y component to zero
3) normalize the vector
4) multiply the vector by how far you want to move the camera forward
(positive numbers) or backwards (negative numbers)
5) move the camera!
6) (note that this breaks down if the camera is pointed straight up or
straight down!)

for handling left, right movement:
1) get the left vector of the camera
2) set the y component to zero
3) normalize the vector
4) multiply the vector by how far you want to move left or right
5) move the camera!
6) (this breaks down if the camera is pointed specific ways too)

How to combine forward/backwards and left/right movement:
1) calculate the vector for each axis as described above, finishing step 3
for each
2) add the two vectors together and normalize the resulting vector again
3) multiply the vector by how far you want to move the camera
4) move the camera!

Is that more what you were looking for?  (:

There is a way to more mathematically generalize it so this would work on
any arbitrary plane, instead of just the X/Z plane, but if you know your
map will always be X/Z, there's no reason to fight with the more complex
(and more computationally expensive) math if you don't have to.


On Tue, Mar 20, 2012 at 10:46 AM, <luo_hei@xxxxxxxx> wrote:

> On 20/03/12 12:33, Alan Wolfe wrote:
>
>> Well for what it's worth if you had a pure top down or side view game,
>> you could use the up vector and the left vector to pan the camera, like
>> Jonathan was saying.
>>
>> (if you are missing the left vector on the camera class, but you have up
>> and forward, you can cross product them to get the left vector)
>>
>> For an isometric view however I believe it is a bit more complex,
>> because if you move the camera along it's up or left vector, you'll
>> start moving farther or closer to the ground since the camera isn't
>> perpendicular to the layout of the map.
>>
>> In isometric mode you have to know the layout of the map and move your
>> camera accordingly.
>>
>> For instance if your map is laid out on the X/Z plane, you would just
>> move your camera on the X and Z directions to pan it around, totally
>> ignoring the direction the camera was pointing because it isn't relevant.
>>
>> If your map is laid out on the X/Z plane, you would move your camera on
>> the X and Z directions to pan it around.
>>
>> You can get more complex if your world isn't flat, like having the
>> camera move on the 3rd axis so it doesn't clip with the ground geometry
>> (etc) but i'd get the simple plane camera movement working first before
>> moving onto that (:
>>
>
> Well, I will deal with non flat map later when I add the terrain (thats
> another problem). The problem here is that even when the world starts X/Z
> oriented, when I rotate the camera the orientation changes, so simply
> displacing on X or Z doesnt works, depending on the angle the camera could
> be moving backwards when you expect it to move to the right.
>
>
> --
> Roger D. Vargas
> Using Gentoo Linux 2010
> La unica forma de encontrar los limites de lo posible es yendo mas
> alla de ellos, hacia lo imposible
>
> ---------------------
> To unsubscribe go to 
> http://gameprogrammer.com/**mailinglist.html<http://gameprogrammer.com/mailinglist.html>
>
>
>

Other related posts: