本文整理汇总了C++中ogre::Vector3::normalisedCopy方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector3::normalisedCopy方法的具体用法?C++ Vector3::normalisedCopy怎么用?C++ Vector3::normalisedCopy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Vector3
的用法示例。
在下文中一共展示了Vector3::normalisedCopy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PerformSphereSphereCollisionTest
bool PhysicsEngine::PerformSphereSphereCollisionTest(const Ogre::FrameEvent &fe, PhysicsEntity *sphere1, PhysicsEntity *sphere2)
{
float overlapMagnitude = (sphere1->GetRadius() + sphere2->GetRadius()) - sphere1->getPosition().distance(sphere2->getPosition());
if (overlapMagnitude >= 0.0f)
{
Ogre::Vector3 d = sphere2->getPosition() - sphere1->getPosition();
Ogre::Vector3 relativeVelocity = d * (d.dotProduct(sphere1->GetVelocity() - sphere2->GetVelocity()) / d.squaredLength());
Ogre::Vector3 impulse1 = (((sphere2->GetRestitution() + 1.0f) * relativeVelocity) /
((1 / sphere1->GetMass()) + (1 / sphere2->GetMass())));
Ogre::Vector3 impulse2 = -(((sphere1->GetRestitution() + 1.0f) * relativeVelocity) /
((1 / sphere1->GetMass()) + (1 / sphere2->GetMass())));
//Ogre::Vector3 currentImpulse1 = d * (d.dotProduct(sphere1->GetAppliedForce()) / d.squaredLength());
//Ogre::Vector3 currentImpulse2 = -d * (d.dotProduct(sphere2->GetAppliedForce()) / d.squaredLength());
if (sphere1->GetBodyType() == ENTITY_BODY_SPHERE && sphere2->GetBodyType() == ENTITY_BODY_SPHERE)
{
sphere1->translate(-d.normalisedCopy() * (overlapMagnitude / 2.0f));
sphere2->translate(d.normalisedCopy() * (overlapMagnitude / 2.0f));
sphere2->ApplyForce(impulse1);// + currentImpulse1);
sphere1->ApplyForce(impulse2);// + currentImpulse2);
}
sphere1->Collide(fe, sphere2);
sphere2->Collide(fe, sphere1);
return true;
}
return false;
}
示例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: orient
void AnimalThirdPersonControler::orient(int i_xRel, int i_yRel, double i_timeSinceLastFrame)
{
if (!(m_pAnimal != nullptr && m_pCamera != nullptr))
return;
Ogre::Vector3 camPos = m_pCamera->getPosition();
Ogre::Radian angleX(i_xRel * -m_camAngularSpeed);
Ogre::Radian angleY(i_yRel * -m_camAngularSpeed);
Ogre::Vector3 avatarToCamera = m_pCamera->getPosition() - m_pAnimal->m_pNode->getPosition();
// restore lenght
if (avatarToCamera.length() != m_camDistance)
avatarToCamera = avatarToCamera.normalisedCopy() * m_camDistance;
// Do not go to the poles
Ogre::Radian latitude = m_pAnimal->m_pNode->getOrientation().zAxis().angleBetween(avatarToCamera);
if (latitude < Ogre::Radian(Ogre::Math::DegreesToRadians(10.f)) && angleY < Ogre::Radian(0.f))
angleY = Ogre::Radian(0.f);
else if (latitude > Ogre::Radian(Ogre::Math::DegreesToRadians(170.f)) && angleY > Ogre::Radian(0.f))
angleY = Ogre::Radian(0.f);
Ogre::Quaternion orient = Ogre::Quaternion(angleY, m_pCamera->getOrientation().xAxis()) * Ogre::Quaternion(angleX, m_pCamera->getOrientation().yAxis());
Ogre::Vector3 newAvatarToCamera = orient * avatarToCamera;
// Move camera closer if collides with terrain
m_collideCamWithTerrain(newAvatarToCamera);
}
示例4: end
//------------------------------------------------------------------------------------------------
RayDebugShape::RayDebugShape(const Ogre::Vector3& start,
const Ogre::Vector3& direction,
const Ogre::Real length) {
const Ogre::Vector3 end(start + (direction.normalisedCopy() * length));
addLine(start, end);
draw();
}
示例5: setDefinition
//------------------------------------------------------------------------------------------------
void RayDebugShape::setDefinition(const Ogre::Vector3& start,
const Ogre::Vector3& direction,
const Ogre::Real length) {
clear();
const Ogre::Vector3 end(start + (direction.normalisedCopy() * length));
addLine(start, end);
draw();
}
示例6: _setDirection
//-----------------------------------------------------------------------------------------
bool CLightEditor::_setDirection(OgitorsPropertyBase* property, const Ogre::Vector3& value)
{
if(value == Ogre::Vector3::ZERO)
mDirection->init(mDirection->getOld());
if(mHandle)
{
mHandle->setDirection(value.normalisedCopy());
_calculateOrientation();
}
return true;
}
示例7: setSunDirection
void SkyDome::setSunDirection (const Ogre::Vector3& sunDir) {
float elevation = sunDir.dotProduct (Ogre::Vector3::UNIT_Y);
elevation = elevation * 0.5 + 0.5;
Ogre::Pass* pass = mMaterial->getBestTechnique()->getPass(0);
if (mShadersEnabled) {
mParams.sunDirection.set(mParams.vpParams, sunDir.normalisedCopy());
mParams.offset.set(mParams.fpParams, elevation);
} else {
Ogre::TextureUnitState* gradientsTus = pass->getTextureUnitState(0);
gradientsTus->setTextureUScroll (elevation);
}
}
示例8: SetLineStartEnd
void LuaScriptUtilities::SetLineStartEnd(
Ogre::SceneNode* line,
const Ogre::Vector3& start,
const Ogre::Vector3& end)
{
Ogre::Vector3 lineVector = end - start;
Ogre::Quaternion lineRotation =
Ogre::Vector3::UNIT_Z.getRotationTo(lineVector.normalisedCopy());
line->setOrientation(lineRotation *
Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3::UNIT_X));
line->setPosition(start);
line->setScale(0.01f, lineVector.length(), 0.01f);
}
示例9: fire
void Fighter::fire()
{
if(lastShot.getMilliseconds() > 100)
lastShot.reset();
else
return;
AudioManager::getInstance().play("shot1");
Ogre::Vector3 shotPos = mNode->getPosition();
Ogre::Vector3 direction = mNode->getOrientation()*Ogre::Vector3::UNIT_Z;
Shot* shotPtr = new Shot(mSceneManagerPtr,shotPos,direction.normalisedCopy());
mShots.push_back(shotPtr);
}
示例10: axisColor
QColor SparseOccupancyGridArrayDisplay::axisColor(const Ogre::Quaternion& q,
const Ogre::Vector3& p)
{
Ogre::Vector3 zaxis = q.zAxis();
Ogre::Vector3 reference = p.normalisedCopy();
double dot = zaxis.dotProduct(reference);
if (dot < -1) {
dot = -1.0;
}
else if (dot > 1) {
dot = 1.0;
}
double scale = (dot + 1) / 2.0;
return gridColor(scale);
}
示例11: m_collideCamWithTerrain
void AnimalThirdPersonControler::m_collideCamWithTerrain(const Ogre::Vector3& i_avatarToCamera)
{
// Move camera closer if collides with terrain
Ogre::Vector3 colPos, newCamPos;
if (rayToTerrain(m_pAnimal->m_pNode->getPosition(), i_avatarToCamera, *m_pTerrainGroup, colPos) &&
((m_pAnimal->m_pNode->getPosition() - colPos).length() < m_camDistance + m_camHeightOffset))
{
newCamPos = colPos - i_avatarToCamera.normalisedCopy() * m_camHeightOffset;
}
else
{
newCamPos = m_pAnimal->m_pNode->getPosition() + i_avatarToCamera;
}
m_pCamera->setPosition(newCamPos);
m_pCamera->lookAt(m_pAnimal->m_pNode->getPosition() + m_pAnimal->m_cameraLookAtOffset);
}
示例12: _getLength
const float Ellipsoid::_getLength(const int &x, const int &y, const int &z) const
{
// x^2 y^2 z^2
// / + / + / = 1 (Ellipsoid ecuation)
// a^2 b^2 c^2
//
// maxradatdir = lambda (Xo, Yo, Zo) = lambda; where Xo, Yo and Zo are the components of the normaliced direction vector
//
// => lambda^2 = 1 / ( EllipsoidEcuation...)
//
// => lambda = sqrt (...) => maxradatdir = lambda
Ogre::Vector3 Direction = Ogre::Vector3(x-mX, y-mY, z-mZ),
DirectionNormalized = Direction.normalisedCopy();
Ogre::Real a = Ogre::Math::Pow(DirectionNormalized.x, 2) / mA2 +
Ogre::Math::Pow(DirectionNormalized.y, 2) / mB2 +
Ogre::Math::Pow(DirectionNormalized.z, 2) / mC2,
lambda = 1.0f / Ogre::Math::Sqrt(a);
return Ogre::Math::Clamp<Ogre::Real>(Direction.length() / lambda, 0, 1);
}
示例13: move
void AnimalThirdPersonControler::move(int i_frontDir, int i_sideDir, bool i_run, double i_timeSinceLastFrame)
{
if (!(m_pAnimal != nullptr && m_pCamera != nullptr))
return;
if (!(i_frontDir == 0 && i_sideDir == 0))
{
Ogre::Vector3 oldAniPos = m_pAnimal->m_pNode->getPosition();
m_pAnimal->moveOnTerrain(i_frontDir, i_sideDir, i_run, i_timeSinceLastFrame, *m_pTerrainGroup);
Ogre::Vector3 newAniPos = m_pAnimal->m_pNode->getPosition();
// Update cammera
Ogre::Vector3 newCamPos = m_pCamera->getPosition() + newAniPos - oldAniPos;
Ogre::Vector3 newAvatarToCamera = newCamPos - m_pAnimal->m_pNode->getPosition();
if (newAvatarToCamera.length() != m_camDistance)
newAvatarToCamera = newAvatarToCamera.normalisedCopy() * m_camDistance;
// Collide with terrain
m_collideCamWithTerrain(newAvatarToCamera);
}
if (!m_lookAround)
alignAnimalToCamera(i_timeSinceLastFrame);
}
示例14: addTerrainSplineDecal
int DecalManager::addTerrainSplineDecal(Ogre::SimpleSpline *spline, float width, Ogre::Vector2 numSeg, Ogre::Vector2 uvSeg, Ogre::String materialname, float ground_offset, Ogre::String export_fn, bool debug)
{
#if 0
Ogre::ManualObject *mo = gEnv->ogreSceneManager->createManualObject();
String oname = mo->getName();
SceneNode *mo_node = terrain_decals_snode->createChildSceneNode();
mo->begin(materialname, Ogre::RenderOperation::OT_TRIANGLE_LIST);
AxisAlignedBox *aab=new AxisAlignedBox();
int offset = 0;
// how width is the road?
float delta_width = width / numSeg.x;
float steps_len = 1.0f / numSeg.x;
for (int l = 0; l<=numSeg.x; l++)
{
// get current position on that spline
Vector3 pos_cur = spline->interpolate(steps_len * (float)l);
Vector3 pos_next = spline->interpolate(steps_len * (float)(l + 1));
Ogre::Vector3 direction = (pos_next - pos_cur);
if (l == numSeg.x)
{
// last segment uses previous position
pos_next = spline->interpolate(steps_len * (float)(l - 1));
direction = (pos_cur - pos_next);
}
for (int w = 0; w<=numSeg.y; w++)
{
// build vector for the width
Vector3 wn = direction.normalisedCopy().crossProduct(Vector3::UNIT_Y);
// calculate the offset, spline in the middle
Vector3 offset = (-0.5 * wn * width) + (w/numSeg.y) * wn * width;
// push everything together
Ogre::Vector3 pos = pos_cur + offset;
// get ground height there
pos.y = hfinder->getHeightAt(pos.x, pos.z) + ground_offset;
// add the position to the mesh
mo->position(pos);
aab->merge(pos);
mo->textureCoord(l/(Ogre::Real)numSeg.x*uvSeg.x, w/(Ogre::Real)numSeg.y*uvSeg.y);
mo->normal(Vector3::UNIT_Y);
}
}
bool reverse = false;
for (int n1 = 0; n1<numSeg.x; n1++)
{
for (int n2 = 0; n2<numSeg.y; n2++)
{
if (reverse)
{
mo->index(offset+0);
mo->index(offset+(numSeg.y+1));
mo->index(offset+1);
mo->index(offset+1);
mo->index(offset+(numSeg.y+1));
mo->index(offset+(numSeg.y+1)+1);
}
else
{
mo->index(offset+0);
mo->index(offset+1);
mo->index(offset+(numSeg.y+1));
mo->index(offset+1);
mo->index(offset+(numSeg.y+1)+1);
mo->index(offset+(numSeg.y+1));
}
offset++;
}
offset++;
}
offset+=numSeg.y+1;
mo->end();
mo->setBoundingBox(*aab);
// some optimizations
mo->setCastShadows(false);
mo->setDynamic(false);
delete(aab);
MeshPtr mesh = mo->convertToMesh(oname+"_mesh");
// build edgelist
mesh->buildEdgeList();
// remove the manualobject again, since we dont need it anymore
gEnv->ogreSceneManager->destroyManualObject(mo);
unsigned short src, dest;
if (!mesh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
{
mesh->buildTangentVectors(VES_TANGENT, src, dest);
//.........这里部分代码省略.........
示例15: UpdateObject
bool RoomsManager::UpdateObject(Room::ObjectType* object)
{
bool updated=false, inrooms=false;
Room *room;
//std::vector<Room*>::iterator iPos=Rooms.begin(), iEnd=Rooms.end();
inrooms=false;
//for (size_t i=0;i<Rooms.Size;++i)
Ogre::AxisAlignedBox box = object->GetRoomable()->GetBoundingBox(), *RoomBox;
//assert()
for (RoomsPool::ListNode *pos = Rooms.GetBegin(); pos!=NULL; pos=pos->Next)
{
room = pos->Value;
RoomBox = room->GetBox();
if (RoomBox->intersects(box))
{
updated = room->UpdateObject(object);
if (updated)
{
inrooms=true;
}
}
}
if (!inrooms)
{
/*char log[100];
sprintf(log,"Rooms 1: empty room set for object %d\n",object->GetScriptable()->GetID());
Debugging::Log("Warnings.log",log);*/
IRoomable *rmbl = object->GetRoomable();
IPhysical *phys = object->GetPhysical();
if (rmbl)
{
rmbl->RemoveFromRooms();
rmbl->GetRooms()->Clear();
switch (rmbl->GetRoomOnly())
{
case IRoomable::ROM_RESTORE:
{
for (RoomsPool::ListNode *pos = Rooms.GetBegin(); pos!=NULL; pos=pos->Next)
{
Ogre::AxisAlignedBox *box = pos->Value->GetBox();
Ogre::Vector3 center = box->getCenter();
Ogre::Vector3 position = object->GetPosition();
Ogre::Vector3 dist = position - center;
int sqradius = AAUtilities::f2i(box->getHalfSize().squaredLength())+3*phys->GetRadius();
int sqdist = AAUtilities::f2i(dist.squaredLength());
if (sqradius>sqdist)
{
//GetPhysical()->SetForwardDirection(GetOrientation()*Vector3::UNIT_Z);
//object->GetPhysical();
//object->RestoreBackupPosition();
//Ogre::Vector3 newdir=phys->GetLastVelocity();
//phys->Stop();
phys->SetReplacingDirection(-dist.normalisedCopy()*10);
break;
}
}
AddOuterObject(object);
//object->RestoreBackupPosition();
break;
}
case IRoomable::ROM_DESTROY:
{
CommonDeclarations::DeleteObjectRequest(object);
break;
}
case IRoomable::ROM_SCRIPT:
{
IScriptable *scr = object->GetScriptable();
if (scr && scr->GetID()>0)
ScriptManager::GetInstance()->Call("OnOutOfRooms", "i", false, object->GetScriptable()->GetID());
break;
}
case IRoomable::ROM_NONE:
{
AddOuterObject(object);
break;
}
};
}
}
return inrooms;
}