Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (685)
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 1090 times)
0 Members and 1 Guest are viewing this topic.
Offline 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");
Offline 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  Smiley

Offline 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.

Dwinin (59 views)
2015-11-07 13:29:08

Rems19 (72 views)
2015-10-31 01:36:56

Rems19 (63 views)
2015-10-31 01:32:37

williamwoles (101 views)
2015-10-23 10:42:59

williamwoles (87 views)
2015-10-23 10:42:45

Jervac_ (102 views)
2015-10-18 23:29:12

DarkCart (128 views)
2015-10-16 00:58:11

KaiHH (112 views)
2015-10-11 14:10:14

KaiHH (148 views)
2015-10-11 13:26:18

BurntPizza (162 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 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‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!