Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 04 Jan 2011
Offline Last Active Dec 15 2012 10:01 AM

Topics I've Started

Camera, Player, and GameObject Architecture

02 December 2012 - 06:43 AM

I'm currently refactoring.

I want my camera to follow a player, rather than being completely detached in third-person.

Goal: Allow a third-person camera while reserving the right to attach the camera to arbitrary objects.

What are some alternatives when constructing the player, camera, and game objects to allow this?

I currently have:
Input -> InputManager -> Camera => Modified Camera Position/Orientation

I've considered attaching the camera to an object (for instance, the player), and allowing the camera to modify the player position (since the camera receives the input). But this seems ludicrous!

Should the InputManager be provided with which object it should affect? And, if the camera happens to be attached to the affected object, that object is responsible for updating the position/orientation of the camera?
Input -> InputManager -> PlayerControlledObject -> Camera => Modified Camera Position/Orientation

Could anyone point me to a good example of how to do this, which allows for a good amount of flexibility in the future?


Using : JOGL 2.0

Quaternion Test Data

19 January 2011 - 03:15 AM

Perhaps you know where to find some test data for Quaternion rotations.

I'm writing some JUnit test cases for my Quaternion class and would like to find some input/output data from series of arbitrary Quaternion operations.

Thanks in advance.

Lighting Trouble

10 January 2011 - 08:43 AM

I'm attempting to enable lighting on Android, OpenGL ES 1.x, right now, only on the Android Emulator.

I've successfully imported some OBJs into a scene and rendered them, moved the camera around etc... but when I add these lines to my GLSurfaceView :: onSurfaceCreated, there is no visible change

My normals are being imported as well from the OBJ, but even if those were incorrect, shouldn't the ambient lighting have a noticable difference?

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
 float[] global_ambient = { 0.2f, 0.2f, 0.2f, 1.0f };
 gl.glLightModelfv(GL10.GL_LIGHT_MODEL_AMBIENT, global_ambient,0);
 float[] lightAmbient = {0.1f,0.1f,0.1f,1.0f};
 float[] diffuseLight = { 0.8f, 0.8f, 0.8f, 1.0f };
 float[] specularLight = { 0.5f, 0.5f, 0.5f, 1.0f };
 float[] position = { 0f, -20f, 0f, 1.0f
 // Assign created components to GL_LIGHT0
 gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbient, 0);
 gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, diffuseLight, 0);
 gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_SPECULAR, specularLight, 0);
 gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, position, 0);

Is there anything glaringly incorrect with the above? Any pointed questions which could possibly help me figure out what's going on?


Quaternion Camera [Solved-Thanks]

04 January 2011 - 09:32 PM

I'm working on my Camera class. I'm trying to get the correct behavior using Quaternions.

My goal: React to a mouse drag in a trackball-like style camera rotation. That is, imagine the camera is in the center of a unit-sphere, aligned so the view is down the -Z axis. In the case of a mouse drag in the Y direction, the camera's sphere/trackball should be rotated around the local X axis (or "right" vector). And, similarly, in the case of a X mouse drag, the sphere/camera should be rotated around the local Y axis.

Right now, my programme exhibits what seems as small rotations around the DIR vector... I would really appreciate some help.

Thanks in advance.

This method receives the deltas in the x/y directions according to the mouse's last position.
It should apply the appropriate rotation to the UP and DIR vectors, where DIR is the looking direction of the camera.

public void adjustVector(float x, float y){
// TODO Change x/y to radians instead
float sensitivity = 0.00001f;

Vector3d right = up.cross(dir, up);

// orientation is a Quaternion
// rotate accepts a Vector as the axis, and a float as the angle
orientation = orientation.rotate(up,sensitivity*x);
orientation = orientation.rotate(right,sensitivity*y);

// These modify the vector directly

// Method to apply a rotation to the current quaternion and return a new

public Quaternion rotate(Vector3d axis, float angle) {
return new Quaternion(axis, angle).times(this);

// Axis/angle constructor

public Quaternion(Vector3d axis, float angle){
float s = (float) Math.sin(angle/2);
this.x = axis.x * s;
this.y = axis.y * s;
this.z = axis.z * s;
this.w = (float) Math.cos(angle/2;

// Method to apply the quaternion rotation to the vector "this"

public void apply(Quaternion orientation) {

// The constructor accepts in order w,x,y,z
// This is the vector disguised as a quaternion
Quaternion disguised = new Quaternion(0,x,y,z);

Quaternion conjugate = orientation.conjugate();

Quaternion step1 = orientation.times(disguised);

Quaternion step2 = step1.times(conjugate);

this.x = step2.x;
this.y = step2.y;
this.z = step2.z;

[Edited by - roguan on January 5, 2011 4:35:55 AM]