Changed the slide coordinates system so that the bottom left hand corner of the
slide is 0,0,0 and the top right is 1,1,0, and the eye point is at the appex of a frustum at x,y,1.
This commit is contained in:
@@ -228,16 +228,42 @@ void ReaderWriterSS3D::parseModel(SlideShowConstructor& constructor, xmlDocPtr d
|
||||
else std::cout<<"Parser error - coordinate_frame=\""<<str<<"\" unrecongonized value"<<std::endl;
|
||||
}
|
||||
|
||||
if (getProperty(cur, "position", str))
|
||||
if (coordinate_frame==SlideShowConstructor::SLIDE)
|
||||
{
|
||||
bool fail = false;
|
||||
if (str=="center") position.set(0.0f,1.0f,0.0f);
|
||||
else if (str=="eye") position.set(0.0f,0.0f,0.0f);
|
||||
else if (!read(str,position)) fail = true;
|
||||
position.set(0.5,0.5,0.0);
|
||||
|
||||
if (fail) std::cout<<"Parser error - position=\""<<str<<"\" unrecongonized value"<<std::endl;
|
||||
else std::cout<<"Read position="<<position<<std::endl;
|
||||
if (getProperty(cur, "position", str))
|
||||
{
|
||||
osg::Vec2 vec2;
|
||||
osg::Vec3 vec3;
|
||||
|
||||
bool fail = false;
|
||||
if (str=="center") position.set(0.5f,.5f,0.0f);
|
||||
else if (str=="eye") position.set(0.0f,0.0f,1.0f);
|
||||
else if (read(str,vec3)) position = vec3;
|
||||
else if (read(str,vec2)) position.set(vec3.x(),vec3.y(),0.0f);
|
||||
else fail = true;
|
||||
|
||||
if (fail) std::cout<<"Parser error - position=\""<<str<<"\" unrecongonized value"<<std::endl;
|
||||
else std::cout<<"Read position="<<position<<std::endl;
|
||||
}
|
||||
}
|
||||
else // coordinate_frame==SlideShowConstructor::MODEL
|
||||
{
|
||||
position.set(0.0,0.0,0.0);
|
||||
|
||||
if (getProperty(cur, "position", str))
|
||||
{
|
||||
bool fail = false;
|
||||
if (str=="center") position.set(0.0f,1.0f,0.0f);
|
||||
else if (str=="eye") position.set(0.0f,0.0f,0.0f);
|
||||
else if (!read(str,position)) fail = true;
|
||||
|
||||
if (fail) std::cout<<"Parser error - position=\""<<str<<"\" unrecongonized value"<<std::endl;
|
||||
else std::cout<<"Read position="<<position<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (getProperty(cur, "scale", scale))
|
||||
{
|
||||
|
||||
@@ -383,12 +383,12 @@ void SlideShowConstructor::addModel(const std::string& filename, CoordinateFrame
|
||||
|
||||
if (coordinate_frame==SLIDE)
|
||||
{
|
||||
osg::Vec3 pos(_slideWidth*position.x(),
|
||||
_slideDistance*position.y(),
|
||||
_slideHeight*position.z());
|
||||
|
||||
|
||||
osg::Vec3 pos = (_slideOrigin+osg::Vec3(_slideWidth*position.x(),0.0f,_slideHeight*position.y()))*(1.0f-position.z());
|
||||
|
||||
const osg::BoundingSphere& bs = model->getBound();
|
||||
float model_scale = scale*_slideHeight*0.7f/bs.radius();
|
||||
float model_scale = scale*_slideHeight*(1.0f-position.z())*0.7f/bs.radius();
|
||||
|
||||
osg::MatrixTransform* transform = new osg::MatrixTransform;
|
||||
transform->setDataVariance(osg::Object::STATIC);
|
||||
@@ -416,11 +416,14 @@ void SlideShowConstructor::addModel(const std::string& filename, CoordinateFrame
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::Matrix matrix(osg::Matrix::scale(1.0f/scale,1.0f/scale,1.0f/scale)*
|
||||
osg::Matrix::rotate(osg::DegreesToRadians(rotate[0]),rotate[1],rotate[2],rotate[3])*
|
||||
osg::Matrix::translate(position));
|
||||
|
||||
|
||||
osg::MatrixTransform* transform = new osg::MatrixTransform;
|
||||
transform->setDataVariance(osg::Object::STATIC);
|
||||
transform->setMatrix(osg::Matrix::translate(-position)*
|
||||
osg::Matrix::scale(scale,scale,scale)*
|
||||
osg::Matrix::rotate(osg::DegreesToRadians(rotate[0]),rotate[1],rotate[2],rotate[3]));
|
||||
transform->setMatrix(osg::Matrix::inverse(matrix));
|
||||
|
||||
transform->addChild(model);
|
||||
|
||||
@@ -586,6 +589,7 @@ void SlideShowConstructor::addModelWithCameraPath(const std::string& filename, C
|
||||
{
|
||||
osg::MatrixTransform* animation_transform = new osg::MatrixTransform;
|
||||
animation_transform->setDataVariance(osg::Object::DYNAMIC);
|
||||
animation_transform->setReferenceFrame(osg::Transform::RELATIVE_TO_ABSOLUTE);
|
||||
|
||||
osg::AnimationPathCallback* apc = new osg::AnimationPathCallback(animation);
|
||||
apc->setUseInverseMatrix(true);
|
||||
@@ -593,14 +597,16 @@ void SlideShowConstructor::addModelWithCameraPath(const std::string& filename, C
|
||||
animation_transform->setUpdateCallback(apc);
|
||||
animation_transform->addChild(transform);
|
||||
|
||||
osg::MatrixTransform* orientation_transform = new osg::MatrixTransform;
|
||||
orientation_transform->setDataVariance(osg::Object::STATIC);
|
||||
orientation_transform->addChild(animation_transform);
|
||||
|
||||
//orientation_transform->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(-00.0f),0.0f,1.0f,0.0f));
|
||||
orientation_transform->setMatrix(osg::Matrix::inverse(osg::Matrix::lookAt(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,1.0,0.0),osg::Vec3(0.0,0.0,1.0))));
|
||||
_currentLayer->addChild(animation_transform);
|
||||
|
||||
_currentLayer->addChild(orientation_transform);
|
||||
// osg::MatrixTransform* orientation_transform = new osg::MatrixTransform;
|
||||
// orientation_transform->setDataVariance(osg::Object::STATIC);
|
||||
// orientation_transform->addChild(animation_transform);
|
||||
//
|
||||
// //orientation_transform->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(-00.0f),0.0f,1.0f,0.0f));
|
||||
// orientation_transform->setMatrix(osg::Matrix::inverse(osg::Matrix::lookAt(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,1.0,0.0),osg::Vec3(0.0,0.0,1.0))));
|
||||
//
|
||||
// _currentLayer->addChild(orientation_transform);
|
||||
|
||||
}
|
||||
else
|
||||
|
||||
@@ -90,6 +90,7 @@ public:
|
||||
protected:
|
||||
|
||||
osg::Vec3 _slideOrigin;
|
||||
osg::Vec3 _eyeOrigin;
|
||||
float _slideWidth;
|
||||
float _slideHeight;
|
||||
float _slideDistance;
|
||||
|
||||
Reference in New Issue
Block a user