Hello there! This is my Quaternion Camera Class:
Quaternion Class:
Vector class:
Point2D class:
This is an excerpt of my InputHandle class:
Then you have to define a set of boolean methods in your renderer class like this one (if you want to do it like I did):
Then you define a Update() method that has to be called in your Display() method like:
Finally, after your glLoadIdentity you should call:
qCam.look(gl,glu);
As you may have noticed, this code is uncommented… I have not yet had the time to do it Anyway if there is something that you do not understand I’ll be happy to clarify every doubt.
There are some things in QuaternionCam that are only needed by my Project. You can delete the Util class references and the Frustum one (I’m currently implementing a Frustum Culling technique).
I followed the “industry” 's standard in term of keyboard layout. You have the usual WASD keys for movement and the mouse for looking around. In the mouselook method movement is capped to a certain degree. In that method you’ll notice that you’ll have to use the Java Robot class to return the pointer to the center. Is there a better way to do it?
I encourage you to try this because there’s a small bug in orbiting up/down. In theory you should rotate the viewing vector around the X-axis. If you try to rotate looking Norh/South it works fine, If you try to rotate Up/down in a east/west sense it doesn’t work… You should try and look and you’ll understand.
Orbiting left/right works fine although I have net yet understood how I can influence the radius of rotation.
Hope this helps.
I’m stuck on the same issue described by AvengerDr here. After 1.5 years does anyone have any new insight?
Wouldn’t it simply be a mater of performing a translation prior to applying the camera rotation?
Such as:
// Position camera 10 points on the z axis (10 unit radius)
gl.glTranslatef(0, 0, 10);
// Apply camera rotation (note: getRotation is simply a method that would convert the quaternion rotation to a 4x4 matrix float[16])
gl.glMultMatrixf( camera.getRotationMatrix() );
// Translate to the position of the thing your orbiting (another fake method that returns the position of the thing your obiting)
gl.glTranslatefv( orbitThing.getPosition() );
Of course some of those methods you will have to map to your class, but you have a quaternion for the camera, so you can easily make a matrix from it, and of course, you must of the position of the thing your orbiting.
I think that should about do it… unless I am misunderstanding your issue.
The gleem ExaminerViewer has a mode which rotates around a focal point at a specified distance from the camera. You might be able to borrow some of the math from there, or just use the class directly. It supports only mouse input, not keyboard input, however.
ahh Vorax, that wasn’t the issue I was referring to. Thanks though!
“I encourage you to try this because there’s a small bug in orbiting up/down. In theory you should rotate the viewing vector around the X-axis. If you try to rotate looking Norh/South it works fine, If you try to rotate Up/down in a east/west sense it doesn’t work… You should try and look and you’ll understand.”
That was the one I was talking about.
Ken, I checked out the ExamineViewer. I’m afraid I can’t make heads or tails of what it’s doing I’m very new to OpenGL and that class is jam packed with things that I have no understanding of.
I noticed this thread and thought I would post to it.
I have created a camera class that is structured for easy use. The code is very isolated from the engine and has lots of comments.
It does both Pan and Orbit style camera using both Arcball and YawPitch algorithms. The camera is fully functional at all orientations, up, down, left, right etc…
I also added Roll correction using lookAt method with the Arcball style. Arcballs introduce twists when implementing lookAts. I finally figured
out how to correct this and I have commented to code, for me as well.
If you are interested the code it is at:
http://www.distanthumans.info/programming/java/misc.php
or more specifically:
http://www.distanthumans.info/programming/java/projects/gloctree/GLOctree_2_24.jar
Don’t worry about the rest of the code.
The camera code is all in the “view” package of the project. To instanciate it take a look at Database.Database() and to use it look at GlRender.render(). You will see code like: gl.glLoadMatrixf(camera.getTransformArray()); in the render method.
As with most cameras the motion is handled with mouse input. It is simple, just look at say, GLRenderLeft.mouseDragged(), mousePressed() and mouseReleased()
Let me know if this helps.
Why does your Quaternion.inverse() method say;
Quaternion Q=new Quaternion();
Q=this;
...
Isn’t that the same as saying Quaternion Q = this; ?
I’m having trouble with inverses in my own implementation, but I thought that was odd.
yeah that’s what I was thinking too. When I made it I made a new constructor that created a copy of the old one so the new line became Quaternion q = new Quaternion(this); Doesn’t seem to change any of the results though.
kick;)
is there a way to specify the ‘up vector’ coz in my application the upVector is 0,0,1 not 0,1,0 so using the lookAt function gives not the desired results( everything is upside down
paul