0

I'm trying to make it so that I can move a camera around a world, however I'm having a tough time finding resources that will explain this clearly. Most resources I have found are explaining (At least I think they are) how to move the world around the camera, without the camera moving, to create the illusion of movement.

I have implemented this, however rotation of the world results in the world spinning around the origin of the world rather than the camera. Now I am of the mindset that I would get far better results if I could move the camera through the world and rotate it independently. I am asking which way is better for creating camera movement in JOGL.. Moving the world around the camera, or moving the camera through the world?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Stromata
  • 245
  • 4
  • 9
  • Something similar to waaitt's suggestion is implemented in JMonkeyEngine 3 which has a JOGL backend, it can be a source of inspiration. If you prefer using the fixed pipeline, modify the model-view matrix, simply use gluLookAt. Have a look at this question: http://stackoverflow.com/questions/1342149/how-would-one-implement-an-fps-camera – gouessej Jul 07 '14 at 10:46
  • Moving the camera is identical to moving the world in the opposite direction. The problem you're facing is that rotations happen about the origin. If your camera isn't at the (world) origin you'll need to first translate it to the origin, perform your rotations, and then translate it back to its proper position. – beaker Jul 07 '14 at 15:55

1 Answers1

0

Use modern openGL with shaders so you can do the latter. Store the transform on the camera object and use that to compute the View Matrix which gets passed to your objects. Try having multiple cameras and multiple viewports.

//C++
//choose camera to use in the viewport
for (int i = 0; i < myWin.allObj.size(); ++i)
{
    if (myWin.allObj[i]->name->val_s == "persp1") //set persp1 by default
        selCam = myWin.allObj[i];
}

//rendering loop
ViewM_t = glm::translate(glm::mat4(), -selCam->t->val_3);
ViewM_rx = glm::rotate(glm::mat4(), selCam->r->val_3.x, myWin.axisX);
ViewM_ry = glm::rotate(glm::mat4(), selCam->r->val_3.y, myWin.axisY);
ViewM = ViewM_t * ViewM_rx * ViewM_ry;

//in object
compute MVP and upload to GPU
bvs
  • 340
  • 5
  • 20