本文整理汇总了C++中MatrixTransform类的典型用法代码示例。如果您正苦于以下问题:C++ MatrixTransform类的具体用法?C++ MatrixTransform怎么用?C++ MatrixTransform使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MatrixTransform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GL3CalculateCubeShadowMapMatrix
void GL3CalculateCubeShadowMapMatrix(Vector3D light_position, Vector3D zdir,
Vector3D cube_s_vector, Vector3D cube_t_vector, float zmin, float zmax) {
MatrixTransform M;
M.Set(
cube_s_vector.x, cube_s_vector.y, cube_s_vector.z, 0.0f,
cube_t_vector.x, cube_t_vector.y, cube_t_vector.z, 0.0f,
- zdir.x, - zdir.y, - zdir.z, 0.0f);
MatrixTransform T;
T.AssignTranslation(- light_position);
// Calculate the projection matrix with a field of view of 90 degrees.
float aspect = 1.0;
float e = 1 / tanf((90.0f * M_PI / 180) / 2);
float n = zmin;
float f = zmax;
float l = - n / e;
float r = n / e;
float b = - (1.0f / aspect) * n / e;
float t = (1.0f / aspect) * n / e;
Matrix4D shadow_map_projection_matrix;
shadow_map_projection_matrix.Set(
2 * n / (r - l), 0.0f, (r + l) / (r - l), 0.0f,
0.0f, 2 * n / (t - b), (t + b) / (t - b), 0.0f,
0.0f, 0.0f, - (f + n) / (f - n), - 2 * n * f / (f - n),
0.0f, 0.0f, - 1.0f, 0.0f);
cube_shadow_map_matrix = shadow_map_projection_matrix * (M * T);
}
示例2: sreLookAt
void sreLookAt(float viewpx, float viewpy, float viewpz, float lookx, float looky, float lookz,
float upx, float upy, float upz) {
Vector3D F = Vector3D(lookx, looky, lookz) - Vector3D(viewpx, viewpy, viewpz);
Vector3D Up = Vector3D(upx, upy, upz);
Vector3D f = F.Normalize();
sre_internal_camera_vector = f;
Up.Normalize();
sre_internal_up_vector = Up;
Vector3D s = Cross(f, Up);
Vector3D u = Cross(s, f);
MatrixTransform M;
M.Set(
s.x, s.y, s.z, 0.0f,
u.x, u.y, u.z, 0.0f,
- f.x, - f.y, - f.z, 0.0f);
MatrixTransform T;
T.AssignTranslation(Vector3D(- viewpx, - viewpy, -viewpz));
sre_internal_view_matrix = M * T;
sre_internal_view_projection_matrix = sre_internal_projection_matrix * sre_internal_view_matrix;
// printf("View-projection matrix:\n");
// for (int row = 0; row < 4; row++)
// for (int column = 0; column < 4; column++)
// printf("%f, ", sre_internal_view_projection_matrix(row, column));
// printf("\n");
}
示例3: Vec3Array
Transform* PatchSet::createPatch(const std::string& filename, PatchOptions* poptions)
{
Patch* patch = new Patch;
patch->setPatchSet(this);
Vec2d ll, ur;
poptions->getPatchExtents(ll, ur);
Vec2d range = (ur - ll);
ref_ptr<Patch::Data> data = new Patch::Data;
int patchDim = _resolution + 1;
Vec3Array* verts = new Vec3Array(patchDim * patchDim);
for (int j = 0; j < patchDim; ++j)
for (int i = 0; i < patchDim; ++i)
(*verts)[patchDim * j + i]
= Vec3((ll.x() + i * range.x()
/ static_cast<float>(_resolution)) * 81920.0,
(ll.y() + j * range.y()
/ static_cast<float>(_resolution)) * 81920.0,
0.0);
data->vertexData.array = verts;
data->vertexData.binding = Geometry::BIND_PER_VERTEX;
Vec3Array* norms = new Vec3Array(1);
(*norms)[0] = Vec3d(0.0, 0.0, 1.0);
data->normalData.array = norms;
data->normalData.binding = Geometry::BIND_OVERALL;
Vec4Array* colors = new Vec4Array(1);
(*colors)[0] = Vec4(1.0, 1.0, 1.0, 1.0);
data->colorData.array = colors;
data->colorData.binding = Geometry::BIND_OVERALL;
patch->setData(data);
MatrixTransform* transform = new MatrixTransform;
transform->addChild(patch);
return transform;
}
示例4: MatrixTransform
ref_ptr<Group> VBSPEntity::createModelGeometry()
{
std::string modelFile;
ref_ptr<Node> modelNode;
ref_ptr<Group> entityGroup;
// Try to load the model
modelNode = osgDB::readRefNodeFile(entity_model);
if (modelNode.valid())
{
// Create a group and add the model to it
if (entity_transformed)
{
// Create a matrix transform
MatrixTransform * entityXform = new MatrixTransform();
// Set it up with the entity's transform information (scale
// the position from inches to meters)
Matrixf transMat, rotMat;
Quat roll, yaw, pitch;
transMat.makeTranslate(entity_origin * 0.0254);
pitch.makeRotate(osg::DegreesToRadians(entity_angles.x()),
Vec3f(0.0, 1.0, 0.0));
yaw.makeRotate(osg::DegreesToRadians(entity_angles.y()),
Vec3f(0.0, 0.0, 1.0));
roll.makeRotate(osg::DegreesToRadians(entity_angles.z()),
Vec3f(1.0, 0.0, 0.0));
rotMat.makeRotate(roll * pitch * yaw);
// Set the transform matrix
entityXform->setMatrix(rotMat * transMat);
// Use the transform node as the main entity group
entityGroup = entityXform;
}
else
{
// Create a group to represent the entire entity
entityGroup = new Group();
}
// Add the model node to the group
entityGroup->addChild(modelNode.get());
// Set the group's name
entityGroup->setName(class_name + std::string(":") + entity_model);
}
else
{
OSG_WARN << "Couldn't find prop \"" << entity_model << "\".";
OSG_WARN << std::endl;
// Leave the group empty (no model to show)
entityGroup = NULL;
}
return entityGroup;
}
示例5: ApplyMatrixTransform
void CollisionVisitor::ApplyMatrixTransform(MatrixTransform &m)
{
matrix4x4f matrix = matrix4x4f::Identity();
if (!m_matrixStack.empty()) matrix = m_matrixStack.back();
m_matrixStack.push_back(matrix * m.GetTransform());
m.Traverse(*this);
m_matrixStack.pop_back();
}
示例6: GL3CalculateShadowMapMatrix
void GL3CalculateShadowMapMatrix(Vector3D viewp, Vector3D light_direction, Vector3D x_direction,
Vector3D y_direction, Vector3D dim_min, Vector3D dim_max) {
MatrixTransform M;
// Note that the y direction has to be negated in order to preserve the handedness of
// triangles when rendering the shadow map.
#if 0
M.Set(
x_direction.x, y_direction.x, - light_direction.x, 0.0f,
x_direction.x, y_direction.y, - light_direction.y, 0.0f,
x_direction.z, y_direction.z, - light_direction.z, 0.0f);
#else
M.Set(
x_direction.x, x_direction.y, x_direction.z, 0.0f,
- y_direction.x, - y_direction.y, - y_direction.z, 0.0f,
- light_direction.x, - light_direction.y, - light_direction.z, 0.0f);
#endif
MatrixTransform T;
T.AssignTranslation(- viewp);
// Set orthographic projection matrix.
MatrixTransform orthographic_shadow_map_projection_matrix;
orthographic_shadow_map_projection_matrix.Set(
2.0f / (dim_max.x - dim_min.x), 0.0f, 0.0f, - (dim_max.x + dim_min.x) / (dim_max.x - dim_min.x),
0.0f, 2.0f / (dim_max.y - dim_min.y), 0.0f, - (dim_max.y + dim_min.y) / (dim_max.y - dim_min.y),
0.0f, 0.0f, - 2.0f / dim_max.z, - 1.0f);
shadow_map_matrix = orthographic_shadow_map_projection_matrix * (M * T);
// Calculate viewport matrix for lighting pass with shadow map.
MatrixTransform shadow_map_viewport_matrix;
shadow_map_viewport_matrix.Set(
0.5f, 0.0f, 0.0f, 0.5f,
0.0f, 0.5f, 0.0f, 0.5f,
0.0f, 0.0f, 0.5f, 0.5f);
shadow_map_lighting_pass_matrix = shadow_map_viewport_matrix * shadow_map_matrix;
#if 0
char *dim_max_str = dim_max.GetString();
sreMessage(SRE_MESSAGE_LOG, "dim_max = %s", dim_max_str);
delete [] dim_max_str;
Point3D P1 = viewp + light_direction * dim_max.z;
Point3D P2 = viewp;
Point3D P3 = viewp + x_direction * dim_max.x + y_direction * dim_max.y;
Vector4D P1_proj = shadow_map_matrix * P1;
Vector4D P2_proj = shadow_map_matrix * P2;
Vector4D P3_proj = shadow_map_matrix * P3;
Vector3D P1_norm = P1_proj.GetVector3D();
Vector3D P2_norm = P2_proj.GetVector3D();
Vector3D P3_norm = P3_proj.GetVector3D();
char *P1_norm_str = P1_norm.GetString();
char *P2_norm_str = P2_norm.GetString();
char *P3_norm_str = P3_norm.GetString();
sreMessage(SRE_MESSAGE_LOG, "CalculateShadowMapMatrix: Point transformations "
"%s, %s and %s.", P1_norm_str, P2_norm_str, P3_norm_str);
delete P1_norm_str;
delete P2_norm_str;
delete P3_norm_str;
#endif
}
示例7: updateCAVEGeodeShape
/***************************************************************
* Function: acceptCAVEGeodeShape()
*
* 'refShapeCenter' is reference center of 'CAVEGeodeShape', use
* this vector as reference center in design object space, which
* is associated with center of BoundingBox. Apply the offset of
* 'shapeCenter - refShapeCenter' on top level of scene graph and
* then rescale them in lower levels to fit into the scale of
* surface icon space.
*
***************************************************************/
void CAVEGroupEditGeodeWireframe::acceptCAVEGeodeShape(CAVEGeodeShape *shapeGeode, const osg::Vec3 &refShapeCenter)
{
mRefShapeCenter = refShapeCenter;
updateCAVEGeodeShape(shapeGeode);
/* create 'MOVE' operational wireframe geode[0] */
MatrixTransform *moveTrans = new MatrixTransform;
CAVEGeodeEditWireframeMove *moveGeode = new CAVEGeodeEditWireframeMove;
mMoveSwitch->addChild(moveTrans);
mMoveMatTransVector.push_back(moveTrans);
moveTrans->addChild(moveGeode);
moveTrans->setMatrix(mBoundBoxScaleMat * mAccRootMat);
/* create 'ROTATE' operational wireframe geode[0] */
MatrixTransform *rotateTrans = new MatrixTransform;
CAVEGeodeEditWireframeRotate *rotateGeode = new CAVEGeodeEditWireframeRotate;
mRotateSwitch->addChild(rotateTrans);
mRotateMatTransVector.push_back(rotateTrans);
rotateTrans->addChild(rotateGeode);
rotateTrans->setMatrix(mBoundSphereScaleMat * mAccRootMat);
/* create 'MANIPULATE' operational wireframe geode[0] */
MatrixTransform *manipulateTrans = new MatrixTransform;
CAVEGeodeEditWireframeManipulate *manipulateGeode = new CAVEGeodeEditWireframeManipulate;
mManipulateSwitch->addChild(manipulateTrans);
mManipulateMatTransVector.push_back(manipulateTrans);
manipulateTrans->addChild(manipulateGeode);
manipulateTrans->setMatrix(mBoundBoxScaleMat * mAccRootMat);
}
示例8: equals
bool MatrixTransform::equals(const MatrixTransform & other) const
{
if (this == &other) return true;
if (getImpl()->dir_ != other.getImpl()->dir_)
{
return false;
}
return *getImpl() == *(other.getImpl());
}
示例9: move
void EgoMovement::update(const int delta_time)
{
move(delta_time);
rotate();
MatrixTransform* transform = (MatrixTransform*)parent;
glm::mat4 parent_matrix = transform->getMatrix();
glm::mat4 delta_matrix = glm::translate(glm::mat4(), position)
* glm::rotate(glm::mat4(), rotation.y, glm::vec3(0, 1, 0))
* glm::rotate(glm::mat4(), rotation.x, glm::vec3(1, 0, 0));
transform->setMatrix(delta_matrix);
}
示例10: MatrixTransform
MatrixTransform* ChessUtils::loadOSGModel(string name, float modelSize, Material* material, bool overrideMaterial,
Vec3 modelCenterShift, double rotationAngle, Vec3 rotationAxis,
Vec3 modelCenterOffsetPercentage) {
// create a new node by reading in model from file
Node* modelNode = osgDB::readNodeFile(name);
if (modelNode != NULL) {
// apply material
if (material != NULL) {
if (overrideMaterial) {
modelNode->getOrCreateStateSet()->setAttributeAndModes(material, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
} else {
modelNode->getOrCreateStateSet()->setAttributeAndModes(material, osg::StateAttribute::ON);
}
}
//put model in origin
//osg::BoundingSphere bound = modelNode->getBound();
osg::ComputeBoundsVisitor cbVisitorOrigin;
modelNode->accept(cbVisitorOrigin);
osg::BoundingBox bound = cbVisitorOrigin.getBoundingBox();
double scaleRatio = modelSize / bound.radius();
MatrixTransform* unitTransform = new MatrixTransform();
unitTransform->postMult(Matrix::translate(-bound.center().x(), -bound.center().y(), -bound.center().z()));
unitTransform->postMult(Matrix::rotate(rotationAngle, rotationAxis));
unitTransform->postMult(Matrix::scale(scaleRatio, scaleRatio, scaleRatio));
unitTransform->addChild(modelNode);
// put model in specified location
osg::ComputeBoundsVisitor cbVisitor;
unitTransform->accept(cbVisitor);
osg::BoundingBox boundingBox = cbVisitor.getBoundingBox();
float modelXOffset = (boundingBox.xMax() - boundingBox.xMin()) * modelCenterOffsetPercentage.x();
float modelYOffset = (boundingBox.yMax() - boundingBox.yMin()) * modelCenterOffsetPercentage.y();
float modelZOffset = (boundingBox.zMax() - boundingBox.zMin()) * modelCenterOffsetPercentage.z();
unitTransform->postMult(Matrix::translate(modelXOffset, modelYOffset, modelZOffset));
MatrixTransform* modelPositionTransform = new MatrixTransform();
modelPositionTransform->postMult(Matrix::translate(modelCenterShift));
modelPositionTransform->addChild(unitTransform);
return modelPositionTransform;
}
return NULL;
}
示例11: BuildMatrixOps
void BuildMatrixOps(OpRcPtrVec & ops,
const Config& /*config*/,
const MatrixTransform & transform,
TransformDirection dir)
{
TransformDirection combinedDir = CombineTransformDirections(dir,
transform.getDirection());
float matrix[16];
float offset[4];
transform.getValue(matrix, offset);
CreateMatrixOffsetOp(ops,
matrix, offset,
combinedDir);
}
示例12: m_enabled
Shields::Shields(SceneGraph::Model *model)
: m_enabled(false)
{
assert(s_initialised);
using SceneGraph::Node;
using SceneGraph::MatrixTransform;
using SceneGraph::StaticGeometry;
using SceneGraph::CollisionGeometry;
//This will find all matrix transforms meant for shields.
SceneGraph::FindNodeVisitor shieldFinder(SceneGraph::FindNodeVisitor::MATCH_NAME_ENDSWITH, s_matrixTransformName);
model->GetRoot()->Accept(shieldFinder);
const std::vector<Node*> &results = shieldFinder.GetResults();
//Store pointer to the shields for later.
for (unsigned int i=0; i < results.size(); i++) {
MatrixTransform *mt = dynamic_cast<MatrixTransform*>(results.at(i));
assert(mt);
for(Uint32 iChild=0 ; iChild<mt->GetNumChildren() ; ++iChild) {
Node* node = mt->GetChildAt(iChild);
if (node)
{
RefCountedPtr<StaticGeometry> sg(dynamic_cast<StaticGeometry*>(node));
assert(sg.Valid());
sg->SetNodeMask(SceneGraph::NODE_TRANSPARENT);
Graphics::RenderStateDesc rsd;
rsd.blendMode = Graphics::BLEND_ALPHA;
rsd.depthWrite = false;
sg->SetRenderState(sg->GetRenderer()->CreateRenderState(rsd));
// set the material
for (Uint32 iMesh = 0; iMesh < sg->GetNumMeshes(); ++iMesh) {
StaticGeometry::Mesh &rMesh = sg->GetMeshAt(iMesh);
rMesh.material = GetGlobalShieldMaterial();
}
m_shields.push_back(Shield(Color3ub(255), mt->GetTransform(), sg.Get()));
}
}
}
}
示例13: apply
virtual void apply(MatrixTransform& mt)
{
Matrix matrix;
if (_useInverseMatrix)
_cp.getInverse(matrix);
else
_cp.getMatrix(matrix);
mt.setMatrix(osg::Matrix::translate(-_pivotPoint)*matrix);
}
示例14: fprintf
//
// INIT
//
bool MathematicPlugin::init()
{
if (plugin)
return false;
if (cover->debugLevel(3))
fprintf(stderr, "\nMathematicPlugin::MathematicPlugin\n");
// set plugin
MathematicPlugin::plugin = this;
// rotate scene so that x axis is in front
MatrixTransform *trafo = VRSceneGraph::instance()->getTransform();
Matrix m;
m.makeRotate(inDegrees(-90.0), 0.0, 0.0, 1.0);
trafo->setMatrix(m);
// bounding box
boundary_ = (double)coCoviseConfig::getFloat("max", "COVER.Plugin.Mathematic.Boundary", boundary_);
boundingBox_ = new BoundingBox(-boundary_, -boundary_, -boundary_,
boundary_, boundary_, boundary_);
coVRPoint::setBoundingBox(boundingBox_);
coVRLine::setBoundingBox(boundingBox_);
coVRPlane::setBoundingBox(boundingBox_);
coVRDirection::setBoundingBox(boundingBox_);
coVRDistance::setBoundingBox(boundingBox_);
drawBoundingBox(boundingBox_);
// mathematics menu
makeMathematicsMenu();
// make the menus state label, it shows which objects intersects, etc
stateLabel_ = new coLabelMenuItem(" ");
mathematicsMenu_->insert(stateLabel_, mainMenuSepPos_ - 1);
// colored axis
axis_ = new coVRCoordinateAxis(0.07, boundary_, true);
// zoom scene
VRSceneGraph::instance()->viewAll();
return true;
}
示例15: loadModel
MatrixTransform* loadModel(std::string name, float scale, float rotX, float rotY, float rotZ, osg::Vec3 translate)
{
__FUNCTION_HEADER__
Node* n = NULL;
//did we already load (or try to load) this one?
std::map<std::string, osg::ref_ptr<osg::Node> >::iterator i;
bool haz = false;
for(i = gLoadedModels.begin(); i != gLoadedModels.end(); i++)
{
if(i->first == name)
{
haz = true;
// printf("We already have %s\n", name.c_str());
n = i->second;
}
}
if(!haz) //if we didn't try to laod it before, do so now
{
n = osgDB::readNodeFile(findDataFile(name));
gLoadedModels[name] = n;
if(!n)
logError("Unable to load model %s\n", name.c_str());
else printf("Loaded %s\n", name.c_str());
}
if(!n) return NULL;
MatrixTransform* m = new MatrixTransform();
m->setName(name);
m->addChild(n);
Matrix mat = Matrix::scale(scale, scale, scale);
mat = mat * Matrix::rotate(rotX / 57.296, Vec3(1, 0, 0));
mat = mat * Matrix::rotate(rotY / 57.296, Vec3(0, 1, 0));
mat = mat * Matrix::rotate(rotZ / 57.296, Vec3(0, 0, 1));
mat = mat * Matrix::translate(translate);
m->setMatrix(mat);
return m;
}