本文整理汇总了C++中Quaternion::FromAxes方法的典型用法代码示例。如果您正苦于以下问题:C++ Quaternion::FromAxes方法的具体用法?C++ Quaternion::FromAxes怎么用?C++ Quaternion::FromAxes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Quaternion
的用法示例。
在下文中一共展示了Quaternion::FromAxes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _notifyCurrentCamera
void VolumeRenderable::_notifyCurrentCamera( Camera* cam )
{
MovableObject::_notifyCurrentCamera(cam);
// Fake orientation toward camera
Vector3 zVec = getParentNode()->_getDerivedPosition() - cam->getDerivedPosition();
zVec.normalise();
Vector3 fixedAxis = cam->getDerivedOrientation() * Vector3::UNIT_Y ;
Vector3 xVec = fixedAxis.crossProduct( zVec );
xVec.normalise();
Vector3 yVec = zVec.crossProduct( xVec );
yVec.normalise();
Quaternion oriQuat;
oriQuat.FromAxes( xVec, yVec, zVec );
oriQuat.ToRotationMatrix(mFakeOrientation);
Matrix3 tempMat;
Quaternion q = getParentNode()->_getDerivedOrientation().UnitInverse() * oriQuat ;
q.ToRotationMatrix(tempMat);
Matrix4 rotMat = Matrix4::IDENTITY;
rotMat = tempMat;
rotMat.setTrans(Vector3(0.5f, 0.5f, 0.5f));
mUnit->setTextureTransform(rotMat);
}
示例2: FromLookRotation
bool Quaternion::FromLookRotation(const Vector3& direction, const Vector3& upDirection)
{
Quaternion ret;
Vector3 forward = direction.Normalized();
Vector3 v = forward.CrossProduct(upDirection);
// If direction & upDirection are parallel and crossproduct becomes zero, use FromRotationTo() fallback
if (v.LengthSquared() >= M_EPSILON)
{
v.Normalize();
Vector3 up = v.CrossProduct(forward);
Vector3 right = up.CrossProduct(forward);
ret.FromAxes(right, up, forward);
}
else
ret.FromRotationTo(Vector3::FORWARD, forward);
if (!ret.IsNaN())
{
(*this) = ret;
return true;
}
else
return false;
}
示例3: dummyNode
//-----------------------------------------------------------------------------
const Matrix4& AutoParamDataSource::getSpotlightViewProjMatrix(size_t index) const
{
if (index < OGRE_MAX_SIMULTANEOUS_LIGHTS)
{
const Light& l = getLight(index);
if (&l != &mBlankLight &&
l.getType() == Light::LT_SPOTLIGHT &&
mSpotlightViewProjMatrixDirty[index])
{
Frustum frust;
SceneNode dummyNode(0);
dummyNode.attachObject(&frust);
frust.setProjectionType(PT_PERSPECTIVE);
frust.setFOVy(l.getSpotlightOuterAngle());
frust.setAspectRatio(1.0f);
// set near clip the same as main camera, since they are likely
// to both reflect the nature of the scene
frust.setNearClipDistance(mCurrentCamera->getNearClipDistance());
// Calculate position, which same as spotlight position, in camera-relative coords if required
dummyNode.setPosition(l.getDerivedPosition(true));
// Calculate direction, which same as spotlight direction
Vector3 dir = - l.getDerivedDirection(); // backwards since point down -z
dir.normalise();
Vector3 up = Vector3::UNIT_Y;
// Check it's not coincident with dir
if (Math::Abs(up.dotProduct(dir)) >= 1.0f)
{
// Use camera up
up = Vector3::UNIT_Z;
}
// cross twice to rederive, only direction is unaltered
Vector3 left = dir.crossProduct(up);
left.normalise();
up = dir.crossProduct(left);
up.normalise();
// Derive quaternion from axes
Quaternion q;
q.FromAxes(left, up, dir);
dummyNode.setOrientation(q);
// The view matrix here already includes camera-relative changes if necessary
// since they are built into the frustum position
mSpotlightViewProjMatrix[index] =
PROJECTIONCLIPSPACE2DTOIMAGESPACE_PERSPECTIVE *
frust.getProjectionMatrixWithRSDepth() *
frust.getViewMatrix();
mSpotlightViewProjMatrixDirty[index] = false;
}
return mSpotlightViewProjMatrix[index];
}
else
return Matrix4::IDENTITY;
}
示例4: initialise
void ThingRenderable::initialise()
{
// Fill array with randomly oriented quads
Vector3 ax, ay, az;
Quaternion q;
things.clear(); orbits.clear();
for(size_t x=0; x<mCount; x++)
{
ax = Vector3(Math::SymmetricRandom(), Math::SymmetricRandom(), Math::SymmetricRandom());
ay = Vector3(Math::SymmetricRandom(), Math::SymmetricRandom(), Math::SymmetricRandom());
az = ax.crossProduct(ay);
ay = az.crossProduct(ax);
ax.normalise(); ay.normalise(); az.normalise();
q.FromAxes(ax, ay, az);
//std::cerr << ax.dotProduct(ay) << " " << ay.dotProduct(az) << " " << az.dotProduct(ax) << std::endl;
things.push_back(q);
ax = Vector3(Math::SymmetricRandom(), Math::SymmetricRandom(), Math::SymmetricRandom());
ay = Vector3(Math::SymmetricRandom(), Math::SymmetricRandom(), Math::SymmetricRandom());
az = ax.crossProduct(ay);
ay = az.crossProduct(ax);
ax.normalise(); ay.normalise(); az.normalise();
q.FromAxes(ax, ay, az);
orbits.push_back(q);
}
// Create buffers
size_t nvertices = mCount*4; // n+1 planes
//size_t elemsize = 2*3; // position, normal
//size_t dsize = elemsize*nvertices;
Ogre::IndexData *idata = new Ogre::IndexData();
Ogre::VertexData *vdata = new Ogre::VertexData();
// Quads
unsigned short *faces = new unsigned short[mCount*6];
for(uint16 x=0; x<uint16(mCount); x++)
{
faces[x*6+0] = x*4+0;
faces[x*6+1] = x*4+1;
faces[x*6+2] = x*4+2;
faces[x*6+3] = x*4+0;
faces[x*6+4] = x*4+2;
faces[x*6+5] = x*4+3;
}
// Setup buffers
vdata->vertexStart = 0;
vdata->vertexCount = nvertices;
VertexDeclaration* decl = vdata->vertexDeclaration;
VertexBufferBinding* bind = vdata->vertexBufferBinding;
size_t offset = 0;
decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
offset += VertexElement::getTypeSize(VET_FLOAT3);
vbuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
offset, nvertices, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
bind->setBinding(0, vbuf);
//vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
mCount*6,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
idata->indexBuffer = ibuf;
idata->indexCount = mCount*6;
idata->indexStart = 0;
ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
// Delete temporary buffers
delete [] faces;
// Now make the render operation
mRenderOp.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
mRenderOp.indexData = idata;
mRenderOp.vertexData = vdata;
mRenderOp.useIndexes = true;
}
示例5: update
//.........这里部分代码省略.........
break;
}
if (!manualOrient) // if !CAM_ExtAng
{
float dtmul = ca->mSpeed == 0 ? 1.0f : ca->mSpeed * time;
if (ca->mType == CAM_Arena)
{
Vector3 Pos(0,0,0), goalPos = ca->mOffset;
Pos = camPosFinal; //read last state (smooth)
Pos += (goalPos - Pos) * dtmul;
mAPitch += (ca->mPitch - mAPitch) * dtmul;
mAYaw += (ca->mYaw - mAYaw) * dtmul;
if (first) {
Pos = goalPos;
mAPitch = ca->mPitch;
mAYaw = ca->mYaw;
}
camPosFinal = Pos;
camRotFinal = Quaternion(Degree(mAYaw),Vector3(0,1,0)) * Quaternion(Degree(mAPitch),Vector3(1,0,0));
manualOrient = true;
}
else
{
if (first) pos = goalPos;
Vector3 addPos,addLook;
addPos = (goalPos - pos).normalisedCopy() * (goalPos - pos).length() * dtmul;
if (addPos.squaredLength() > (goalPos - pos).squaredLength()) addPos = goalPos - pos;
pos += addPos;
camPosFinal = pos + ofs;
goalLook = posGoal + ofs;
if (first) {
mLook = goalLook;
}
addLook = (goalLook - mLook) * dtmul;//Rot;
mLook += addLook;
}
}
//camLookFinal = mLook;
if (!manualOrient) // CAM_Free or CAM_Follow
{
Vector3 zdir = camPosFinal - mLook;
zdir.normalise();
Vector3 xVec = Vector3::UNIT_Y.crossProduct(zdir);
xVec.normalise();
Vector3 yVec = zdir.crossProduct(xVec);
yVec.normalise();
Quaternion q;
q.FromAxes(xVec, yVec, zdir);
camRotFinal = q;
}
// cast ray from car to camera, reduce dist if hit
//-------------------------------------------------------------------------------------------
Vector3 pp = camPosFinal;
if (bounce)
pp += posIn.camOfs * ca->mOfsMul
* gPar.camBncScale * pSet->cam_bnc_mul;
Vector3 p = posGoal;
p.y += 1.f; //up
//Vector3 d = camRotFinal * Vector3::UNIT_Z; d.normalise();
Vector3 d = pp - p;
d.normalise();
if (!first && ca->mType != CAM_Arena)
{
MATHVECTOR<float,3> pos1(p.x,-p.z,p.y), dir(d.x,-d.z,d.y); //dir = dir.Normalize();
COLLISION_CONTACT ct;
float maxLen = (p - pp).length(); //cam near
world->CastRay(pos1, dir, maxLen,chassis, ct, 0,0, true, true, true/*+*/);
//dbgLen = -maxLen;
if (ct.GetColObj())
{
float len = ct.GetDepth(); //dbgLen = len;
len -= 0.2f + ct.GetNormal()[2]; ///par normal up, flat terrain, move closer
if (len < maxLen)
{
Real dist = maxLen - len;
if (dist > mDistReduce)
mDistReduce = dist;
}
}
}
// save result in out posInfo
posOut->camPos = mDistReduce > 0.0001f ? (pp - d * mDistReduce) : pp;
posOut->camRot = camRotFinal;
// smooth, back to normal dist
if (mDistReduce > 0.f)
mDistReduce -= time * 10.f;
}
示例6: setDirection
//-----------------------------------------------------------------------
void Camera::setDirection(const Vector3& vec)
{
// Do nothing if given a zero vector
// (Replaced assert since this could happen with auto tracking camera and
// camera passes through the lookAt point)
if (vec == Vector3::ZERO) return;
// Remember, camera points down -Z of local axes!
// Therefore reverse direction of direction vector before determining local Z
Vector3 zAdjustVec = -vec;
zAdjustVec.normalise();
Quaternion targetWorldOrientation;
if( mYawFixed )
{
Vector3 xVec = mYawFixedAxis.crossProduct( zAdjustVec );
xVec.normalise();
Vector3 yVec = zAdjustVec.crossProduct( xVec );
yVec.normalise();
targetWorldOrientation.FromAxes( xVec, yVec, zAdjustVec );
}
else
{
// Get axes from current quaternion
Vector3 axes[3];
updateView();
mRealOrientation.ToAxes(axes);
Quaternion rotQuat;
if ( (axes[2]+zAdjustVec).squaredLength() < 0.00005f)
{
// Oops, a 180 degree turn (infinite possible rotation axes)
// Default to yaw i.e. use current UP
rotQuat.FromAngleAxis(Radian(Math::PI), axes[1]);
}
else
{
// Derive shortest arc to new direction
rotQuat = axes[2].getRotationTo(zAdjustVec);
}
targetWorldOrientation = rotQuat * mRealOrientation;
}
// transform to parent space
if (mParentNode)
{
mOrientation =
mParentNode->_getDerivedOrientation().Inverse() * targetWorldOrientation;
}
else
{
mOrientation = targetWorldOrientation;
}
// TODO If we have a fixed yaw axis, we mustn't break it by using the
// shortest arc because this will sometimes cause a relative yaw
// which will tip the camera
invalidateView();
}
示例7: getShadowCamera
/// Default shadow camera setup implementation
void DefaultShadowCameraSetup::getShadowCamera (const SceneManager *sm, const Camera *cam,
const Viewport *vp, const Light *light, Camera *texCam, size_t iteration) const
{
Vector3 pos, dir;
// reset custom view / projection matrix in case already set
texCam->setCustomViewMatrix(false);
texCam->setCustomProjectionMatrix(false);
texCam->setNearClipDistance(light->_deriveShadowNearClipDistance(cam));
texCam->setFarClipDistance(light->_deriveShadowFarClipDistance(cam));
// get the shadow frustum's far distance
Real shadowDist = light->getShadowFarDistance();
if (!shadowDist)
{
// need a shadow distance, make one up
shadowDist = cam->getNearClipDistance() * 300;
}
Real shadowOffset = shadowDist * (sm->getShadowDirLightTextureOffset());
// Directional lights
if (light->getType() == Light::LT_DIRECTIONAL)
{
// set up the shadow texture
// Set ortho projection
texCam->setProjectionType(PT_ORTHOGRAPHIC);
// set ortho window so that texture covers far dist
texCam->setOrthoWindow(shadowDist * 2, shadowDist * 2);
// Calculate look at position
// We want to look at a spot shadowOffset away from near plane
// 0.5 is a little too close for angles
Vector3 target = cam->getDerivedPosition() +
(cam->getDerivedDirection() * shadowOffset);
// Calculate direction, which same as directional light direction
dir = - light->getDerivedDirection(); // backwards since point down -z
dir.normalise();
// Calculate position
// We want to be in the -ve direction of the light direction
// far enough to project for the dir light extrusion distance
pos = target + dir * sm->getShadowDirectionalLightExtrusionDistance();
// Round local x/y position based on a world-space texel; this helps to reduce
// jittering caused by the projection moving with the camera
// Viewport is 2 * near clip distance across (90 degree fov)
//~ Real worldTexelSize = (texCam->getNearClipDistance() * 20) / vp->getActualWidth();
//~ pos.x -= fmod(pos.x, worldTexelSize);
//~ pos.y -= fmod(pos.y, worldTexelSize);
//~ pos.z -= fmod(pos.z, worldTexelSize);
Real worldTexelSize = (shadowDist * 2) / texCam->getViewport()->getActualWidth();
//get texCam orientation
Vector3 up = Vector3::UNIT_Y;
// Check it's not coincident with dir
if (Math::Abs(up.dotProduct(dir)) >= 1.0f)
{
// Use camera up
up = Vector3::UNIT_Z;
}
// cross twice to rederive, only direction is unaltered
Vector3 left = dir.crossProduct(up);
left.normalise();
up = dir.crossProduct(left);
up.normalise();
// Derive quaternion from axes
Quaternion q;
q.FromAxes(left, up, dir);
//convert world space camera position into light space
Vector3 lightSpacePos = q.Inverse() * pos;
//snap to nearest texel
lightSpacePos.x -= fmod(lightSpacePos.x, worldTexelSize);
lightSpacePos.y -= fmod(lightSpacePos.y, worldTexelSize);
//convert back to world space
pos = q * lightSpacePos;
}
// Spotlight
else if (light->getType() == Light::LT_SPOTLIGHT)
{
// Set perspective projection
texCam->setProjectionType(PT_PERSPECTIVE);
// set FOV slightly larger than the spotlight range to ensure coverage
Radian fovy = light->getSpotlightOuterAngle()*1.2;
// limit angle
if (fovy.valueDegrees() > 175)
fovy = Degree(175);
texCam->setFOVy(fovy);
// Calculate position, which same as spotlight position
pos = light->getDerivedPosition();
// Calculate direction, which same as spotlight direction
dir = - light->getDerivedDirection(); // backwards since point down -z
//.........这里部分代码省略.........