Hi, all,
Before this email, I searched mail archieve and read all the posting
related to camera, expecially "Positioning and viewers camera" (around
2008 Jun) and "Camera Control and view matrix" (around 2008 Sep). But I
still cannot manually control the camera orientation. As a new OSG user,
your kind help is appreciated.
I did test code according to OpenSceneGraph Tutorials "Positioning a
Camera with a User-Defined Matrix". I have a problem for do a rotation
from "Y" up to "Z" up.
In the following test code, if code in /*test 1*/ section is used, I got
the top view instead of expected vehicle driving view;
if code in /*test 2*/section is used, the display is some pieces of
color (jump around), cannot get the right view.
Here is piece of my test code:
--------------------------------------------------------
//Declare and set a matrix to be used for the camera
osg::Matrixd cameraTrans;
osg::Matrixd cameraRotation;
osg::Matrixd myCameraMatrix;
double roll,pitch,yaw, x, y, z;
/*in world coordinate ---start position for testing; z=z0+3 for
driver's eyepoint height*/
roll=0.0;
pitch=0.0;
yaw=30.0;
x=121937.02;
y=-15370.085;
z=10.2275+3;
cameraRotation.makeRotate(osg::DegreesToRadians(roll),
osg::Vec3(0.0f,1.0f,0.0f), //roll
osg::DegreesToRadians(pitch),
osg::Vec3(1.0f,0.0f,0.0f), //pitch
osg::DegreesToRadians(yaw),
osg::Vec3(0.0f ,0.0f,1.0f)); //heading
cameraTrans.makeTranslate(x, y, z);
myCameraMatrix=cameraRotation*cameraTrans;
while(!viewer.done()){
/*Test 1*/
osg::Matrixd i=myCameraMatrix.inverse(myCameraMatrix);
viewer.getCamera()->setViewMatrix(i);
/*Test 1 end*/
/*Test 2
// osg::Matrixd
j=myCameraMatrix.preMult(osg::Matrix::rotate(osg::PI_2, osg::X_AXIS));
// osg::Matrixd i=j.inverse(j);
// viewer.getCamera()->setViewMatrix(i);
Test 2 end*/
viewer.frame();
}
-------------------------------------
Thanks again
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org