本文整理汇总了C++中ogre::Vector3::squaredLength方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector3::squaredLength方法的具体用法?C++ Vector3::squaredLength怎么用?C++ Vector3::squaredLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Vector3
的用法示例。
在下文中一共展示了Vector3::squaredLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addRandomStars
void PointStarfield::addRandomStars (int count)
{
for (int i = 0; i < count; ++i) {
// Generate a vector inside a sphere
Ogre::Vector3 pos;
do {
pos.x = randReal(-1, 1);
pos.y = randReal(-1, 1);
pos.z = randReal(-1, 1);
} while (pos.squaredLength () >= 1);
// Convert to rasc/decl angles.
LongReal rasc, decl, dist;
Astronomy::convertRectangularToSpherical(
pos.x, pos.y, pos.z,
rasc, decl, dist);
Star s;
s.RightAscension = Ogre::Degree (rasc);
s.Declination = Ogre::Degree (decl);
// This distribution is wrong.
s.Magnitude = 6 * pos.squaredLength () + 1.5;
mStars.push_back(s);
}
notifyStarVectorChanged ();
}
示例2: updateBoundingBoxAndSphereFromBillboards
void GPUBillboardSet::updateBoundingBoxAndSphereFromBillboards(const std::vector<PhotoSynth::Vertex>& vertices)
{
Ogre::AxisAlignedBox box = calculateBillboardsBoundingBox(vertices);
setBoundingBox(box);
Ogre::Vector3 vmax = box.getMaximum();
Ogre::Vector3 vmin = box.getMinimum();
Ogre::Real sqLen = std::max(vmax.squaredLength(), vmin.squaredLength());
mBBRadius = Ogre::Math::Sqrt(sqLen);
}
示例3: getParentNode
void
IntersectGrid::fillPosition( const PositionArray &posArray )
{
size_t posCount = posArray.size();
if ( posCount <= 0 )
return;
// if ( posCount > mCurrentVertexCount )
// {
// 如果缓冲区不够用了,就扩容一倍
// mCurrentVertexCount = posCount<<1;
// 如果不每帧创建缓冲区的话,由于lock时用的是discard,所以上次缓冲区中的内容还是会被显示
mCurrentVertexCount = posCount;
_createBuffer();
// }
Ogre::Vector3 vmax = posArray[posCount-1];
Ogre::Vector3 vmin = posArray[0];
vmin.y -= 100.0f;
vmax.y += 100.0f;
Real sqLen = std::max(vmax.squaredLength(), vmin.squaredLength());
mRadius = Ogre::Math::Sqrt(sqLen);//
mBox.setExtents(vmin,vmax);//
getParentNode()->needUpdate();//
float *vertexPos = static_cast<float*>(vbuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
for (size_t i = 0; i < posCount; ++i)
{
*vertexPos++ = posArray[i].x;
*vertexPos++ = posArray[i].y+1;
*vertexPos++ = posArray[i].z;
Ogre::RGBA *pCol;
pCol = static_cast<Ogre::RGBA*>(static_cast<void*>(vertexPos));
// 用diffuse来做为alpha来源
Ogre::Root::getSingleton().convertColourValue(mGridsColour, pCol++ ) ;
vertexPos = static_cast<float*>(static_cast<void*>(pCol));
}
vbuf->unlock();
}
示例4: 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.));*/
}
}
示例5: EnergyExplosion
void GameState::EnergyExplosion(Ogre::Vector3 location,Ogre::Real size, double EnergyAdjustment,const std::string& Material)
{
float sqSize = size*size;
auto it = _actors.begin();
while(it != _actors.end())
{
Ogre::Vector3 diff = (*it)->GetLocation() - location;
if(diff.squaredLength() <= sqSize)
(*it)->AdjustEnergy(EnergyAdjustment);
++it;
}
if(Material != "")
{
_billboardManager->AddBillboard(
location,
Material,
Ogre::Vector2(1.0f,1.0f)*size*EnergyExplosionSizeFactor,
Ogre::ColourValue(1.0f,1.0f,1.0f,1.0f),
EnergyExplosionDuration,
BillboardManager::OPTIONS_FADE_OUT | BillboardManager::OPTIONS_ALIGNED | BillboardManager::OPTIONS_SCALE_UP,
Ogre::Vector2(1.0f,1.0f)*size*EnergyExplosionSizeFactor);
}
}
示例6: collisionAABB
Object* ObjectManager::collisionAABB(const Ogre::Vector3& fromPoint, const Ogre::Vector3& toPoint, int queryMask)
{
Ogre::Vector3 direction = toPoint - fromPoint;
Ogre::Ray ray(fromPoint, direction);
mRayQuery->setRay(ray);
mRayQuery->setQueryMask(queryMask);
// The rays are sorted by the distance query set, [very important]
mRayQuery->setSortByDistance(true);
Ogre::RaySceneQueryResult& result = mRayQuery->execute();
Ogre::RaySceneQueryResult::iterator itr = result.begin();
// Just get the nearest object
if (itr != result.end() && itr->movable)
{
Ogre::MovableObject *object = itr->movable;
Ogre::Vector3 pos = object->getParentSceneNode()->getPosition();
// If the current starting point of an object in the distance is less than a predetermined range
// then return this obj
// Avoid using the square root operation squaredLength
if ((pos - fromPoint).squaredLength() <= direction.squaredLength())
return getObject(itr->movable->getName());
}
return NULL;
}
示例7: getSquaredViewDepth
Ogre::Real DeferredLight::getSquaredViewDepth(const Ogre::Camera* camera) const {
if (ignoreWorld) {
return 0.0;
} else {
Ogre::Vector3 dist = camera->getDerivedPosition() - getParentSceneNode()->_getDerivedPosition();
return dist.squaredLength();
}
}
示例8: findCell
Cell* NavigationMesh::findCell(const Ogre::Vector3& pos) {
Ogre::Vector3 v;
Ogre::Vector3 minDistance = Ogre::Vector3(500.0, 500.0, 500.0);
Cell* closestCell = 0;
for (Cells::iterator i = _cells.begin(); i != _cells.end(); ++i) {
if ((*i)->containsPoint(pos)) {
return *i;
}
v = (*i)->getCenter() - pos;
if (v.squaredLength() < minDistance.squaredLength()) {
minDistance = v;
closestCell = (*i);
}
}
return closestCell;
}
示例9: frameRenderingQueued
bool CEditor::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
// manually call sample callback to ensure correct order
mGuiMgr->frameRenderingQueued(evt);
if ( mHaveLevel )
{
// build our acceleration vector based on keyboard input composite
Ogre::Vector3 accel = Ogre::Vector3::ZERO;
if (mGoingForward)
accel += mCamera->getDirection();
if (mGoingBack)
accel -= mCamera->getDirection();
if (mGoingRight)
accel += mCamera->getRight();
if (mGoingLeft)
accel -= mCamera->getRight();
if (mGoingUp)
accel += mCamera->getUp();
if (mGoingDown)
accel -= mCamera->getUp();
// if accelerating, try to reach top speed in a certain time
Ogre::Real topSpeed = mTopSpeed;
if (accel.squaredLength() != 0)
{
accel.normalise();
mVelocity += accel * topSpeed * evt.timeSinceLastFrame * 10;
}
// if not accelerating, try to stop in a certain time
else mVelocity -= mVelocity * evt.timeSinceLastFrame * 10;
Ogre::Real tooSmall = std::numeric_limits<Ogre::Real>::epsilon();
// keep camera velocity below top speed and above epsilon
if (mVelocity.squaredLength() > topSpeed * topSpeed)
{
mVelocity.normalise();
mVelocity *= topSpeed;
}
else if (mVelocity.squaredLength() < tooSmall * tooSmall)
mVelocity = Ogre::Vector3::ZERO;
if (mVelocity != Ogre::Vector3::ZERO)
{
mCamera->move(mVelocity * evt.timeSinceLastFrame);
}
else
{
mpEntityMgr->UpdatePageManager();
}
}
return true;
}
示例10: _affect
//-----------------------------------------------------------------------
inline void GravityAffector::_affect(ParticleTechnique* particleTechnique, Particle* particle, Ogre::Real timeElapsed)
{
/** Applying Newton's law of universal gravitation. */
Ogre::Vector3 distance = mDerivedPosition - particle->position;
Ogre::Real length = distance.squaredLength();
if (length > 0)
{
Ogre::Real force = (mGravity * particle->mass * mass) / length;
particle->direction += force * distance * timeElapsed * _calculateAffectSpecialisationFactor(particle);
}
}
示例11: frameRenderingQueued
bool CameraMan::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
CameraStyle mStyle = getCameraStyle();
if (mStyle == CS_FREELOOK)
{
// build our acceleration vector based on keyboard input composite
Ogre::Vector3 accel = Ogre::Vector3::ZERO;
if (mGoingForward)
accel += mCamera->getDirection();
if (mGoingBack)
accel -= mCamera->getDirection();
if (mGoingRight)
accel += mCamera->getRight();
if (mGoingLeft)
accel -= mCamera->getRight();
if (mGoingUp)
accel += mCamera->getUp();
if (mGoingDown)
accel -= mCamera->getUp();
// if accelerating, try to reach top speed in a certain time
Ogre::Real topSpeed = mFastMove ? mTopSpeed * mFastFactor : mTopSpeed;
if (accel.squaredLength() != 0)
{
accel.normalise();
mVelocity += accel * topSpeed * evt.timeSinceLastFrame * 10;
}
// if not accelerating, try to stop in a certain time
else
{
Ogre::Vector3 dir = mVelocity;
mVelocity -= mVelocity * evt.timeSinceLastFrame * 10;
if (mVelocity.dotProduct(dir) < 0.)
mVelocity = Ogre::Vector3::ZERO;
}
Ogre::Real tooSmall = std::numeric_limits<Ogre::Real>::epsilon();
// keep camera velocity below top speed and above epsilon
if (mVelocity.squaredLength() > topSpeed * topSpeed)
{
mVelocity.normalise();
mVelocity *= topSpeed;
}
else if (mVelocity.squaredLength() < tooSmall * tooSmall)
mVelocity = Ogre::Vector3::ZERO;
if (mVelocity != Ogre::Vector3::ZERO)
mCamera->move(mVelocity * evt.timeSinceLastFrame);
}
return true;
}
示例12: distance
/*
distance(target_positon+t*target_speed) = t*interceptor_speed
formal solver gives :
delta =
(-target_positon.y^2-target_positon.x^2)*target_speed.z^2
+(2*target_positon.y*target_positon.z*target_speed.y+2*target_positon.x*target_positon.z*target_speed.x)*target_speed.z
+(-target_positon.z^2-target_positon.x^2)*target_speed.y^2
+2*target_positon.x*target_positon.y*target_speed.x*target_speed.y
+(-target_positon.z^2-target_positon.y^2)*target_speed.x^2
+interceptor_speed^2*target_positon.z^2
+interceptor_speed^2*target_positon.y^2
+interceptor_speed^2*target_positon.x^2
if delta > 0
t = (sqrt(delta)
-target_positon.z*target_speed.z-target_positon.y*target_speed.y-target_positon.x*target_speed.x)
/(target_speed.z^2+target_speed.y^2+target_speed.x^2-laser_speed^2)
special case for delta=0 when equation becomes linear
*/
std::pair<bool,float> calculateInterceptionTime(
const Ogre::Vector3& target_position,
const Ogre::Vector3& target_speed,
const float& interceptor_speed)
{
// result ;
float time = 0 ;
if (target_speed.length() != 0)
{
float delta =
(-pow(target_position.y,2)-pow(target_position.x,2))*pow(target_speed.z,2)
+(2*target_position.y*target_position.z*target_speed.y+2*target_position.x*target_position.z*target_speed.x)*target_speed.z
+(-pow(target_position.z,2)-pow(target_position.x,2))*pow(target_speed.y,2)
+2*target_position.x*target_position.y*target_speed.x*target_speed.y
+(-pow(target_position.z,2)-pow(target_position.y,2))*pow(target_speed.x,2)
+pow(interceptor_speed,2)*pow(target_position.z,2)
+pow(interceptor_speed,2)*pow(target_position.y,2)
+pow(interceptor_speed,2)*pow(target_position.x,2) ;
float divisor = target_speed.squaredLength()-pow(interceptor_speed,2) ;
if (delta > 0 && fabs(divisor) > 1e-10)
{
float b = -target_position.z*target_speed.z-target_position.y*target_speed.y-target_position.x*target_speed.x ;
time = (sqrt(delta)+b)/divisor ;
if (time < 0)
time = (-sqrt(delta)+b)/divisor ;
}
else
{
/// no real solution : target is unreachable by interceptor
return std::pair<bool,float>(false,0) ;
}
}
else
{
time = target_position.length()/interceptor_speed ;
}
return std::pair<bool,float>(true,time) ;
}
示例13: Update
void BubbleController::Update(float dt){
if (m_apply_impulse){
Ogre::Vector3 impulse = (m_impulse_direction * m_velocity) * dt;
m_messenger->Notify(MSG_RIGIDBODY_APPLY_IMPULSE, &impulse, "body");
m_apply_impulse = false;
if (m_owner->GetType() == GAME_OBJECT_PINK_BUBBLE){
m_distance -= impulse.squaredLength();
}
}
if (m_owner->GetType() == GAME_OBJECT_PINK_BUBBLE){
float percent = m_max_distance * 0.5f;
if (m_distance < percent){
Ogre::SceneNode* node = NULL;
m_messenger->Notify(MSG_NODE_GET_NODE, &node);
if (node){
float scale_inc = (m_scale_increment * (percent / m_distance)) * dt;
if (m_scale_state == 0) { // increase size
Ogre::Vector3 scale = node->getScale() + scale_inc;
node->setScale(scale);
if (node->getScale().y > m_max_scale){
node->setScale(Ogre::Vector3(m_max_scale));
m_scale_state = 1;
}
}
else if (m_scale_state == 1){ // decrease size
Ogre::Vector3 scale = node->getScale() - scale_inc;
node->setScale(scale);
if (node->getScale().y < m_original_scale){
node->setScale(Ogre::Vector3(m_original_scale));
m_scale_state = 0;
}
}
}
}
if (m_distance <= 0.0f){
SoundData2D pop_sound = m_owner->GetGameObjectManager()->GetSoundManager()->Create2DData("Bubble_Burst", false, false, false, false, 1.0, 1.0);
m_owner->GetGameObjectManager()->GetGameObject("Player")->GetComponentMessenger()->Notify(MSG_SFX2D_PLAY, &pop_sound);
m_owner->RemoveGameObject(m_owner);
}
}
}
示例14: intersect
//-----------------------------------------------------------------------
bool Plane::intersect(const Plane& other, Line& outputLine) const
{
//TODO : handle the case where the plane is perpendicular to T
Ogre::Vector3 point1;
Ogre::Vector3 direction = normal.crossProduct(other.normal);
if (direction.squaredLength() < 1e-08)
return false;
Ogre::Real denom = 1./(normal.x*other.normal.y-other.normal.x*normal.y);
{
Ogre::Real d1 = d;
Ogre::Real d2 = other.d;
point1.x = (normal.y*d2-other.normal.y*d1)*denom;
point1.y = (other.normal.x*d1-normal.x*d2)*denom;
point1.z = 0;
}
outputLine = Line(point1, direction);
return true;
}
示例15:
BoundingSphere::BoundingSphere(const BoundingSphere &one,
const BoundingSphere &two)
{
Ogre::Vector3 centerOffset = two.center - one.center;
real distance = centerOffset.squaredLength();
real radiusDiff = two.radius - one.radius;
// Check if the larger sphere encloses the small one
if (radiusDiff*radiusDiff >= distance)
{
if (one.radius > two.radius)
{
center = one.center;
radius = one.radius;
}
else
{
center = two.center;
radius = two.radius;
}
}
// Otherwise we need to work with partially
// overlapping spheres
else
{
distance = Ogre::Math::Sqrt(distance);
radius = (distance + one.radius + two.radius) * ((real)0.5);
// The new centre is based on one's centre, moved towards
// two's centre by an ammount proportional to the spheres'
// radii.
center = one.center;
if (distance > 0)
{
center += centerOffset * ((radius - one.radius)/distance);
}
}
}