本文整理汇总了C++中TransformKeyFrame::setTranslate方法的典型用法代码示例。如果您正苦于以下问题:C++ TransformKeyFrame::setTranslate方法的具体用法?C++ TransformKeyFrame::setTranslate怎么用?C++ TransformKeyFrame::setTranslate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TransformKeyFrame
的用法示例。
在下文中一共展示了TransformKeyFrame::setTranslate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readKeyFrame
//---------------------------------------------------------------------
void SkeletonSerializer::readKeyFrame(DataStreamPtr& stream, NodeAnimationTrack* track,
Skeleton* pSkel)
{
// float time : The time position (seconds)
float time;
readFloats(stream, &time, 1);
TransformKeyFrame *kf = track->createNodeKeyFrame(time);
// Quaternion rotate : Rotation to apply at this keyframe
Quaternion rot;
readObject(stream, rot);
kf->setRotation(rot);
// Vector3 translate : Translation to apply at this keyframe
Vector3 trans;
readObject(stream, trans);
kf->setTranslate(trans);
// Do we have scale?
if (mCurrentstreamLen > calcKeyFrameSizeWithoutScale(pSkel, kf))
{
Vector3 scale;
readObject(stream, scale);
kf->setScale(scale);
}
}
示例2: _applyBaseKeyFrame
//--------------------------------------------------------------------------
void NodeAnimationTrack::_applyBaseKeyFrame(const KeyFrame* b)
{
const TransformKeyFrame* base = static_cast<const TransformKeyFrame*>(b);
for (KeyFrameList::iterator i = mKeyFrames.begin(); i != mKeyFrames.end(); ++i)
{
TransformKeyFrame* kf = static_cast<TransformKeyFrame*>(*i);
kf->setTranslate(kf->getTranslate() - base->getTranslate());
kf->setRotation(base->getRotation().Inverse() * kf->getRotation());
kf->setScale(kf->getScale() * (Vector3::UNIT_SCALE / base->getScale()));
}
}
示例3: ReadAnimation
void FvXMLAnimationModelSerializerImpl::ReadAnimation(
FvXMLSectionPtr spSection, Ogre::SceneNode* pkNode, FvAnimationModel* pkDest )
{
Ogre::SceneManager *pkSceneManager = Ogre::Root::getSingleton().
_getCurrentSceneManager();
FV_ASSERT(pkSceneManager);
FvString kAnimationName = spSection->ReadString("name");
bool bEnable = spSection->ReadBool("enable");
bool bLoop = spSection->ReadBool("loop");
FvString kIterpolationMode = spSection->ReadString("interpolationMode");
FvString kRotationIterpolationMode = spSection->ReadString("rotationInterpolationMode");
float fLength = spSection->ReadFloat("length");
if(!pkSceneManager->hasAnimation(pkNode->getName() + kAnimationName))
{
std::vector<FvXMLSectionPtr> kKeyFrames;
spSection->OpenSections("keyframe",kKeyFrames);
Animation *pkAnimation = pkSceneManager->createAnimation(pkNode->getName() + kAnimationName, fLength);
if(strcmp(kIterpolationMode.c_str(),"spline") == 0)
pkAnimation->setInterpolationMode(Animation::IM_SPLINE);
else
pkAnimation->setInterpolationMode(Animation::IM_LINEAR);
if(strcmp(kRotationIterpolationMode.c_str(),"spherical") == 0)
pkAnimation->setRotationInterpolationMode(Animation::RIM_SPHERICAL);
else
pkAnimation->setRotationInterpolationMode(Animation::RIM_LINEAR);
NodeAnimationTrack *pkAnimationTrack = pkAnimation->createNodeTrack(
pkAnimation->getNumNodeTracks() + 1, pkNode);
for (size_t stKeyframeIndex = 0; stKeyframeIndex < kKeyFrames.size(); stKeyframeIndex++)
{
float fTime = kKeyFrames[stKeyframeIndex]->ReadFloat("time");
FvVector3 kPosition = kKeyFrames[stKeyframeIndex]->ReadVector3("translation");
FvVector3 kScale = kKeyFrames[stKeyframeIndex]->ReadVector3("scale");
FvQuaternion kQuaternion = kKeyFrames[stKeyframeIndex]->ReadQuaternion("rotation");
TransformKeyFrame *pkKeyFrame = pkAnimationTrack->createNodeKeyFrame(fTime);
pkKeyFrame->setTranslate(Vector3(kPosition.x,kPosition.y,kPosition.z));
pkKeyFrame->setRotation(Quaternion(kQuaternion.w,kQuaternion.x,kQuaternion.y,kQuaternion.z));
pkKeyFrame->setScale(Vector3(kScale.x,kScale.y,kScale.z));
}
AnimationState *pkAnimationState = pkSceneManager->createAnimationState(pkNode->getName() + kAnimationName);
pkAnimationState->setEnabled(bEnable);
pkAnimationState->setLoop(bLoop);
pkDest->m_kModelAnimations.insert(std::make_pair(kAnimationName,pkAnimationState));
}
}
示例4: oldKf
void OgreSample19App::tweakSneakAnim()
{
SkeletonPtr skel = SkeletonManager::getSingleton().load("jaiqua.skeleton",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Animation * anim = skel->getAnimation("Sneak");
Animation::NodeTrackIterator tracks = anim->getNodeTrackIterator();
while(tracks.hasMoreElements())
{
NodeAnimationTrack * track = tracks.getNext();
TransformKeyFrame oldKf(0,0);
track->getInterpolatedKeyFrame(ANIM_CHOP,&oldKf);
while (track->getKeyFrame(track->getNumKeyFrames()-1)->getTime() >= ANIM_CHOP - 0.3f)
{
track->removeKeyFrame(track->getNumKeyFrames()-1);
}
TransformKeyFrame * newKf = track->createNodeKeyFrame(ANIM_CHOP);
TransformKeyFrame * startKf = track->getNodeKeyFrame(0);
Bone * bone = skel->getBone(track->getHandle());
if (bone->getName() == "Spineroot")
{
mSneakStartPos = startKf->getTranslate() + bone->getInitialPosition();
mSneakEndPos = oldKf.getTranslate() + bone->getInitialPosition();
mSneakStartPos.y = mSneakEndPos.y;
newKf->setTranslate(oldKf.getTranslate());
newKf->setRotation(oldKf.getRotation());
newKf->setScale(oldKf.getScale());
}
else
{
newKf->setTranslate(startKf->getTranslate());
newKf->setRotation(startKf->getRotation());
newKf->setScale(startKf->getScale());
}
}
}
示例5: _rebuild
// 重建整个动画控制器
void AnimationTrackController::_rebuild()
{
if(!m_needRebuild)
return;
destroy();
// 计算动画长度
m_length = 0.0f;
{
AnimationTrackObject::ConstKeyFrameIterator iterator = m_animationTrackObject->getConstKeyFrameIterator();
while(iterator.hasMoreElements())
{
const AnimationTrackObject::KeyFrame& keyFrame = iterator.getNext();
m_length += keyFrame.m_length;
}
}
// 创建动画
m_animation = m_sceneMgr->createAnimation(m_animationTrackObject->getFullName() + "_" + m_trackObject->getScene()->getName() + m_trackObject->getName()
, m_length
);
// 使用样条动画
m_animation->setInterpolationMode((Animation::InterpolationMode)m_interpolationMode);
m_animation->setRotationInterpolationMode((Animation::RotationInterpolationMode)m_rotationInterpolationMode);
// 创建节点轨迹动画
m_animationTrack = m_animation->createNodeTrack(0 , m_trackObject->getOgreSceneNode());
// 创建所有关键帧
{
float timePos = 0.0f;
AnimationTrackObject::ConstKeyFrameIterator iterator = m_animationTrackObject->getConstKeyFrameIterator();
while(iterator.hasMoreElements())
{
const AnimationTrackObject::KeyFrame& keyFrame = iterator.getNext();
timePos += keyFrame.m_length;
TransformKeyFrame *frame = m_animationTrack->createNodeKeyFrame(timePos);
frame->setTranslate(keyFrame.m_translate);
frame->setScale(keyFrame.m_scale);
frame->setRotation(keyFrame.m_rotate);
}
}
// 创建动画状态
m_animationState = m_sceneMgr->createAnimationState(m_animation->getName());
// 总是不使用循环系统
m_animationState->setLoop(false);
// 重建完毕
m_needRebuild = false;
}
示例6: createScene
// Just override the mandatory create scene method
void createScene(void)
{
sceneMgr = mSceneMgr ;
// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.75, 0.75, 0.75));
// Create a light
Light* l = mSceneMgr->createLight("MainLight");
// Accept default settings: point light, white diffuse, just set position
// NB I could attach the light to a SceneNode if I wanted it to move automatically with
// other objects, but I don't
l->setPosition(200,300,100);
// Create water mesh and entity
waterMesh = new WaterMesh(MESH_NAME, PLANE_SIZE, COMPLEXITY);
waterEntity = mSceneMgr->createEntity(ENTITY_NAME,
MESH_NAME);
//~ waterEntity->setMaterialName(MATERIAL_NAME);
SceneNode *waterNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
waterNode->attachObject(waterEntity);
// Add a head, give it it's own node
headNode = waterNode->createChildSceneNode();
Entity *ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
headNode->attachObject(ent);
// Make sure the camera track this node
//~ mCamera->setAutoTracking(true, headNode);
// Create the camera node, set its position & attach camera
SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
camNode->translate(0, 500, PLANE_SIZE);
camNode->yaw(Degree(-45));
camNode->attachObject(mCamera);
// Create light node
SceneNode* lightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
lightNode->attachObject(l);
// set up spline animation of light node
Animation* anim = mSceneMgr->createAnimation("WaterLight", 20);
NodeAnimationTrack *track ;
TransformKeyFrame *key ;
// create a random spline for light
track = anim->createNodeTrack(0, lightNode);
key = track->createNodeKeyFrame(0);
for(int ff=1;ff<=19;ff++) {
key = track->createNodeKeyFrame(ff);
Vector3 lpos (
rand()%(int)PLANE_SIZE , //- PLANE_SIZE/2,
rand()%300+100,
rand()%(int)PLANE_SIZE //- PLANE_SIZE/2
);
key->setTranslate(lpos);
}
key = track->createNodeKeyFrame(20);
// Create a new animation state to track this
mAnimState = mSceneMgr->createAnimationState("WaterLight");
mAnimState->setEnabled(true);
// Put in a bit of fog for the hell of it
//mSceneMgr->setFog(FOG_EXP, ColourValue::White, 0.0002);
// show overlay
waterOverlay = OverlayManager::getSingleton().getByName("Example/WaterOverlay");
waterOverlay->show();
// Let there be rain
particleSystem = mSceneMgr->createParticleSystem("rain",
"Examples/Water/Rain");
particleEmitter = particleSystem->getEmitter(0);
SceneNode* rNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
rNode->translate(PLANE_SIZE/2.0f, 3000, PLANE_SIZE/2.0f);
rNode->attachObject(particleSystem);
// Fast-forward the rain so it looks more natural
particleSystem->fastForward(20);
// It can't be set in .particle file, and we need it ;)
static_cast<BillboardParticleRenderer*>(particleSystem->getRenderer())->setBillboardOrigin(BBO_BOTTOM_CENTER);
prepareCircleMaterial();
}
示例7: _mergeSkeletonAnimations
//.........这里部分代码省略.........
{
// New bone, the delta-transform is identity
deltaTransform.translate = Vector3::ZERO;
deltaTransform.rotate = Quaternion::IDENTITY;
deltaTransform.scale = Vector3::UNIT_SCALE;
deltaTransform.isIdentity = true;
}
}
// Now copy animations
ushort numAnimations;
if (animations.empty())
numAnimations = src->getNumAnimations();
else
numAnimations = static_cast<ushort>(animations.size());
for (ushort i = 0; i < numAnimations; ++i)
{
const Animation* srcAnimation;
if (animations.empty())
{
// Get animation of source skeleton by the given index
srcAnimation = src->getAnimation(i);
}
else
{
// Get animation of source skeleton by the given name
const LinkedSkeletonAnimationSource* linker;
srcAnimation = src->_getAnimationImpl(animations[i], &linker);
if (!srcAnimation || linker)
{
OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
"No animation entry found named " + animations[i],
"Skeleton::_mergeSkeletonAnimations");
}
}
// Create target animation
Animation* dstAnimation = this->createAnimation(srcAnimation->getName(), srcAnimation->getLength());
// Copy interpolation modes
dstAnimation->setInterpolationMode(srcAnimation->getInterpolationMode());
dstAnimation->setRotationInterpolationMode(srcAnimation->getRotationInterpolationMode());
// Copy track for each bone
for (handle = 0; handle < numSrcBones; ++handle)
{
const DeltaTransform& deltaTransform = deltaTransforms[handle];
ushort dstHandle = boneHandleMap[handle];
if (srcAnimation->hasNodeTrack(handle))
{
// Clone track from source animation
const NodeAnimationTrack* srcTrack = srcAnimation->getNodeTrack(handle);
NodeAnimationTrack* dstTrack = dstAnimation->createNodeTrack(dstHandle, this->getBone(dstHandle));
dstTrack->setUseShortestRotationPath(srcTrack->getUseShortestRotationPath());
ushort numKeyFrames = srcTrack->getNumKeyFrames();
for (ushort k = 0; k < numKeyFrames; ++k)
{
const TransformKeyFrame* srcKeyFrame = srcTrack->getNodeKeyFrame(k);
TransformKeyFrame* dstKeyFrame = dstTrack->createNodeKeyFrame(srcKeyFrame->getTime());
// Adjust keyframes to match target binding pose
if (deltaTransform.isIdentity)
{
dstKeyFrame->setTranslate(srcKeyFrame->getTranslate());
dstKeyFrame->setRotation(srcKeyFrame->getRotation());
dstKeyFrame->setScale(srcKeyFrame->getScale());
}
else
{
dstKeyFrame->setTranslate(deltaTransform.translate + srcKeyFrame->getTranslate());
dstKeyFrame->setRotation(deltaTransform.rotate * srcKeyFrame->getRotation());
dstKeyFrame->setScale(deltaTransform.scale * srcKeyFrame->getScale());
}
}
}
else if (!deltaTransform.isIdentity)
{
// Create 'static' track for this bone
NodeAnimationTrack* dstTrack = dstAnimation->createNodeTrack(dstHandle, this->getBone(dstHandle));
TransformKeyFrame* dstKeyFrame;
dstKeyFrame = dstTrack->createNodeKeyFrame(0);
dstKeyFrame->setTranslate(deltaTransform.translate);
dstKeyFrame->setRotation(deltaTransform.rotate);
dstKeyFrame->setScale(deltaTransform.scale);
dstKeyFrame = dstTrack->createNodeKeyFrame(dstAnimation->getLength());
dstKeyFrame->setTranslate(deltaTransform.translate);
dstKeyFrame->setRotation(deltaTransform.rotate);
dstKeyFrame->setScale(deltaTransform.scale);
}
}
}
}
示例8: createSampleLights
//.........这里部分代码省略.........
MLight *d = mSystem->createMLight();
SceneNode *dn = parentNode->createChildSceneNode();
dn->attachObject(d);
d->setAttenuation(1.0f, 0.002f, 0.002f);
dn->setPosition(-25,0,0);
d->setDiffuseColour(1,0,1);
d->setSpecularColour(0.0,0,0.0);
lights.push_back(d);
nodes.push_back(dn);
MLight *e = mSystem->createMLight();
SceneNode *en = parentNode->createChildSceneNode();
en->attachObject(e);
e->setAttenuation(1.0f, 0.002f, 0.0025f);
en->setPosition(25,0,25);
e->setDiffuseColour(0,0,1);
e->setSpecularColour(0,0,0);
lights.push_back(e);
nodes.push_back(en);
MLight *f = mSystem->createMLight();
SceneNode *fn = parentNode->createChildSceneNode();
fn->attachObject(f);
f->setAttenuation(1.0f, 0.0015f, 0.0021f);
fn->setPosition(-25,0,-25);
f->setDiffuseColour(0,1,0);
f->setSpecularColour(0,0.0,0.0);
lights.push_back(f);
nodes.push_back(fn);
// Create marker meshes to show user where the lights are
Entity *ent;
GeomUtils::createSphere("PointLightMesh", 1.0f, 5, 5, true, true);
for(std::vector<MLight*>::iterator i=lights.begin(); i!=lights.end(); ++i)
{
MLight* light = *i;
ent = mSceneMgr->createEntity(light->getName()+"v", "PointLightMesh");
String matname = light->getName()+"m";
// Create coloured material
MaterialPtr mat = MaterialManager::getSingleton().create(matname,
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Pass* pass = mat->getTechnique(0)->getPass(0);
pass->setDiffuse(0.0f,0.0f,0.0f,1.0f);
pass->setAmbient(0.0f,0.0f,0.0f);
pass->setSelfIllumination(light->getDiffuseColour());
ent->setMaterialName(matname);
ent->setRenderQueueGroup(light->getRenderQueueGroup());
static_cast<SceneNode*>(light->getParentNode())->attachObject(ent);
}
// Store nodes for hiding/showing
SharedData::getSingleton().mLightNodes = nodes;
// Do some animation for node a-f
// Generate helix structure
float seconds_per_station = 1.0f;
float r=35;
//Vector3 base(0,-30,0);
Vector3 base(-100, -30, 85);
float h=120;
const size_t s_to_top = 16;
const size_t stations = s_to_top*2-1;
float ascend = h/((float)s_to_top);
float stations_per_revolution = 3.5f;
size_t skip = 2; // stations between lights
Vector3 station_pos[stations];
for(int x=0; x<s_to_top; ++x)
{
float theta = ((float)x/stations_per_revolution)*2.0f*Math::PI;
station_pos[x] = base+Vector3(Math::Sin(theta)*r, ascend*x, Math::Cos(theta)*r);
}
for(int x=s_to_top; x<stations; ++x)
{
float theta = ((float)x/stations_per_revolution)*2.0f*Math::PI;
station_pos[x] = base+Vector3(Math::Sin(theta)*r, h-ascend*(x-s_to_top), Math::Cos(theta)*r);
}
// Create a track for the light swarm
Animation* anim = mSceneMgr->createAnimation("LightSwarmTrack", stations*seconds_per_station);
// Spline it for nice curves
anim->setInterpolationMode(Animation::IM_SPLINE);
for(unsigned int x=0; x<nodes.size(); ++x)
{
// Create a track to animate the camera's node
NodeAnimationTrack* track = anim->createNodeTrack(x, nodes[x]);
for(int y=0; y<=stations; ++y)
{
// Setup keyframes
TransformKeyFrame* key = track->createNodeKeyFrame(y*seconds_per_station); // A start position
key->setTranslate(station_pos[(x*skip+y)%stations]);
// Make sure size of light doesn't change
key->setScale(nodes[x]->getScale());
}
}
// Create a new animation state to track this
SharedData::getSingleton().mMLAnimState = mSceneMgr->createAnimationState("LightSwarmTrack");
SharedData::getSingleton().mMLAnimState->setEnabled(true);
}
示例9: createScene
//.........这里部分代码省略.........
2000, 2000, -1000,
20, 20,
true, 1, 10, 10, Vector3::UNIT_Z);
mPlaneEnt = mSceneMgr->createEntity( "Plane", "ReflectionPlane" );
mPlaneNode = rootNode->createChildSceneNode();
mPlaneNode->attachObject(mPlaneEnt);
mPlaneNode->translate(-5, -30, 0);
//mPlaneNode->roll(Degree(5));
mPlaneEnt->setMaterialName("DeferredDemo/Ground");
// Create an entity from a model (will be loaded automatically)
Entity* knotEnt = mSceneMgr->createEntity("Knot", "knot.mesh");
knotEnt->setMaterialName("DeferredDemo/RockWall");
knotEnt->setMeshLodBias(0.25f);
// Create an entity from a model (will be loaded automatically)
Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
ogreHead->getSubEntity(0)->setMaterialName("DeferredDemo/Ogre/Eyes");// eyes
ogreHead->getSubEntity(1)->setMaterialName("DeferredDemo/Ogre/Skin");
ogreHead->getSubEntity(2)->setMaterialName("DeferredDemo/Ogre/EarRing"); // earrings
ogreHead->getSubEntity(3)->setMaterialName("DeferredDemo/Ogre/Tusks"); // tusks
rootNode->createChildSceneNode( "Head" )->attachObject( ogreHead );
// Add a whole bunch of extra entities to fill the scene a bit
Entity *cloneEnt;
int N=4;
for (int n = 0; n < N; ++n)
{
float theta = 2.0f*Math::PI*(float)n/(float)N;
// Create a new node under the root
SceneNode* node = mSceneMgr->createSceneNode();
// Random translate
Vector3 nodePos;
nodePos.x = Math::SymmetricRandom() * 40.0 + Math::Sin(theta) * 500.0;
nodePos.y = Math::SymmetricRandom() * 20.0 - 40.0;
nodePos.z = Math::SymmetricRandom() * 40.0 + Math::Cos(theta) * 500.0;
node->setPosition(nodePos);
Quaternion orientation(Math::SymmetricRandom(),Math::SymmetricRandom(),Math::SymmetricRandom(),Math::SymmetricRandom());
orientation.normalise();
node->setOrientation(orientation);
rootNode->addChild(node);
// Clone knot
char cloneName[12];
sprintf(cloneName, "Knot%d", n);
cloneEnt = knotEnt->clone(cloneName);
// Attach to new node
node->attachObject(cloneEnt);
}
mCamera->setPosition(-50, 100, 500);
mCamera->lookAt(0,0,0);
// show overlay
Overlay* overlay = OverlayManager::getSingleton().getByName("Example/ShadowsOverlay");
overlay->show();
mSystem = new DeferredShadingSystem(mWindow->getViewport(0), mSceneMgr, mCamera);
// Create main, moving light
MLight* l1 = mSystem->createMLight();//"MainLight");
l1->setDiffuseColour(0.75f, 0.7f, 0.8f);
l1->setSpecularColour(0.85f, 0.9f, 1.0f);
SceneNode *lightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
lightNode->attachObject(l1);
// Create a track for the light
Animation* anim = mSceneMgr->createAnimation("LightTrack", 16);
// Spline it for nice curves
anim->setInterpolationMode(Animation::IM_SPLINE);
// Create a track to animate the camera's node
NodeAnimationTrack* track = anim->createNodeTrack(0, lightNode);
// Setup keyframes
TransformKeyFrame* key = track->createNodeKeyFrame(0); // A start position
key->setTranslate(Vector3(300,300,-300));
key = track->createNodeKeyFrame(4);//B
key->setTranslate(Vector3(300,300,300));
key = track->createNodeKeyFrame(8);//C
key->setTranslate(Vector3(-300,300,300));
key = track->createNodeKeyFrame(12);//D
key->setTranslate(Vector3(-300,300,-300));
key = track->createNodeKeyFrame(16);//D
key->setTranslate(Vector3(300,300,-300));
// Create a new animation state to track this
SharedData::getSingleton().mAnimState = mSceneMgr->createAnimationState("LightTrack");
SharedData::getSingleton().mAnimState->setEnabled(true);
// Create some happy little lights
createSampleLights();
// safely setup application's (not postfilter!) shared data
SharedData::getSingleton().iCamera = mCamera;
SharedData::getSingleton().iRoot = mRoot;
SharedData::getSingleton().iWindow = mWindow;
SharedData::getSingleton().iActivate = true;
SharedData::getSingleton().iGlobalActivate = true;
SharedData::getSingleton().iSystem = mSystem;
SharedData::getSingleton().iMainLight = l1;
}
示例10: getInterpolatedKeyFrame
//---------------------------------------------------------------------
void NodeAnimationTrack::getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const
{
if (mListener)
{
if (mListener->getInterpolatedKeyFrame(this, timeIndex, kf))
return;
}
TransformKeyFrame* kret = static_cast<TransformKeyFrame*>(kf);
// Keyframe pointers
KeyFrame *kBase1, *kBase2;
TransformKeyFrame *k1, *k2;
unsigned short firstKeyIndex;
Real t = this->getKeyFramesAtTime(timeIndex, &kBase1, &kBase2, &firstKeyIndex);
k1 = static_cast<TransformKeyFrame*>(kBase1);
k2 = static_cast<TransformKeyFrame*>(kBase2);
if (t == 0.0)
{
// Just use k1
kret->setRotation(k1->getRotation());
kret->setTranslate(k1->getTranslate());
kret->setScale(k1->getScale());
}
else
{
// Interpolate by t
Animation::InterpolationMode im = mParent->getInterpolationMode();
Animation::RotationInterpolationMode rim =
mParent->getRotationInterpolationMode();
Vector3 base;
switch(im)
{
case Animation::IM_LINEAR:
// Interpolate linearly
// Rotation
// Interpolate to nearest rotation if mUseShortestRotationPath set
if (rim == Animation::RIM_LINEAR)
{
kret->setRotation( Quaternion::nlerp(t, k1->getRotation(),
k2->getRotation(), mUseShortestRotationPath) );
}
else //if (rim == Animation::RIM_SPHERICAL)
{
kret->setRotation( Quaternion::Slerp(t, k1->getRotation(),
k2->getRotation(), mUseShortestRotationPath) );
}
// Translation
base = k1->getTranslate();
kret->setTranslate( base + ((k2->getTranslate() - base) * t) );
// Scale
base = k1->getScale();
kret->setScale( base + ((k2->getScale() - base) * t) );
break;
case Animation::IM_SPLINE:
// Spline interpolation
// Build splines if required
if (mSplineBuildNeeded)
{
buildInterpolationSplines();
}
// Rotation, take mUseShortestRotationPath into account
kret->setRotation( mSplines->rotationSpline.interpolate(firstKeyIndex, t,
mUseShortestRotationPath) );
// Translation
kret->setTranslate( mSplines->positionSpline.interpolate(firstKeyIndex, t) );
// Scale
kret->setScale( mSplines->scaleSpline.interpolate(firstKeyIndex, t) );
break;
}
}
}
示例11: sampleAllBones
//-----------------------------------------------------------------------------
void XsiSkeletonExporter::sampleAllBones(DeformerMap& deformers,
std::vector<NodeAnimationTrack*> deformerTracks, double frame,
Real time, float fps, AxisAlignedBox& AABBPadding)
{
CValueArray args;
CValue dummy;
args.Resize(2);
// set the playcontrol
args[0] = L"PlayControl.Key";
args[1] = frame;
mXsiApp.ExecuteCommand(L"SetValue", args, dummy);
args[0] = L"PlayControl.Current";
mXsiApp.ExecuteCommand(L"SetValue", args, dummy);
// Refresh
mXsiApp.ExecuteCommand(L"Refresh", CValueArray(), dummy);
// Sample all bones
for (DeformerMap::iterator di = deformers.begin(); di != deformers.end(); ++di)
{
DeformerEntry* deformer = di->second;
NodeAnimationTrack* track = deformerTracks[deformer->boneID];
double initposx, initposy, initposz;
deformer->initialXform.GetTranslationValues(initposx, initposy, initposz);
double initrotx, initroty, initrotz;
deformer->initialXform.GetRotation().GetXYZAngles(initrotx, initroty, initrotz);
double initsclx, initscly, initsclz;
deformer->initialXform.GetScalingValues(initsclx, initscly, initsclz);
XSI::MATH::CMatrix4 invTrans = deformer->initialXform.GetMatrix4();
invTrans.InvertInPlace();
XSI::MATH::CTransformation transformation;
if (deformer->pBone->getParent() == 0)
{
// Based on global
transformation =
deformer->obj.GetKinematics().GetGlobal().GetTransform();
}
else
{
// Based on local
transformation =
deformer->obj.GetKinematics().GetLocal().GetTransform();
}
double posx, posy, posz;
transformation.GetTranslationValues(posx, posy, posz);
double sclx, scly, sclz;
transformation.GetScalingValues(sclx, scly, sclz);
// Make relative to initial
XSI::MATH::CMatrix4 transformationMatrix = transformation.GetMatrix4();
transformationMatrix.MulInPlace(invTrans);
transformation.SetMatrix4(transformationMatrix);
// create keyframe
TransformKeyFrame* kf = track->createNodeKeyFrame(time);
// not sure why inverted transform doesn't work for position, but it doesn't
// I thought XSI used same transform order as OGRE
kf->setTranslate(Vector3(posx - initposx, posy - initposy, posz - initposz));
kf->setRotation(XSItoOgre(transformation.GetRotationQuaternion()));
kf->setScale(Vector3(sclx / initsclx, scly / initscly, sclz / initsclz));
// Derive AABB of bone positions, for padding animated mesh AABB
XSI::MATH::CVector3 bonePos =
deformer->obj.GetKinematics().GetGlobal().GetTransform().GetTranslation();
AABBPadding.merge(XSItoOgre(bonePos));
}
}
示例12: readKeyFrames
//---------------------------------------------------------------------
void XMLSkeletonSerializer::readKeyFrames(NodeAnimationTrack* track, TiXmlElement* mKeyfNode) {
TransformKeyFrame* kf ;
Quaternion q ;
for (TiXmlElement* keyfElem = mKeyfNode->FirstChildElement("keyframe"); keyfElem != 0; keyfElem = keyfElem->NextSiblingElement())
{
Vector3 trans;
Vector3 axis;
Radian angle;
Real time;
// Get time and create keyframe
time = StringConverter::parseReal(keyfElem->Attribute("time"));
kf = track->createNodeKeyFrame(time);
// Optional translate
TiXmlElement* transElem = keyfElem->FirstChildElement("translate");
if (transElem)
{
trans.x = StringConverter::parseReal(transElem->Attribute("x"));
trans.y = StringConverter::parseReal(transElem->Attribute("y"));
trans.z = StringConverter::parseReal(transElem->Attribute("z"));
kf->setTranslate(trans) ;
}
// Optional rotate
TiXmlElement* rotElem = keyfElem->FirstChildElement("rotate");
if (rotElem)
{
TiXmlElement* axisElem = rotElem->FirstChildElement("axis");
if (!axisElem)
{
OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Missing 'axis' element "
"expected under parent 'rotate'", "MXLSkeletonSerializer::readKeyFrames");
}
angle = Radian(StringConverter::parseReal(rotElem->Attribute("angle")));
axis.x = StringConverter::parseReal(axisElem->Attribute("x"));
axis.y = StringConverter::parseReal(axisElem->Attribute("y"));
axis.z = StringConverter::parseReal(axisElem->Attribute("z"));
q.FromAngleAxis(angle,axis);
kf->setRotation(q) ;
}
// Optional scale
TiXmlElement* scaleElem = keyfElem->FirstChildElement("scale");
if (scaleElem)
{
// Uniform scale or per axis?
const char* factorAttrib = scaleElem->Attribute("factor");
if (factorAttrib)
{
// Uniform scale
Real factor = StringConverter::parseReal(factorAttrib);
kf->setScale(Vector3(factor, factor, factor));
}
else
{
// axis scale
Real xs = 1.0f, ys = 1.0f, zs=1.0f;
const char* factorString = scaleElem->Attribute("x");
if(factorString)
{
xs = StringConverter::parseReal(factorString);
}
factorString = scaleElem->Attribute("y");
if(factorString)
{
ys = StringConverter::parseReal(factorString);
}
factorString = scaleElem->Attribute("z");
if(factorString)
{
zs = StringConverter::parseReal(factorString);
}
kf->setScale(Vector3(xs, ys, zs));
}
}
/*
LogManager::getSingleton().logMessage("Keyframe: translation("
+ StringConverter::toString(trans.x) + "," + StringConverter::toString(trans.y) + "," + StringConverter::toString(trans.z) + ")"
+ " - angle: " + StringConverter::toString(angle) +" - axe: "
+ StringConverter::toString(axis.x) + "," + StringConverter::toString(axis.y) + "," + StringConverter::toString(axis.z) );
*/
}
}
示例13: setupContent
void Sample_VolumeTex::setupContent()
{
// Create dynamic texture
ptex = TextureManager::getSingleton().createManual(
"DynaTex","General", TEX_TYPE_3D, 64, 64, 64, 0, PF_A8R8G8B8);
// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.6, 0.6, 0.6));
mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox", 50 );
//mRoot->getRenderSystem()->clearFrameBuffer(FBT_COLOUR, ColourValue(255,255,255,0));
// Create a light
Light* l = mSceneMgr->createLight("MainLight");
l->setDiffuseColour(0.75, 0.75, 0.80);
l->setSpecularColour(0.9, 0.9, 1);
l->setPosition(-100,80,50);
mSceneMgr->getRootSceneNode()->attachObject(l);
// Create volume renderable
snode = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,0,0));
vrend = new VolumeRenderable(32, 750.0f, "DynaTex");
snode->attachObject( vrend );
trend = new ThingRenderable(90.0f, 32, 7.5f);
trend->setMaterial("Examples/VTDarkStuff");
snode->attachObject(trend);
// Ogre head node
fnode = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,0,0));
// Load ogre head
Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh");
fnode->attachObject(head);
// Animation for ogre head
// Create a track for the light
Animation* anim = mSceneMgr->createAnimation("OgreTrack", 10);
// Spline it for nice curves
anim->setInterpolationMode(Animation::IM_SPLINE);
// Create a track to animate the camera's node
NodeAnimationTrack* track = anim->createNodeTrack(0, fnode);
// Setup keyframes
TransformKeyFrame* key = track->createNodeKeyFrame(0); // A startposition
key->setTranslate(Vector3(0.0f, -15.0f, 0.0f));
key = track->createNodeKeyFrame(5);//B
key->setTranslate(Vector3(0.0f, 15.0f, 0.0f));
key = track->createNodeKeyFrame(10);//C
key->setTranslate(Vector3(0.0f, -15.0f, 0.0f));
// Create a new animation state to track this
mOgreAnimState = mSceneMgr->createAnimationState("OgreTrack");
mOgreAnimState->setEnabled(true);
//mFountainNode->attachObject(pSys2);
//Setup defaults
global_real = 0.4f;
global_imag = 0.6f;
global_theta = 0.0f;
// show GUI
createControls();
setDragLook(true);
generate();
}
示例14: Degree
void OgreSample18App::createScene()
{
mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
mCurrentShadowTechnique = SHADOWTYPE_STENCIL_ADDITIVE;
// Set ambient light off
mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0));
// Fixed light, dim
mSunLight = mSceneMgr->createLight("SunLight");
mSunLight->setType(Light::LT_SPOTLIGHT);
mSunLight->setPosition(1500,1750,1300);
mSunLight->setSpotlightRange(Degree(30), Degree(50));
Ogre::Vector3 dir;
dir = -mSunLight->getPosition();
dir.normalise();
mSunLight->setDirection(dir);
mSunLight->setDiffuseColour(0.35, 0.35, 0.38);
mSunLight->setSpecularColour(0.9, 0.9, 1);
// Point light, movable, reddish
mLight = mSceneMgr->createLight("Light2");
mLight->setDiffuseColour(mMinLightColour);
mLight->setSpecularColour(1, 1, 1);
mLight->setAttenuation(8000,1,0.0005,0);
// Create light node
mLightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
"MovingLightNode");
mLightNode->attachObject(mLight);
// create billboard set
BillboardSet* bbs = mSceneMgr->createBillboardSet("lightbbs", 1);
bbs->setMaterialName("Examples/Flare");
Billboard* bb = bbs->createBillboard(0,0,0,mMinLightColour);
// attach
mLightNode->attachObject(bbs);
ControllerFunctionRealPtr func = ControllerFunctionRealPtr(new WaveformControllerFunction(Ogre::WFT_SINE,0.75f,0.5f));
ControllerManager& contMgr = ControllerManager::getSingleton();
ControllerValueRealPtr val = ControllerValueRealPtr(new LightWibbler(mLight,bb,mMinLightColour,mMaxLightColour,mMinFlareSize,mMaxFlareSize));
mController = contMgr.createController(contMgr.getFrameTimeSource(),val,func);
mLightNode->setPosition(Vector3(300,1750,-700));
Animation* anim = mSceneMgr->createAnimation("LightTrack", 20);
// Spline it for nice curves
anim->setInterpolationMode(Animation::IM_SPLINE);
// Create a track to animate the camera's node
NodeAnimationTrack* track = anim->createNodeTrack(0, mLightNode);
// Setup keyframes
TransformKeyFrame* key = track->createNodeKeyFrame(0); // A startposition
key->setTranslate(Vector3(300,750,-700));
key = track->createNodeKeyFrame(2);//B
key->setTranslate(Vector3(150,800,-250));
key = track->createNodeKeyFrame(4);//C
key->setTranslate(Vector3(-150,850,-100));
key = track->createNodeKeyFrame(6);//D
key->setTranslate(Vector3(-400,700,-200));
key = track->createNodeKeyFrame(8);//E
key->setTranslate(Vector3(-200,700,-400));
key = track->createNodeKeyFrame(10);//F
key->setTranslate(Vector3(-100,850,-200));
key = track->createNodeKeyFrame(12);//G
key->setTranslate(Vector3(-100,575,180));
key = track->createNodeKeyFrame(14);//H
key->setTranslate(Vector3(0,750,300));
key = track->createNodeKeyFrame(16);//I
key->setTranslate(Vector3(100,850,100));
key = track->createNodeKeyFrame(18);//J
key->setTranslate(Vector3(250,800,0));
key = track->createNodeKeyFrame(20);//K == A
key->setTranslate(Vector3(300,750,-700));
// Create a new animation state to track this
mAnimState = mSceneMgr->createAnimationState("LightTrack");
mAnimState->setEnabled(true);
mLightNode->setAutoTracking(true,mSceneMgr->getRootSceneNode());
MeshPtr pAthene = MeshManager::getSingleton().load("athene.mesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
unsigned short src, dest;
if (!pAthene->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
{
pAthene->buildTangentVectors(VES_TANGENT, src, dest);
}
SceneNode* node;
node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mAthene = mSceneMgr->createEntity( "athene", "athene.mesh" );
mAthene->setMaterialName(BASIC_ATHENE_MATERIAL);
node->attachObject( mAthene );
node->yaw(Degree(90));
Entity* pEnt;
// Columns
for (int x = -2; x <= 2; ++x)
{
for (int z = -2; z <= 2; ++z)
{
if (x != 0 || z != 0)
{
StringUtil::StrStreamType str;
//.........这里部分代码省略.........
示例15: bake
SkeletonPtr MergeSkeleton::bake()
{
MeshCombiner::getSingleton().log(
"Baking: New Skeleton started" );
SkeletonPtr sp = SkeletonManager::getSingleton().create( "mergeSkeleton",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true );
for( std::vector< Ogre::SkeletonPtr >::iterator it = m_Skeletons.begin();
it != m_Skeletons.end(); ++it )
{
if( it == m_Skeletons.begin() )
{
MeshCombiner::getSingleton().log(
"Baking: using " + (*it)->getName() + " as the base skeleton" );
MeshCombiner::getSingleton().log(
"Baking: adding bones" );
Skeleton::BoneIterator bit = (*it)->getBoneIterator();
while( bit.hasMoreElements() )
{
Bone* bone = bit.getNext();
Bone* newbone = sp->createBone( bone->getName(), bone->getHandle() );
newbone->setScale( bone->getScale() );
newbone->setOrientation( bone->getOrientation() );
newbone->setPosition( bone->getPosition() );
}
MeshCombiner::getSingleton().log(
"Baking: building bone hierarchy" );
// bone hierarchy
bit = (*it)->getBoneIterator();
while( bit.hasMoreElements() )
{
Bone* bone = bit.getNext();
Node* pnode = bone->getParent();
if( pnode != NULL )
{
Bone* pbone = static_cast<Bone*>( pnode );
sp->getBone( pbone->getHandle() )->addChild( sp->getBone( bone->getHandle() ) );
}
}
}
MeshCombiner::getSingleton().log(
"Baking: adding animations for " + (*it)->getName() );
// insert all animations
for (unsigned short a=0; a < (*it)->getNumAnimations(); ++a )
{
Animation* anim = (*it)->getAnimation( a );
Animation* newanim = sp->createAnimation( anim->getName(), anim->getLength() );
if( anim->getNumNodeTracks() > 0 )
MeshCombiner::getSingleton().log(
"Baking: adding node tracks" );
for( unsigned short na=0; na < anim->getNumNodeTracks(); ++na )
{
if( anim->hasNodeTrack( na ) )
{
NodeAnimationTrack* nat = anim->getNodeTrack( na );
NodeAnimationTrack* newnat = newanim->createNodeTrack( na );
// all key frames
for( unsigned short nf=0; nf < nat->getNumKeyFrames(); ++nf )
{
TransformKeyFrame* tkf = nat->getNodeKeyFrame( nf );
TransformKeyFrame* newtkf = newnat->createNodeKeyFrame( tkf->getTime() );
newtkf->setRotation( tkf->getRotation() );
newtkf->setTranslate( tkf->getTranslate() );
newtkf->setScale( tkf->getScale() );
}
newnat->setAssociatedNode( sp->getBone( nat->getHandle() ) );
}
}
if( anim->getNumNumericTracks() > 0 )
MeshCombiner::getSingleton().log(
"Baking: adding numeric tracks" );
for( unsigned short na=0; na < anim->getNumNumericTracks(); ++na )
{
if( anim->hasNumericTrack( na ) )
{
NumericAnimationTrack* nat = anim->getNumericTrack( na );
NumericAnimationTrack* newnat = newanim->createNumericTrack( na );
// all key frames
for( unsigned short nf=0; nf < nat->getNumKeyFrames(); ++nf )
{
NumericKeyFrame* nkf = nat->getNumericKeyFrame( nf );
NumericKeyFrame* newnkf = newnat->createNumericKeyFrame( nkf->getTime() );
newnkf->setValue( nkf->getValue() );
}
}
}
if( anim->getNumVertexTracks() > 0 )
MeshCombiner::getSingleton().log(
"Baking: adding vertex tracks" );
for( unsigned short va=0; va < anim->getNumVertexTracks(); ++va )
{
//.........这里部分代码省略.........