本文整理汇总了C++中ogre::Vector3类的典型用法代码示例。如果您正苦于以下问题:C++ Vector3类的具体用法?C++ Vector3怎么用?C++ Vector3使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vector3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: destination
//-------------------------------------------------------------------------------------
bool
PlayersManager::moving(zappy::Player *p, int i)
{
OPlayer *OPlayer = this->mOPlayers.at(i);
this->speed = Constants::SquareSize /
((Constants::timeUnit / static_cast<Ogre::Real>(time)));
Ogre::SceneNode *node = OPlayer->getSceneNode();
Ogre::Vector3 &direction = OPlayer->getDirection();
Ogre::Real &distance = OPlayer->getDistance();
Ogre::Real move = this->speed * this->tslf;
Ogre::Vector3 destination(p->getX() * Constants::SquareSize, 0, p->getY() * Constants::SquareSize);
Ogre::AnimationState *anim = OPlayer->getEntity()->
getAnimationState(distance <= 0.0f ? "Idle" : "Walk");
anim->setLoop(true);
anim->setEnabled(true);
if (direction == Ogre::Vector3::ZERO)
{
Ogre::Vector3 src = node->getOrientation() * Ogre::Vector3::UNIT_X;
direction = destination - node->getPosition();
distance = direction.normalise();
if ((1.0f + src.dotProduct(direction)) < 0.0001f)
node->yaw(Ogre::Degree(180));
else
node->rotate(src.getRotationTo(direction));
if (distance > Constants::SquareSize)
distance = 0.0f;
}
else
{
distance -= move;
if (distance <= 0.0f)
{
node->setPosition(destination);
direction = Ogre::Vector3::ZERO;
}
else
node->translate(direction * move);
}
if (OPlayer->stateHasChanged())
OPlayer->detachAnim();
anim->addTime(this->tslf);
return true;
}
示例2: UpdateAI
void CharacterController::UpdateAI(float dt)
{
_CurrentPathAge += dt;
//std::cerr << _CurrentPathIndex << " / " << _CurrentPath.size() << "\n";
if (_CurrentPathIndex + 2 <= _CurrentPath.size())
{
Ogre::Vector3 const & a = _CurrentPath[_CurrentPathIndex];
Ogre::Vector3 const & b = _CurrentPath[_CurrentPathIndex+1];
Ogre::Vector3 const & m = GetPosition();
Ogre::Vector3 const ab = b - a;
Ogre::Vector3 const am = m - a;
Ogre::Vector3 const mb = b - m;
Ogre::Vector3 const mb_unit = mb.normalisedCopy();
float remaining = mb.length();
for(size_t i = _CurrentPathIndex + 1; i + 2 <= _CurrentPath.size(); ++i)
{
remaining += _CurrentPath[i].distance(_CurrentPath[i+1]);
}
//std::cerr << "Remaining distance: " << remaining << " m\n";
float lambda = am.dotProduct(ab) / ab.squaredLength();
//const float tau = 0.1;
SetVelocity(_CurrentVelocity * mb_unit);
if (lambda > 1) _CurrentPathIndex++;
/*if (_CurrentPathIndex + 1 == _CurrentPath.size())
SetVelocity(Ogre::Vector3(0.));*/
}
}
示例3: IsCameraInside
bool DeferredLight::IsCameraInside(Ogre::Camera* camera)
{
switch (mParentLight->getType())
{
case Ogre::Light::LT_DIRECTIONAL:
return false;
case Ogre::Light::LT_POINT:
{
Ogre::Real distanceFromLight =
camera->getDerivedPosition().distance(mParentLight->getDerivedPosition());
// Small epsilon fix to account for the fact that we aren't a true sphere.
return distanceFromLight <= mRadius + camera->getNearClipDistance() + 0.1f;
}
case Ogre::Light::LT_SPOTLIGHT:
{
Ogre::Vector3 lightPos = mParentLight->getDerivedPosition();
Ogre::Vector3 lightDir = mParentLight->getDerivedDirection();
Ogre::Radian attAngle = mParentLight->getSpotlightOuterAngle();
// Extend the analytic cone's radius by the near clip range by moving its
// tip accordingly.
// Some trigonometry needed here.
Ogre::Vector3 clipRangeFix =
-lightDir * (camera->getNearClipDistance() / Ogre::Math::Tan(attAngle / 2));
lightPos += clipRangeFix;
Ogre::Vector3 lightToCamDir = camera->getDerivedPosition() - lightPos;
Ogre::Real distanceFromLight = lightToCamDir.normalise();
Ogre::Real cosAngle = lightToCamDir.dotProduct(lightDir);
Ogre::Radian angle = Ogre::Math::ACos(cosAngle);
// Check whether we will see the cone from our current POV.
return (distanceFromLight <=
(mParentLight->getAttenuationRange() / cosAngle + clipRangeFix.length())) &&
(angle <= attAngle);
}
default:
return false;
}
}
示例4: mouseMoveEvent
/** The user moved the mouse, if tracking process it
@param e The event data
*/
void QtSpacescapeWidget::mouseMoveEvent(QMouseEvent *e) {
if (mMousePressed) {
QPoint curPos = e->pos();
double w = width();
double h = height();
double curX = (curPos.x() * 2. - w) / w;
double curY = (h - curPos.y() * 2.) / h;
double x0 = (mMousePressPos.x() * 2. - w) / w;
double y0 = (h - mMousePressPos.y() * 2.) / h;
Ogre::Vector3 v1(x0, y0, 0);
Ogre::Vector3 v2(curX, curY, 0);
double radiusSqr = mRADIUS * mRADIUS;
double cutoff = radiusSqr * 0.5;
double Rho = v1[0] * v1[0] + v1[1] * v1[1];
v1[2] = (Rho < cutoff) ? sqrt(radiusSqr - Rho) : (cutoff / sqrt(Rho));
Rho = v2[0] * v2[0] + v2[1] * v2[1];
v2[2] = (Rho < cutoff) ? sqrt(radiusSqr - Rho) : (cutoff / sqrt(Rho));
// v_cross is the normal of rotating plane
Ogre::Vector3 cross = v2.crossProduct(v1);
cross.normalise();
// compute the angle
v1.normalise();
v2.normalise();
double cosAngle = v1.dotProduct(v2);
if (cosAngle < -1.0)
cosAngle = -1.0;
else if(cosAngle > 1.0)
cosAngle = 1.0;
double angle = acos(cosAngle);
mCameraNode->rotate(cross, Ogre::Radian(angle));
mMousePressPos = curPos;
mLastCamOrientation = mCameraNode->getOrientation();
update();
}
}
示例5: Intersects
/*
* \brief Does this bounding box intersect with another
*/
const bool CSpaghettiBoundsSphere::Intersects(
CSpaghettiBounds *other, //!< The bounding box to test against
std::vector<CCollision> &collision
)
{
if (other->GetType() == BoundsType::Box)
{
// Sphere on box
const bool result = other->Intersects(this, collision);
if (!result)
return false;
return true;
}
else if (other->GetType() == BoundsType::Sphere)
{
// Sphere on sphere
CSpaghettiBoundsSphere *const otherSphere = static_cast<CSpaghettiBoundsSphere*>(other);
const float distance = (m_position - otherSphere->GetPosition()).length();
const float radius = GetRadius() + otherSphere->GetRadius();
if (distance <= radius)
{
Ogre::Vector3 collisionNormal = otherSphere->GetPosition() - GetPosition();
collisionNormal.normalise();
Ogre::Vector3 collisionPoint =collisionNormal * GetRadius();
CCollision newCollision;
newCollision.bodyOne = GetBody();
newCollision.bodyTwo = otherSphere->GetBody();
newCollision.collisionNormal = collisionNormal;
newCollision.collisionPoint = GetPosition() + collisionPoint;
newCollision.penetration = radius - distance;
collision.push_back(newCollision);
return true;
}
return false;
}
return false;
}
示例6: operateBulletEventSystem
void BulletHelixOperator::operateBulletEventSystem(Real timeElapsed)
{
BulletEventSystem::BulletSystemVecotor::iterator it = m_parent->getActiveBulletSystem().begin();
while(it != m_parent->getActiveBulletSystem().end())
{
BulletSystem* pBulletSystem = *it;
if(pBulletSystem && pBulletSystem->getIsCreated())
{
// 步骤:[6/2/2010 陈军龙]
// 1.计算朝向
// 2.将时间映射到曲线函数Sin (映射公式: (2 * PI) / (1 / Frequency) = x / Age )
// 3.计算绕螺旋的旋转轴的旋转偏移量
// (绕任意轴旋转公式:v' = (v - (v 。n) 。n) * cosx + (v * n) * sinx + (v 。n)。n
// 其中的 。代表点乘 * 代表叉乘,v是要旋转的向量,n是旋转轴,x是旋转的角度)
// 4.根据到目标的百分比设置振幅,更新子弹位置
static Ogre::Vector3 startpos = pBulletSystem->getCurrentPosition();
Ogre::Vector3 direction = pBulletSystem->getTargetPosition() - startpos;
direction.normalise();
Real fCumulateTime = pBulletSystem->getAge();
Real sinvalue = Ogre::Math::Sin(fCumulateTime * Ogre::Math::TWO_PI * m_frequency);
Real cosvalue = Ogre::Math::Cos(fCumulateTime * Ogre::Math::TWO_PI * m_frequency);
Ogre::Vector3 absoffset, vdelta;
vdelta = Ogre::Vector3::UNIT_Y;//此次设置为Y轴,也可以设置为其它
// v' = (v - (v 。n) 。n) * cosx + (v * n) * sinx + (v 。n)。n
absoffset = (vdelta - (vdelta.dotProduct(direction)) * direction) * cosvalue
+ (vdelta.crossProduct(direction)) * sinvalue
+ (vdelta.dotProduct(direction)) *direction;
Real oridistance = startpos.distance(pBulletSystem->getTargetPosition());
Real curdistance = pBulletSystem->getCurrentPosition().distance(pBulletSystem->getTargetPosition());
Real percent = Ogre::Math::RealEqual(oridistance, 0) ? 1 : curdistance/oridistance;
TransformInfo info;
info = pBulletSystem->getTransformInfo();
Ogre::Vector3 vBulletPosition = info.mPosition;
vBulletPosition += (m_amplitude * absoffset * percent);
info.mPosition = vBulletPosition;
pBulletSystem->setTransformInfo(info);
pBulletSystem->setPosition(info.mPosition);
}
it ++;
}
}
示例7: update
void Fighter::update(Ogre::Real deltaTime)
{
Ogre::Vector3 curPos = mNode->getPosition();
Ogre::Vector3 direction = curPos - mCursorPos;
Ogre::Vector3 src = mNode->getOrientation() * -Ogre::Vector3::UNIT_Z;
src.y = 0;
direction.y = 0;
src.normalise();
direction.normalise();
mNode->setPosition(mNode->getPosition()+mCurrentMoveVector);
Ogre::Quaternion quat = src.getRotationTo(direction);
mNode->rotate(quat);
/*
* Update all shots
*/
for(std::vector<Shot*>::iterator it = mShots.begin(); it != mShots.end();)
{
(*it)->update(deltaTime);
/**
@see http://www.ogre3d.org/forums/viewtopic.php?t=2519
http://de.wikipedia.org/wiki/Projektionsmatrix
*/
Ogre::Vector3 hcpPos = (*mCameraPtr)->getProjectionMatrix()*(*mCameraPtr)->getViewMatrix()*mNode->getPosition();
if ((hcpPos.x < -1.0f) ||
(hcpPos.x > 1.0f) ||
(hcpPos.y < -1.0f) ||
(hcpPos.y > 1.0f))
{
(*it)->die();
delete (*it);
it = mShots.erase(it);
}
else
{
++it;
}
}
//Update positon for enemies
mCurrentPosition = mNode->getPosition();
}
示例8:
void
CharacterController::_doOgreOpcodeCollision(CollisionPacket& colData,
float sweepOffset)
{
Ogre::Vector3 pos_R3 = colData.basePoint * colData.eRadius;
Ogre::Vector3 vel_R3 = colData.velocity * colData.eRadius;
OgreOpcode::CollisionPair** reports;
// TODO: sweptSphereCheck does not support ellipsoids,
// so we must use only one dimension!!!
Ogre::Real radius = colData.eRadius.x;
// Add a little offset to velocity so that we don't get too close.
Ogre::Vector3 offset = vel_R3;
offset.normalise();
offset *= sweepOffset;
OgreOpcode::Details::CollisionClass collClass =
OgreOpcode::COLLTYPE_ALWAYS_EXACT;
int count =
OgreOpcode::CollisionManager::getSingletonPtr()->getDefaultContext()->sweptSphereCheck(
pos_R3, vel_R3 + offset, radius, collClass, reports);
if (count)
{
// search for closest distance collision
int closest = 0;
Ogre::Real d = reports[0]->distance;
for(int i = 1; i < count; i++){
if (reports[i]->distance < d)
{
d = reports[i]->distance;
closest = i;
}
}
colData.foundCollision = true;
colData.nearestDistance = reports[closest]->distance;
colData.intersectionPoint = reports[closest]->contact / colData.eRadius;
mContactName = reports[closest]->other_object->getName();
}
}
开发者ID:PlumInTheLateAfternoonShade,项目名称:ember_gsoc_2013_test,代码行数:45,代码来源:OgreOpcodeCharacterController.cpp
示例9: wanderMovement
void Tank::wanderMovement(const float & deltaTime)
{
if(wanderPathCreated)
{
if (mWanderDirection == Ogre::Vector3::ZERO)
{
wanderNextLocation();
}
else
{
Ogre::Real move = mMoveSpd * (deltaTime);
mWanderDistance -= move;
Ogre::Vector3 src = mTankBodyNode->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_X;
//http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Quaternion+and+Rotation+Primer
//this is used for rotation of the tank
if ((1.0 + src.dotProduct(mWanderDirection)) < 0.0001)
{
mTankBodyNode->yaw(Ogre::Degree(180));
}
else
{
mWanderDirection.y = 0;
Ogre::Quaternion quat = src.getRotationTo(mWanderDirection);
Ogre::Quaternion mOrientSrc = mTankBodyNode->getOrientation();
Ogre::Quaternion mOrientDest = quat * mOrientSrc;
Ogre::Quaternion delta = Ogre::Quaternion::nlerp(deltaTime * 2.0, mOrientSrc, mOrientDest, true);
mTankBodyNode->setOrientation(delta);
}
//for movement
if (mWanderDistance <= 0)
{
mTankBodyNode->setPosition(mWanderDestination);
mWanderDirection = Ogre::Vector3::ZERO;
}
else
{
mTankBodyNode->translate(move * mWanderDirection);
}
}
}
}
示例10: mSceneManager
MapCameraLightning::MapCameraLightning(Ogre::SceneManager& sceneManager)
: mSceneManager(sceneManager)
{
mLight = sceneManager.createLight("MapFixedSunLight");
mLight->setType(Ogre::Light::LT_DIRECTIONAL);
mLight->setPosition(Ogre::Vector3(-500,300,-350));
Ogre::Vector3 dir = -mLight->getPosition();
dir.normalise();
mLight->setDirection(dir);
mLight->setDiffuseColour(Ogre::ColourValue(0.8, 0.8, 0.6)); //yellow
//mSun->setSpecularColour(1, 1, 0.7); //yellow
mLight->setCastShadows(false);
mLight->setAttenuation(1000000, 1, 0, 0);
mLight->setVisible(false);
}
示例11: SolveForTargetXInv
void IKChain::SolveForTargetXInv(Ogre::Vector3 Target, double Pitch, double Yaw, double Roll)
{
double dRate = Target.distance(GetEffectorPosition()) / mChainLength;
for ( int i = 0; i < 5; i++ )
{
mIKRoot->GetEffector()->DoSolverIterationXInv(Target, dRate, Pitch, Yaw, Roll);
dRate = dRate / 1.5;
}
}
示例12: SolveForTargetYInv
void IKChain::SolveForTargetYInv(Ogre::Vector3 Target)
{
double dRate = Target.distance(GetEffectorPosition()) / mChainLength;
for ( int i = 0; i < 5; i++ )
{
mIKRoot->GetEffector()->DoSolverIterationYInv(Target, dRate);
dRate = dRate / 1.5;
}
}
示例13: _behaviorIdle
void NPCCharacter::_behaviorIdle()
{
stop();
//still want to point the character in the direction last traveled.
Ogre::Vector3 vel = getVelocity();
float speed = vel.length();
Ogre::Vector3 src = _node->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Z;
src.y = 0;
vel.y = 0;
vel.normalise();
_node->rotate(src.getRotationTo(vel));
_isBhvFinished = true;
//transition to idle animation
_animHandler.blend("Idle",AnimationBlender::BlendWhileAnimating,.2f,true);
}
示例14: cos
Ogre::Vector3 SuperEllipsoid::CalculateNormal(float phi, float beta, float n1, float n2,
float scale_x, float scale_y, float scale_z)
{
Ogre::Vector3 normal;
float cos_phi = cos(phi);
float cos_beta = cos(beta);
float sin_phi = sin(phi);
float sin_beta = sin(beta);
normal.x = SIGN(cos_phi) * pow(fabs(cos_phi), 2-n1) * SIGN(sin_beta) * pow(fabs(sin_beta), 2-n2) / scale_x;
normal.y = SIGN(sin_phi) * pow(fabs(sin_phi), 2-n1) / scale_y;
normal.z = SIGN(cos_phi) * pow(fabs(cos_phi), 2-n1) * SIGN(cos_beta) * pow(fabs(cos_beta), 2-n2) / scale_z;
normal.normalise();
return normal;
}
示例15: collidesWithObject
Ogre::Entity* CollisionTools::collidesWithObject(const Ogre::Vector3& fromPoint, const Ogre::Vector3& toPoint, const float collisionRadius, const Ogre::uint32 queryMask)
{
Ogre::Vector3 normal = toPoint - fromPoint;
float distToDest = normal.normalise();
Ogre::Vector3 myResult(0, 0, 0);
Ogre::Entity* myObject = NULL;
float distToColl = 0.0f;
if (raycastFromPoint(fromPoint, normal, myResult, myObject, distToColl, queryMask))
{
distToColl -= collisionRadius;
if (distToColl <= distToDest)
return myObject;
}
return NULL;
}