Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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 837 times)
0 Members and 1 Guest are viewing this topic.
Offline weston

Junior Member





« Posted 2005-03-22 09: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 Member





« Reply #1 - Posted 2005-03-22 09: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

D.
Offline weston

Junior Member





« Reply #2 - Posted 2005-03-22 18: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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (22 views)
2014-04-15 18:08:23

BurntPizza (17 views)
2014-04-15 03:46:01

UprightPath (31 views)
2014-04-14 17:39:50

UprightPath (15 views)
2014-04-14 17:35:47

Porlus (31 views)
2014-04-14 15:48:38

tom_mai78101 (57 views)
2014-04-10 04:04:31

BurntPizza (115 views)
2014-04-08 23:06:04

tom_mai78101 (214 views)
2014-04-05 13:34:39

trollwarrior1 (182 views)
2014-04-04 12:06:45

CJLetsGame (189 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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
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!