本文整理汇总了C++中MatrixTransform::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixTransform::addChild方法的具体用法?C++ MatrixTransform::addChild怎么用?C++ MatrixTransform::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatrixTransform
的用法示例。
在下文中一共展示了MatrixTransform::addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: acceptCAVEGeodeShape
/***************************************************************
* 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);
}
示例2: Widget
TextureWidget::TextureWidget(Interaction* interaction, float width, float height) : Widget(), Events()
{
StateSet* stateSet;
_interaction = interaction;
_width = width;
_height = height;
createBackground();
createTexturesGeometry();
initLabels();
initTextures();
_texture[0] = new Geode();
_texture[0]->addDrawable(_geom);
_texture[0]->addDrawable(_label0);
_texture[0]->addDrawable(_texGeom0);
stateSet = _texGeom0->getOrCreateStateSet();
stateSet->setMode(GL_LIGHTING, StateAttribute::OFF);
stateSet->setRenderingHint(StateSet::TRANSPARENT_BIN);
stateSet->setTextureAttributeAndModes(StateAttribute::TEXTURE, _tex0, StateAttribute::ON);
_texture[1] = new Geode();
_texture[1]->addDrawable(_geom);
_texture[1]->addDrawable(_label1);
_texture[1]->addDrawable(_texGeom1);
stateSet = _texGeom1->getOrCreateStateSet();
stateSet->setMode(GL_LIGHTING, StateAttribute::OFF);
stateSet->setRenderingHint(StateSet::TRANSPARENT_BIN);
stateSet->setTextureAttributeAndModes(StateAttribute::TEXTURE, _tex1, StateAttribute::ON);
_swTexture = new Switch();
_swTexture->addChild(_texture[0]);
_swTexture->addChild(_texture[1]);
_swTexture->setSingleChildOn(0);
_node->addChild(_swTexture.get());
_leftGeode = new Geode();
_rightGeode = new Geode();
MatrixTransform* transLeft = new MatrixTransform();
MatrixTransform* transRight = new MatrixTransform();
Matrix trans;
trans.makeTranslate(Vec3(-_width/2.0, -_height/2.0 - DEFAULT_LABEL_HEIGHT/2.0, 3*EPSILON_Z));
transLeft->setMatrix(trans);
transLeft->addChild(_leftGeode);
trans.makeTranslate(Vec3(+_width/2.0, -_height/2.0 - DEFAULT_LABEL_HEIGHT/2.0, 3*EPSILON_Z));
transRight->setMatrix(trans);
transRight->addChild(_rightGeode);
_node->addChild(transLeft);
_node->addChild(transRight);
_interaction->addListener(this, this);
}
示例3: loadOSGModel
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;
}
示例4: createPatch
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;
}
示例5: 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;
}
示例6: generate
int Tree::generate(MatrixTransform *curr, int start, int level){
//Node *curr = root;
printf("before: %d\n", start);
int index_jump;
i=start;
while(i < result.size()){
printf("level is: %d\n", level);
if(result[i] == '['){
MatrixTransform *tmp = new MatrixTransform();
//tmp->M = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f, 0.5f, 0.5f));
curr->addChild(tmp);
generate(tmp, i+1, level+1);
i++;
//i += index_jump;
}
else if(result[i] == ']'){
i++;
return i-start+1;
}
else if(result[i] == 'F'){
MatrixTransform *tmp = new MatrixTransform();
tmp->M = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 1.0f, 0.0f))*tmp->M;
curr->addChild(tmp);
Geode *child = new Geode(obj);
tmp->addChild(child);
index_jump = generate(tmp, i+1, level+1);
i++;
//i += index_jump;
}
else if(result[i] == '+'){
i++;
curr->M = glm::rotate(glm::mat4(1.0f), 20.0f/180.0f*glm::pi<float>(), glm::vec3(0.0f, 0.0f, 1.0f))*curr->M;
}
else if(result[i] == '-'){
i++;
curr->M = glm::rotate(glm::mat4(1.0f), -20.0f/180.0f*glm::pi<float>(), glm::vec3(0.0f, 0.0f, 1.0f))*curr->M;
}
}
printf("after: %d\n", i);
return 0;
}
示例7: MatrixTransform
Boat::Boat()
{
mT = 0;
mTV = 0.1;
MatrixTransform* modelTransform = new MatrixTransform();
mPat->addChild(modelTransform);
//load a boat model
MatrixTransform* n = Util::loadModel("jetski.3DS", 1.0/12 / 4, -90);
if(n)
{
// Util::setTint(n, Vec4(1, 0, 0, 1));
//the texture doesn't apply automatically for some reason, so let's do it manually
Image* image = osgDB::readImageFile(Util::findDataFile("jetski.jpg"));
Texture2D* tex = new Texture2D(image);
n->getOrCreateStateSet()->setTextureAttributeAndModes(0, tex);
}
modelTransform->addChild(n);
}
示例8: applyScaling
/***************************************************************
* Function: applyScaling()
*
* 'gridUnitScaleVect' is guranteed to be non-negative vector
*
***************************************************************/
void CAVEGroupEditGeodeWireframe::applyScaling( const short &nOffsetSegs, const Vec3 &gridUnitScaleVect,
const std::string &gridUnitScaleInfo)
{
mManipulateSwitch->setAllChildrenOn();
/* scale to other direction: clear all children of 'mManipulateSwitch' except child[0], rebuild offset tree */
if (mScaleNumSegs * nOffsetSegs <= 0)
{
unsigned int numChildren = mManipulateSwitch->getNumChildren();
if (numChildren > 1)
{
mManipulateSwitch->removeChildren(1, numChildren - 1);
MatrixTransVector::iterator itrMatTrans = mManipulateMatTransVector.begin();
mManipulateMatTransVector.erase(itrMatTrans + 1, itrMatTrans + numChildren);
}
mScaleNumSegs = 0;
}
/* decide unit offset vector and start/end index of children under 'mManipulateSwitch' */
short idxStart = 0, idxEnd = 0;
if (nOffsetSegs != 0)
{
idxStart = mScaleNumSegs;
idxEnd = nOffsetSegs;
}
idxStart = idxStart > 0 ? idxStart: -idxStart;
idxEnd = idxEnd > 0 ? idxEnd : -idxEnd;
/* update the first wireframe with global translation and rotation */
if (idxStart == 0) mManipulateMatTransVector[0]->setMatrix(mBoundBoxScaleMat * mAccRootMat);
/* create or remove a sequence of extra children under 'mMoveSwitch' */
if (idxStart < idxEnd)
{
for (short i = idxStart + 1; i <= idxEnd; i++)
{
/* generate scaling vector with non-negative values */
Vec3 scaleVect = Vec3(1, 1, 1);
if (nOffsetSegs > 0) scaleVect += gridUnitScaleVect * i;
else scaleVect -= gridUnitScaleVect * i;
scaleVect.x() = scaleVect.x() > 0 ? scaleVect.x() : 0;
scaleVect.y() = scaleVect.y() > 0 ? scaleVect.y() : 0;
scaleVect.z() = scaleVect.z() > 0 ? scaleVect.z() : 0;
Matrixd scaleMat;
scaleMat.makeScale(scaleVect);
MatrixTransform *scaleTrans = new MatrixTransform;
CAVEGeodeEditWireframeManipulate *manipulateGeode = new CAVEGeodeEditWireframeManipulate;
mManipulateSwitch->addChild(scaleTrans);
mManipulateMatTransVector.push_back(scaleTrans);
scaleTrans->addChild(manipulateGeode);
scaleTrans->setMatrix(mBoundBoxScaleMat * mAccRootMat * scaleMat);
}
}
else if (idxStart > idxEnd)
{
mManipulateSwitch->removeChildren(idxEnd + 1, idxStart - idxEnd);
MatrixTransVector::iterator itrMatTrans = mManipulateMatTransVector.begin();
itrMatTrans += idxEnd + 1;
mManipulateMatTransVector.erase(itrMatTrans, itrMatTrans + (idxStart - idxEnd));
}
mScaleNumSegs = nOffsetSegs;
mScaleUnitVect = gridUnitScaleVect;
if (!mPrimaryFlag) return;
/* update info text if 'this' wireframe is primary */
mEditInfoTextSwitch->setAllChildrenOn();
float scaleUnit = gridUnitScaleVect.x() > 0 ? gridUnitScaleVect.x() : gridUnitScaleVect.y();
scaleUnit = scaleUnit > 0 ? scaleUnit : gridUnitScaleVect.z();
char info[128];
float scaleval = scaleUnit * nOffsetSegs + 1.0f;
scaleval = scaleval > 0 ? scaleval:0;
sprintf(info, "Scale = %3.2f \nSnapping = ", scaleval);
mEditInfoText->setText(info + gridUnitScaleInfo);
}
示例9: applyRotation
/***************************************************************
* Function: applyRotation()
*
* 'axisSVect': rotational snapping values around each axis,
* for instance, Vec3(2, 0, 0) means rotation around X-axis by
* two times of 'gridUnitAngle'
* only one component of 'axisIntVect' is supposed to be non-zero
*
***************************************************************/
void CAVEGroupEditGeodeWireframe::applyRotation(const osg::Vec3s &axisSVect, const float &gridUnitAngle,
const string &gridUnitAngleInfo)
{
if (!mPrimaryFlag) return;
mRotateSwitch->setAllChildrenOn();
/* rotate in other direction: clear all children of 'mRotateSwitch' except child[0], rebuild offset tree */
if ((mRotateSVect.x() * axisSVect.x() + mRotateSVect.y() * axisSVect.y() + mRotateSVect.z() * axisSVect.z()) <= 0)
{
unsigned int numChildren = mRotateSwitch->getNumChildren();
if (numChildren > 1)
{
mRotateSwitch->removeChildren(1, numChildren - 1);
MatrixTransVector::iterator itrMatTrans = mRotateMatTransVector.begin();
mRotateMatTransVector.erase(itrMatTrans + 1, itrMatTrans + numChildren);
}
mRotateSVect = Vec3s(0, 0, 0);
}
/* decide unit rotation quat and start/end index of children under 'mRotateSwitch' */
Vec3 gridRotationAxis;
short idxStart = 0, idxEnd = 0;
if (axisSVect.x() != 0)
{
idxStart = mRotateSVect.x();
idxEnd = axisSVect.x();
if (axisSVect.x() > 0) gridRotationAxis = Vec3(1, 0, 0);
else gridRotationAxis = Vec3(-1, 0, 0);
}
else if (axisSVect.y() != 0)
{
idxStart = mRotateSVect.y();
idxEnd = axisSVect.y();
if (axisSVect.y() > 0) gridRotationAxis = Vec3(0, 1, 0);
else gridRotationAxis = Vec3(0, -1, 0);
}
else if (axisSVect.z() != 0)
{
idxStart = mRotateSVect.z();
idxEnd = axisSVect.z();
if (axisSVect.z() > 0) gridRotationAxis = Vec3(0, 0, 1);
else gridRotationAxis = Vec3(0, 0, -1);
}
idxStart = idxStart > 0 ? idxStart: -idxStart;
idxEnd = idxEnd > 0 ? idxEnd : -idxEnd;
/* create or remove a sequence of extra children under 'mRotateSwitch' */
if (idxStart < idxEnd)
{
for (short i = idxStart + 1; i <= idxEnd; i++)
{
Matrixd rotMat;
rotMat.makeRotate(gridUnitAngle * i, gridRotationAxis);
MatrixTransform *rotateTrans = new MatrixTransform;
CAVEGeodeEditWireframeRotate *rotateGeode = new CAVEGeodeEditWireframeRotate;
mRotateSwitch->addChild(rotateTrans);
mRotateMatTransVector.push_back(rotateTrans);
rotateTrans->addChild(rotateGeode);
rotateTrans->setMatrix(mBoundSphereScaleMat * rotMat);
}
}
else if (idxStart > idxEnd)
{
mRotateSwitch->removeChildren(idxEnd + 1, idxStart - idxEnd);
MatrixTransVector::iterator itrMatTrans = mRotateMatTransVector.begin();
itrMatTrans += idxEnd + 1;
mRotateMatTransVector.erase(itrMatTrans, itrMatTrans + (idxStart - idxEnd));
}
mRotateSVect = axisSVect;
/* update info text if 'this' wireframe is primary */
mEditInfoTextSwitch->setAllChildrenOn();
char info[128];
const float gridUnitAngleDegree = gridUnitAngle * 180 / M_PI;
sprintf(info, "Angle = %3.2f\nSnapping = ", gridUnitAngleDegree * idxEnd);
mEditInfoText->setText(info + gridUnitAngleInfo);
}
示例10: applyTranslation
/***************************************************************
* Function: applyTranslation()
*
* 'gridSVect': number of snapping segments along each direction
* 'gridUnitLegnth': actual length represented by each segment,
* only one component of 'gridSVect' is supposed to be non-zero
*
***************************************************************/
void CAVEGroupEditGeodeWireframe::applyTranslation(const osg::Vec3s &gridSVect, const float &gridUnitLegnth,
const string &gridUnitLegnthInfo)
{
mMoveSwitch->setAllChildrenOn();
/* move to other direction: clear all children of 'mMoveSwitch' except child[0], rebuild offset tree */
if ((mMoveSVect.x() * gridSVect.x() + mMoveSVect.y() * gridSVect.y() + mMoveSVect.z() * gridSVect.z()) <= 0)
{
unsigned int numChildren = mMoveSwitch->getNumChildren();
if (numChildren > 1)
{
mMoveSwitch->removeChildren(1, numChildren - 1);
MatrixTransVector::iterator itrMatTrans = mMoveMatTransVector.begin();
mMoveMatTransVector.erase(itrMatTrans + 1, itrMatTrans + numChildren);
}
mMoveSVect = Vec3s(0, 0, 0);
}
/* decide unit offset vector and start/end index of children under 'mMoveSwitch' */
Vec3 gridOffsetVect;
short idxStart = 0, idxEnd = 0;
if (gridSVect.x() != 0)
{
idxStart = mMoveSVect.x();
idxEnd = gridSVect.x();
if (gridSVect.x() > 0) gridOffsetVect = Vec3(gridUnitLegnth, 0, 0);
else gridOffsetVect = Vec3(-gridUnitLegnth, 0, 0);
}
else if (gridSVect.y() != 0)
{
idxStart = mMoveSVect.y();
idxEnd = gridSVect.y();
if (gridSVect.y() > 0) gridOffsetVect = Vec3(0, gridUnitLegnth, 0);
else gridOffsetVect = Vec3(0, -gridUnitLegnth, 0);
}
else if (gridSVect.z() != 0)
{
idxStart = mMoveSVect.z();
idxEnd = gridSVect.z();
if (gridSVect.z() > 0) gridOffsetVect = Vec3(0, 0, gridUnitLegnth);
else gridOffsetVect = Vec3(0, 0, -gridUnitLegnth);
}
idxStart = idxStart > 0 ? idxStart: -idxStart;
idxEnd = idxEnd > 0 ? idxEnd : -idxEnd;
/* update the first wireframe with global translation and rotation */
if (idxStart == 0) mMoveMatTransVector[0]->setMatrix(mBoundBoxScaleMat * mAccRootMat);
/* create or remove a sequence of extra children under 'mMoveSwitch' */
if (idxStart < idxEnd)
{
for (short i = idxStart + 1; i <= idxEnd; i++)
{
Matrixd transMat;
transMat.makeTranslate(gridOffsetVect * i);
MatrixTransform *moveTrans = new MatrixTransform;
CAVEGeodeEditWireframeMove *moveGeode = new CAVEGeodeEditWireframeMove;
mMoveSwitch->addChild(moveTrans);
mMoveMatTransVector.push_back(moveTrans);
moveTrans->addChild(moveGeode);
moveTrans->setMatrix(mBoundBoxScaleMat * mAccRootMat * transMat);
}
}
else if (idxStart > idxEnd)
{
mMoveSwitch->removeChildren(idxEnd + 1, idxStart - idxEnd);
MatrixTransVector::iterator itrMatTrans = mMoveMatTransVector.begin();
itrMatTrans += idxEnd + 1;
mMoveMatTransVector.erase(itrMatTrans, itrMatTrans + (idxStart - idxEnd));
}
mMoveSVect = gridSVect;
if (!mPrimaryFlag) return;
/* update info text if 'this' wireframe is primary */
mEditInfoTextSwitch->setAllChildrenOn();
char info[128];
sprintf(info, "Offset = %3.2f m\nSnapping = ", gridUnitLegnth * idxEnd);
mEditInfoText->setText(info + gridUnitLegnthInfo);
}
示例11: loadCharacter
void Window::loadCharacter() {
Matrix4 temp;
Matrix4 id;
id.identity();
//Setting up Controller
temp.makeTranslate(0, 0, 10);
control = MatrixTransform(temp);
//Setting up Head
headCube = Cube(2);
headCube.setTexture(head);
headRotation = MatrixTransform(id);
headScaling = MatrixTransform(id);
temp.makeTranslate(0, 7, 0);
headTranslation = MatrixTransform(temp);
headRotation.addChild(&headCube);
headScaling.addChild(&headRotation);
headTranslation.addChild(&headScaling);
control.addChild(&headTranslation);
//Setting up body
bodyCube = Cube(1);
bodyCube.setTexture(body);
bodyRotation = MatrixTransform(id);
temp.makeScale(2, 3, 1);
bodyScaling = MatrixTransform(temp);
temp.makeTranslate(0, 4.5, 0);
bodyTranslation = MatrixTransform(temp);
bodyRotation.addChild(&bodyCube);
bodyScaling.addChild(&bodyRotation);
bodyTranslation.addChild(&bodyScaling);
control.addChild(&bodyTranslation);
//Setting up Arms
armCube = Cube(1);
armCube.setTexture(arm);
leftArmRotation = MatrixTransform(id);
rightArmRotation = MatrixTransform(id);
temp.makeScale(1, 3, 1);
leftArmScaling = MatrixTransform(temp);
rightArmScaling = MatrixTransform(temp);
temp.makeTranslate(1.5, 4.5, 0);
leftArmTranslation = MatrixTransform(temp);
temp.makeTranslate(-(1.5), 4.5, 0);
rightArmTranslation = MatrixTransform(temp);
leftArmScaling.addChild(&armCube);
rightArmScaling.addChild(&armCube);
leftArmRotation.addChild(&leftArmScaling);
rightArmRotation.addChild(&rightArmScaling);
leftArmTranslation.addChild(&leftArmRotation);
rightArmTranslation.addChild(&rightArmRotation);
control.addChild(&leftArmTranslation);
control.addChild(&rightArmTranslation);
//Setting up Legs
legCube = Cube(1);
legCube.setTexture(leg);
leftLegRotation = MatrixTransform(id);
rightLegRotation = MatrixTransform(id);
temp.makeScale(1, 3, 1);
leftLegScaling = MatrixTransform(temp);
rightLegScaling = MatrixTransform(temp);
temp.makeTranslate(.5, 1.5, 0);
leftLegTranslation = MatrixTransform(temp);
temp.makeTranslate(-.5, 1.5, 0);
rightLegTranslation = MatrixTransform(temp);
leftLegScaling.addChild(&legCube);
rightLegScaling.addChild(&legCube);
leftLegRotation.addChild(&leftLegScaling);
rightLegRotation.addChild(&rightLegScaling);
leftLegTranslation.addChild(&leftLegRotation);
rightLegTranslation.addChild(&rightLegRotation);
control.addChild(&leftLegTranslation);
control.addChild(&rightLegTranslation);
character.addChild(&control);
}
示例12: ANIMLoadSketchBook
/***************************************************************
* Function: ANIMLoadSketchBook()
***************************************************************/
void ANIMLoadSketchBook(PositionAttitudeTransform** xformScaleFwd, PositionAttitudeTransform** xformScaleBwd,
int &numPages, ANIMPageEntry ***pageEntryArray)
{
*xformScaleFwd = new PositionAttitudeTransform;
*xformScaleBwd = new PositionAttitudeTransform;
MatrixTransform *sketchbookTrans = new MatrixTransform;
Matrixf transMat, scaleMat;
transMat.makeTranslate(Vec3(0, 0, ANIM_VIRTUAL_SPHERE_RADIUS));
scaleMat.makeScale(Vec3(ANIM_PARA_PAINT_FRAME_ZOOM_FACTOR,
ANIM_PARA_PAINT_FRAME_ZOOM_FACTOR,
ANIM_PARA_PAINT_FRAME_ZOOM_FACTOR));
sketchbookTrans->setMatrix(transMat * scaleMat);
(*xformScaleFwd)->addChild(sketchbookTrans);
(*xformScaleBwd)->addChild(sketchbookTrans);
// load sketch book node from VRML file, create page geodes
Node* sketchbookNode = osgDB::readNodeFile(ANIMDataDir() + "VRMLFiles/SketchBook.WRL");
sketchbookTrans->addChild(sketchbookNode);
// Load floorplan filenames from config file
bool isFile = true;
int j = 0, numTex;
std::string file = "", dir, path;
std::vector<std::string> filenames;
dir = cvr::ConfigManager::getEntry("dir", "Plugin.CaveCADBeta.Floorplans", "/home/cehughes");
dir = dir + "/";
path = "Plugin.CaveCADBeta.Floorplans.0";
file = cvr::ConfigManager::getEntry(path, "", &isFile);
while (isFile)
{
filenames.push_back(dir + file);
j++;
char buf[50];
sprintf(buf, "Plugin.CaveCADBeta.Floorplans.%d", j);
std::string path = std::string(buf);
file = cvr::ConfigManager::getEntry(path, "", &isFile);
}
numPages = j;
//numPages = 3;
// create tree structured page entry array
*pageEntryArray = new ANIMPageEntry*[numPages];
for (int i = 0; i < numPages; i++)
{
/* char idxStr[16];
if (i < 10)
{
sprintf(idxStr, "0%d", i);
}
else if (i < 100)
{
sprintf(idxStr, "%d", i);
}*/
string filename = filenames[i];//ANIMDataDir() + "Textures/Floorplans/Floorplan" + string(idxStr) + string(".JPG");
(*pageEntryArray)[i] = new ANIMPageEntry;
Switch *singlePageSwitch = new Switch;
PositionAttitudeTransform *flipUpTrans = new PositionAttitudeTransform;
PositionAttitudeTransform *flipDownTrans = new PositionAttitudeTransform;
sketchbookTrans->addChild(singlePageSwitch);
singlePageSwitch->addChild(flipUpTrans);
singlePageSwitch->addChild(flipDownTrans);
singlePageSwitch->setAllChildrenOff();
// set up flip up / flip down animation paths for each page
Geode *flipUpGeode, *flipDownGeode;
AnimationPathCallback *flipUpCallback, *flipDownCallback;
ANIMCreateSinglePageGeodeAnimation(filename, &flipUpGeode, &flipDownGeode, &flipUpCallback, &flipDownCallback);
flipUpTrans->addChild(flipUpGeode);
flipUpTrans->setUpdateCallback(flipUpCallback);
flipDownTrans->addChild(flipDownGeode);
flipDownTrans->setUpdateCallback(flipDownCallback);
// write into page entry array record
(*pageEntryArray)[i]->mSwitch = singlePageSwitch;
(*pageEntryArray)[i]->mFlipUpAnim = flipUpCallback;
(*pageEntryArray)[i]->mFlipDownAnim = flipDownCallback;
(*pageEntryArray)[i]->mPageGeode = flipDownGeode;
(*pageEntryArray)[i]->mTexFilename = filename;
}
(*pageEntryArray)[0]->mSwitch->setSingleChildOn(1);
(*pageEntryArray)[1]->mSwitch->setSingleChildOn(0);
// size of floorplan
//.........这里部分代码省略.........
示例13: Sphere
/***************************************************************
* Function: ANIMCreateRefSkyDome()
*
***************************************************************/
MatrixTransform *ANIMCreateRefSkyDome(StateSet **stateset)
{
/* sky dome geometry */
Sphere *skyShape = new Sphere();
ShapeDrawable* skyDrawable = new ShapeDrawable(skyShape);
Geode* skyGeode = new Geode();
MatrixTransform *skyDomeTrans = new MatrixTransform;
//osg::Matrix m;
//m.makeRotate(osg::Quat(M_PI/2, osg::Vec3(0, 1, 0)));
//skyDomeTrans->setMatrix(m);
skyShape->setRadius(ANIM_SKYDOME_RADIUS);
skyGeode->addDrawable(skyDrawable);
skyDomeTrans->addChild(skyGeode);
// apply simple colored materials
Material* material = new Material;
material->setDiffuse(Material::FRONT_AND_BACK, Vec4(1.0f, 1.0f, 1.0f, 1.0f));
material->setAlpha(Material::FRONT_AND_BACK, 1.0f);
(*stateset) = new StateSet();
(*stateset)->setAttributeAndModes(material, StateAttribute::OVERRIDE | StateAttribute::ON);
(*stateset)->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON );
(*stateset)->setRenderingHint(StateSet::TRANSPARENT_BIN);
skyGeode->setStateSet(*stateset);
// skyGeode->setNodeMask(0xFFFFFF & ~(0x2 | 0x3));
// load sky dome shader
Uniform* sunrUniform = new Uniform("hazeRadisuMin", 0.975f);
(*stateset)->addUniform(sunrUniform);
Uniform* sunRUniform = new Uniform("hazeRadisuMax", 0.995f);
(*stateset)->addUniform(sunRUniform);
Uniform* sunDirUniform = new Uniform("sundir", Vec4(0.0, 0.0, 1.0, 1.0));
(*stateset)->addUniform(sunDirUniform);
Uniform* suncolorUniform = new Uniform("suncolor", Vec4(1.0, 1.0, 1.0, 1.0));
(*stateset)->addUniform(suncolorUniform);
Uniform* skycolorUniform = new Uniform("skycolor", Vec4(0.5, 0.5, 1.0, 1.0));
(*stateset)->addUniform(skycolorUniform);
Uniform* skyfadingcolorUniform = new Uniform("skyfadingcolor", Vec4(0.8, 0.8, 0.8, 1.0));
(*stateset)->addUniform(skyfadingcolorUniform);
Uniform* skymaskingcolorUniform = new Uniform("skymaskingcolor", Vec4(1.0, 1.0, 1.0, 1.0));
(*stateset)->addUniform(skymaskingcolorUniform);
Uniform *matShaderToWorldUniform = new Uniform("shaderToWorldMat", Matrixd());
(*stateset)->addUniform(matShaderToWorldUniform);
Image* imageSky = osgDB::readImageFile(ANIMDataDir() + "Textures/NightSky.JPG");
Texture2D* textureSky = new Texture2D(imageSky);
(*stateset)->setTextureAttributeAndModes(0, textureSky, StateAttribute::ON);
Image* imagePara = osgDB::readImageFile(ANIMDataDir() + "Textures/Paramounts/Paramount00.JPG");
Texture2D* texturePara = new Texture2D(imagePara);
(*stateset)->setTextureAttributeAndModes(1, texturePara, StateAttribute::ON);
Uniform* skyNightSampler = new Uniform("texNightSky", 0);
(*stateset)->addUniform(skyNightSampler);
Uniform* paraImageTextureSampler = new Uniform("texParamount", 1);
(*stateset)->addUniform(paraImageTextureSampler);
Program* programSky = new Program;
(*stateset)->setAttribute(programSky);
programSky->addShader(Shader::readShaderFile(Shader::VERTEX, ANIMDataDir() + "Shaders/EnvSky.vert"));
programSky->addShader(Shader::readShaderFile(Shader::FRAGMENT, ANIMDataDir() + "Shaders/EnvSky.frag"));
return skyDomeTrans;
}
示例14: ANIMLoadSketchBook
/***************************************************************
* Function: ANIMLoadSketchBook()
***************************************************************/
void ANIMLoadSketchBook(PositionAttitudeTransform** xformScaleFwd, PositionAttitudeTransform** xformScaleBwd,
int &numPages, ANIMPageEntry ***pageEntryArray)
{
*xformScaleFwd = new PositionAttitudeTransform;
*xformScaleBwd = new PositionAttitudeTransform;
MatrixTransform *sketchbookTrans = new MatrixTransform;
Matrixf transMat, scaleMat;
transMat.makeTranslate(Vec3(0, 0, ANIM_VIRTUAL_SPHERE_RADIUS));
scaleMat.makeScale(Vec3(ANIM_PARA_PAINT_FRAME_ZOOM_FACTOR,
ANIM_PARA_PAINT_FRAME_ZOOM_FACTOR,
ANIM_PARA_PAINT_FRAME_ZOOM_FACTOR));
sketchbookTrans->setMatrix(transMat * scaleMat);
(*xformScaleFwd)->addChild(sketchbookTrans);
(*xformScaleBwd)->addChild(sketchbookTrans);
/* load sketch book node from VRML file, create page geodes */
Node* sketchbookNode = osgDB::readNodeFile(ANIMDataDir() + "VRMLFiles/SketchBook.WRL");
sketchbookTrans->addChild(sketchbookNode);
/* create tree structured page entry array */
numPages = 3;
*pageEntryArray = new ANIMPageEntry*[numPages];
for (int i = 0; i < numPages; i++)
{
char idxStr[16];
if (i < 10) sprintf(idxStr, "0%d", i);
else if (i < 100) sprintf(idxStr, "%d", i);
string filename = ANIMDataDir() + "Textures/Floorplans/Floorplan" + string(idxStr) + string(".JPG");
(*pageEntryArray)[i] = new ANIMPageEntry;
Switch *singlePageSwitch = new Switch;
PositionAttitudeTransform *flipUpTrans = new PositionAttitudeTransform;
PositionAttitudeTransform *flipDownTrans = new PositionAttitudeTransform;
sketchbookTrans->addChild(singlePageSwitch);
singlePageSwitch->addChild(flipUpTrans);
singlePageSwitch->addChild(flipDownTrans);
singlePageSwitch->setAllChildrenOff();
/* set up flip up / flip down animation paths for each page */
Geode *flipUpGeode, *flipDownGeode;
AnimationPathCallback *flipUpCallback, *flipDownCallback;
ANIMCreateSinglePageGeodeAnimation(filename, &flipUpGeode, &flipDownGeode, &flipUpCallback, &flipDownCallback);
flipUpTrans->addChild(flipUpGeode);
flipUpTrans->setUpdateCallback(flipUpCallback);
flipDownTrans->addChild(flipDownGeode);
flipDownTrans->setUpdateCallback(flipDownCallback);
/* write into page entry array record */
(*pageEntryArray)[i]->mSwitch = singlePageSwitch;
(*pageEntryArray)[i]->mFlipUpAnim = flipUpCallback;
(*pageEntryArray)[i]->mFlipDownAnim = flipDownCallback;
(*pageEntryArray)[i]->mPageGeode = flipDownGeode;
(*pageEntryArray)[i]->mTexFilename = filename;
}
(*pageEntryArray)[0]->mSwitch->setSingleChildOn(1);
(*pageEntryArray)[1]->mSwitch->setSingleChildOn(0);
/* size of floorplan */
(*pageEntryArray)[0]->mLength = 32; (*pageEntryArray)[0]->mWidth = 16; (*pageEntryArray)[0]->mAlti = -1.5f;
(*pageEntryArray)[1]->mLength = 128; (*pageEntryArray)[1]->mWidth = 128; (*pageEntryArray)[1]->mAlti = -1.5f;
(*pageEntryArray)[2]->mLength = 32; (*pageEntryArray)[2]->mWidth = 16; (*pageEntryArray)[2]->mAlti = -1.5f;
/* set up the forward / backward scale animation paths for sketch book root switch */
AnimationPath* animationPathScaleFwd = new AnimationPath;
AnimationPath* animationPathScaleBwd = new AnimationPath;
animationPathScaleFwd->setLoopMode(AnimationPath::NO_LOOPING);
animationPathScaleBwd->setLoopMode(AnimationPath::NO_LOOPING);
Vec3 scaleFwd, scaleBwd;
float step = 1.f / ANIM_VIRTUAL_SPHERE_NUM_SAMPS;
for (int i = 0; i < ANIM_VIRTUAL_SPHERE_NUM_SAMPS + 1; i++)
{
float val = i * step;
scaleFwd = Vec3(val, val, val);
scaleBwd = Vec3(1.f-val, 1.f-val, 1.f-val);
animationPathScaleFwd->insert(val, AnimationPath::ControlPoint(Vec3(),Quat(), scaleFwd));
animationPathScaleBwd->insert(val, AnimationPath::ControlPoint(Vec3(),Quat(), scaleBwd));
}
AnimationPathCallback *animCallbackFwd = new AnimationPathCallback(animationPathScaleFwd,
0.0, 1.f / ANIM_VIRTUAL_SPHERE_LAPSE_TIME);
AnimationPathCallback *animCallbackBwd = new AnimationPathCallback(animationPathScaleBwd,
0.0, 1.f / ANIM_VIRTUAL_SPHERE_LAPSE_TIME);
(*xformScaleFwd)->setUpdateCallback(animCallbackFwd);
(*xformScaleBwd)->setUpdateCallback(animCallbackBwd);
}
示例15: createOSGAxes
osg::Node* Shape::createOSGAxes(const base::Dimension3& dim)
{
const Real s = 1.5;
Real d = Math::minimum(0.06,Math::minimum(dim.x,dim.y,dim.z)/16.0);
Group* g = NewObj Group;
g->setName("debug");
// color the axes X:red, Y:green and Z:blue, with white end cones
StateSet* red = NewObj StateSet();
osg::Material* rmat = NewObj osg::Material();
Vec4 cred(1,0,0,1);
// mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
//mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
rmat->setDiffuse( osg::Material::FRONT_AND_BACK, cred );
rmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
rmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
red->setAttribute( rmat );
StateSet* green = NewObj StateSet();
osg::Material* gmat = NewObj osg::Material();
Vec4 cgreen(0,1,0,1);
// mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
//mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
gmat->setDiffuse( osg::Material::FRONT_AND_BACK, cgreen );
gmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
gmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
green->setAttribute( gmat );
StateSet* blue = NewObj StateSet();
osg::Material* bmat = NewObj osg::Material();
Vec4 cblue(0,0,1,1);
// mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
//mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
bmat->setDiffuse( osg::Material::FRONT_AND_BACK, cblue );
bmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
bmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
blue->setAttribute( bmat );
StateSet* white = NewObj StateSet();
osg::Material* wmat = NewObj osg::Material();
Vec4 cwhite(1,1,1,1);
// mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
//mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
wmat->setDiffuse( osg::Material::FRONT_AND_BACK, cwhite );
wmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
wmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
white->setAttribute( wmat );
// a long Clyinder for the axis and a cone-like cylinder
// for the arrow head of each X,Y and Z.
MatrixTransform* xrot = NewObj MatrixTransform();
xrot->setMatrix(osg::Matrix::rotate(consts::Pi/2.0,Vec3(0,1,0)));
xrot->postMult(osg::Matrix::translate(s*dim.x/4.0,0,0));
g->addChild(xrot);
MatrixTransform* yrot = NewObj MatrixTransform();
yrot->setMatrix(osg::Matrix::rotate(consts::Pi/2.0,Vec3(-1,0,0)));
yrot->postMult(osg::Matrix::translate(0,s*dim.y/4.0,0));
g->addChild(yrot);
MatrixTransform* zrot = NewObj MatrixTransform();
zrot->setMatrix(osg::Matrix::translate(0,0,s*dim.z/4.0));
g->addChild(zrot);
// the cylinder axes
ref<Cylinder> xc(NewObj Cylinder(s*dim.x/2.0,d));
xrot->addChild(xc->createOSGVisual());
xrot->setStateSet(red);
ref<Cylinder> yc(NewObj Cylinder(s*dim.y/2.0,d));
yrot->addChild(yc->createOSGVisual());
yrot->setStateSet(green);
ref<Cylinder> zc(NewObj Cylinder(s*dim.z/2.0,d));
zrot->addChild(zc->createOSGVisual());
zrot->setStateSet(blue);
// Translate each axis cone to the end
MatrixTransform* xtrans = NewObj MatrixTransform();
xtrans->setMatrix(osg::Matrix::translate(0,0,s*dim.x/4.0+d));
xrot->addChild(xtrans);
MatrixTransform* ytrans = NewObj MatrixTransform();
ytrans->setMatrix(osg::Matrix::translate(0,0,s*dim.y/4.0+d));
yrot->addChild(ytrans);
MatrixTransform* ztrans = NewObj MatrixTransform();
ztrans->setMatrix(osg::Matrix::translate(0,0,s*dim.z/4.0+d));
zrot->addChild(ztrans);
// the end cones
ref<Cone> cone(NewObj Cone(4*d,2*d));
osg::Node* coneNode = cone->createOSGVisual();
coneNode->setStateSet(white);
xtrans->addChild(coneNode);
ytrans->addChild(coneNode);
//.........这里部分代码省略.........