Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (581) Games in Android Showcase (162) games submitted by our members Games in WIP (632) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 3d camera question  (Read 1008 times) 0 Members and 1 Guest are viewing this topic.
weston
 « Posted 2005-03-22 08:03:41 »

I started writing a camera class today (my first one) and its mostly done except one little thing that I can't seem to get right. First of all the camera is set up like a camera for a first person shooter, mouse looks around and ASDW moves. My problem is that when I turn my mouse I need the camera's translation to be rotated too. In other words, if I turn around 180 degrees using my mouse and then press the forward button, it should move me backwards. I tried multiplying my velocity by the same matrix that I use to rotate the camera, but I'm getting weird results. The directions seem to reverse sometimes, up goes down etc. its actually worse than this because sometimes up could move me left or right when pressing up. I'm just wondering if this is the right approach or if there is a better way to do it... how do you do it?

for(int i = 1; i > 0; i++)
System.out.println(i+" cups of java downed");
Daire Quinlan

Junior Devvie

 « Reply #1 - Posted 2005-03-22 08:41:17 »

well, it depends on how you're actually DOING your camera at the moment, You don't really say. Sounds like a classic example of gimbal lock to me. The way I've had my camera set up for quite some time seems to be the most widespread and convenient usage ( disregarding quaternion solutions ). I have 3 orthogonal vectors representing the Orthonormal base of the camera's transformation system. Essentially these can be plugged directly into a 3x3 matrix to compose the rotation part of the camera's transformation. When rotating I rotate two of the camera normals around the target normal. Every now and again you have to re-normalise to ensure its still orthogonal.

This has its advantages because you always have ready access to the three normals that represent the cameras view direction, the cameras 'up' direction and the 'side' direction of the camera. You can use these for a multitude of things, such as panning and dollying the camera, using the 'up' and 'side' vectors to construct billboards, etc etc.

Theres quite a few good tutorials on the net about the best way to construct your camera class, I'd suggest a bit of googling

D.
weston
 « Reply #2 - Posted 2005-03-22 17:19:29 »

The first method I used for implementing my camera class was actually the same method that you described. I was having the same problem I'm having now though, so I decided to switch to quaternions to avoid gimbal lock and hopefully find a solution to the movement problem. Sounds like I could have been ill informed when I read that gimbal lock could also occur using this method? So I currently have access to my forward vector and (correct me if I'm wrong) I should be able to calculate my up and side vectors from there. This is the part I don't get though, what do I need to do with this to rotate my movement (or my velocity, however you want to think about it) so that pressing forward will move me in the direction I'm facing (needs to work for left/right/back as well though). I'm guessing its going to be something fairly simple since none of the tutorials I read actually mentioned anything about it explicitly, which is why I would bother to ask on here. I was feeling about worn out on the subject yesterday (ready to give up more like it), but today's a new day and it looks like its time to go back to google..

for(int i = 1; i > 0; i++)
System.out.println(i+" cups of java downed");
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 MrMapcom (13 views) 2015-05-23 20:26:16 MrMapcom (19 views) 2015-05-23 20:23:34 Waterwolf (29 views) 2015-05-20 15:01:45 chrislo27 (35 views) 2015-05-20 03:42:21 BurntPizza (70 views) 2015-05-10 15:53:18 FrozenShade (55 views) 2015-05-07 09:11:21 TheLopais (218 views) 2015-05-06 13:36:48 TheLopais (202 views) 2015-05-06 13:35:14 TheLopais (207 views) 2015-05-06 13:33:39 TheLopais (226 views) 2015-05-06 13:32:48
 Spasi 32x BurntPizza 16x Riven 14x ra4king 12x theagentd 11x DavidBVal 11x Husk 11x EgonOlsen 11x KevinWorkman 9x princec 8x scanevaro 8x opiop65 7x Slyth2727 6x revers 6x KaiHH 6x SauronWatchesYou 6x
 List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org