本文整理汇总了C++中ogre::Vector3::crossProduct方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector3::crossProduct方法的具体用法?C++ Vector3::crossProduct怎么用?C++ Vector3::crossProduct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Vector3
的用法示例。
在下文中一共展示了Vector3::crossProduct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: offsetX
void CCS::FreeCameraMode::update(const Ogre::Real &timeSinceLastFrame)
{
Ogre::Vector3 dirVector = mCameraCS->getOgreCamera()->getRealDirection();
Ogre::Vector3 lateralVector = dirVector.crossProduct(mFixedAxis).normalisedCopy();
Ogre::Vector3 upVector = -dirVector.crossProduct(lateralVector).normalisedCopy();
Ogre::Vector3 displacement = ((dirVector * mLongitudinalDisplacement)
+ (upVector * mVerticalDisplacement)
+ (lateralVector * mLateralDisplacement)) * timeSinceLastFrame * mMoveFactor;
mCameraPosition += displacement;
if(mCollisionsEnabled)
{
mCameraPosition = collisionDelegate(mCameraCS->getCameraTargetPosition(), mCameraPosition);
}
Ogre::Quaternion offsetX(mRotY,Ogre::Vector3::UNIT_X);
Ogre::Quaternion offsetY(mRotX,mFixedAxis);
mCameraOrientation = offsetY * offsetX;
mLongitudinalDisplacement = 0;
mLateralDisplacement = 0;
mVerticalDisplacement = 0;
}
示例2: setDirection
//-----------------------------------------------------------------------------------------
void CCameraEditor::setDirection(const Ogre::Vector3 &vec)
{
if (vec == Ogre::Vector3::ZERO) return;
Ogre::Vector3 zAdjustVec = -vec;
zAdjustVec.normalise();
Ogre::Quaternion orientation;
Ogre::Vector3 YawFixedAxis = Ogre::Vector3::UNIT_Y;
Ogre::Vector3 xVec = YawFixedAxis.crossProduct( zAdjustVec );
xVec.normalise();
Ogre::Vector3 yVec = zAdjustVec.crossProduct( xVec );
yVec.normalise();
orientation.FromAxes( xVec, yVec, zAdjustVec );
// transform to parent space
if (mParentEditor->get())
{
orientation = mParentEditor->get()->getNode()->_getDerivedOrientation().Inverse() * orientation;
}
mOrientation->set(orientation);
}
示例3: axis
Ogre::Vector3 ParticleChain::computeFrictionDamping(const Ogre::Vector3 &normal, const Ogre::Vector3 &velocity)
{
int minAxis = 0;
if (normal.y*normal.y < normal.x*normal.x) minAxis = 1;
Ogre::Vector3 axis(0, 0, 0);
axis[minAxis] = 1;
Ogre::Vector3 u = normal.crossProduct(axis);
Ogre::Vector3 v = u.crossProduct(normal);
return mFriction * (velocity.dotProduct(u) * u + velocity.dotProduct(v) * v);
}
示例4: if
Ogre::Vector2 SceneObject::getCoordByTriangle(Ogre::Vector3 _position, const Ogre::Vector3& _corner0, const Ogre::Vector3& _corner1, const Ogre::Vector3& _corner2) const
{
Ogre::Vector2 result; // результат
Ogre::Vector3 dirX = _corner1 - _corner0;
Ogre::Vector3 dirY = _corner2 - _corner0;
_position -= _corner0; // расстояние от начала координат (от точки 0)
Ogre::Vector3 div = (dirX.crossProduct(dirY));
if (div.x != 0.0)
{
result = Ogre::Vector2((_position.crossProduct(dirY)).x, (dirX.crossProduct(_position)).x);
result /= div.x;
}
else if (div.y != 0.0)
{
result = Ogre::Vector2((_position.crossProduct(dirY)).y, (dirX.crossProduct(_position)).y);
result /= div.y;
}
else if (div.z != 0.0)
{
result = Ogre::Vector2((_position.crossProduct(dirY)).z, (dirX.crossProduct(_position)).z);
result /= div.z;
}
else
{
// пипец
}
return result;
}
示例5: mouseMovedObjectsPalettePreview
void EditorApplication::mouseMovedObjectsPalettePreview(const OIS::MouseEvent &arg) {
float mouse_x=arg.state.X.abs/float(arg.state.width);
float mouse_y=arg.state.Y.abs/float(arg.state.height);
viewport->convertMouseToLocalScreen(mouse_x, mouse_y);
// Raycast from camera to viewport
Ogre::Vector3 raycast_point(0.0f);
Ogre::Vector3 raycast_normal(0.0f);
viewport->raycastPlacement(mouse_x, mouse_y, 15.0f, &raycast_point, &raycast_normal, EDITOR_NODE_QUERY_TERRAIN | EDITOR_NODE_QUERY_HAVOK);
if (placement_grid_snap > 0.0f) {
float half_placement_grid_snap = placement_grid_snap/2.0f;
float grid_offset = fmod(raycast_point.x, placement_grid_snap);
if (grid_offset < half_placement_grid_snap) raycast_point.x -= grid_offset;
else raycast_point.x += placement_grid_snap - grid_offset;
grid_offset = fmod(raycast_point.y, placement_grid_snap);
if (grid_offset < half_placement_grid_snap) raycast_point.y -= grid_offset;
else raycast_point.y += placement_grid_snap - grid_offset;
grid_offset = fmod(raycast_point.z, placement_grid_snap);
if (grid_offset < half_placement_grid_snap) raycast_point.z -= grid_offset;
else raycast_point.z += placement_grid_snap - grid_offset;
}
// Calculate current preview's center
Ogre::Vector3 center=Ogre::Vector3::ZERO;
for (list<ObjectNode *>::iterator it=current_palette_nodes.begin(); it!=current_palette_nodes.end(); it++) {
center += (*it)->getPosition();
}
center /= current_palette_nodes.size();
// Translate all nodes from center of the list
Ogre::Vector3 translate = raycast_point - center;
for (list<ObjectNode *>::iterator it=current_palette_nodes.begin(); it!=current_palette_nodes.end(); it++) {
(*it)->translate(translate);
}
// Calculate rotation
Ogre::Quaternion rotation;
if (!raycast_normal.isZeroLength()) {
Ogre::Vector3 right = raycast_normal.crossProduct(Ogre::Vector3::UNIT_Z);
Ogre::Vector3 forward = right.crossProduct(raycast_normal);
rotation = Ogre::Quaternion(right, raycast_normal, forward);
}
else {
rotation = Ogre::Quaternion::IDENTITY;
}
// Rotate all nodes
for (list<ObjectNode *>::iterator it=current_palette_nodes.begin(); it!=current_palette_nodes.end(); it++) {
(*it)->setRotation(rotation);
}
}
示例6: addGlobalForce
void Body::addGlobalForce( Ogre::Vector3& force, Ogre::Vector3& pos )
{
Ogre::Vector3 bodypos;
Ogre::Quaternion bodyorient;
getPositionOrientation( bodyorient, bodypos );
Ogre::Vector3 topoint = pos - bodypos;
Ogre::Vector3 torque = topoint.crossProduct( force );
addForce( force );
addTorque( torque );
}
示例7: AddTorqueAtPoint
void CSpaghettiRigidBody::AddTorqueAtPoint(
Ogre::Vector3 &force,
Ogre::Vector3 &point
)
{
// Convert to coordinates relative to center of mass.
Ogre::Vector3 pt = point;
pt = m_position - pt;
Ogre::Vector3 ptxi = force.crossProduct(pt);
m_torque = m_torque + ptxi;
}
示例8: testCollisionWithBall
void RacketPhysics::testCollisionWithBall()
{
if (timeSinceLastHit < 0.5f)
return;
Ogre::Vector3 racketNormal = Ogre::Vector3::UNIT_Y;
racketNormal = ori * racketNormal;
Ogre::Vector3 ballPos = ball->getPosition();
Ogre::Plane racketPlane(racketNormal, pos);
float distanceFromPlane = racketPlane.getDistance(ballPos);
if (distanceFromPlane < 0.0f)
{
racketNormal = -racketNormal;
distanceFromPlane = -distanceFromPlane;
}
//if (distanceFromPlane < g_RacketThickness + g_BallRadius)
if (distanceFromPlane < 0.03f)
{
Ogre::Vector3 distanceVector = racketNormal * distanceFromPlane;
Ogre::Vector3 nearestPointOnPlane = ballPos - distanceVector;
Ogre::Vector3 distanceOnPlane = nearestPointOnPlane - pos;
//odprintf("dist before: %f, %f, %f", distanceOnPlane.x, distanceOnPlane.y, distanceOnPlane.z);
distanceOnPlane.z *= 0.5f;
distanceOnPlane.y *= 0.5f;
//odprintf("dist after: %f, %f, %f", distanceOnPlane.x, distanceOnPlane.y, distanceOnPlane.z);
float projectedDistance = distanceOnPlane.length();
//odprintf("dist sum: %f", projectedDistance);
//if (projectedDistance < g_RacketRadiusB)
if (projectedDistance < 0.3f)
{
odprintf("HIT, time sinc last hit: %f", timeSinceLastHit);
timeSinceLastHit = 0;
// Collision
ballPos += distanceVector * (0.03f/abs(distanceFromPlane));
ball->setPosition(ballPos);
Ogre::Vector3 ballSpeed = ball->getSpeed();
ballSpeed = ballSpeed.reflect(racketNormal);
// Perpendicular element, used for spin
Ogre::Vector3 speedPerp = racketPlane.projectVector(speed);
ball->setSpin(speedPerp.crossProduct(racketNormal));
// Parallel element, used for speed
Ogre::Vector3 speedPara = speed - speedPerp;
ballSpeed += speedPara * g_HitStrength;
ball->setSpeed(ballSpeed);
gameLogic->onTouchRacket(playerId);
}
else
{
//odprintf("no hit, time sinc last hit: %f", timeSinceLastHit);
}
}
}
示例9: getOrientation
Ogre::Quaternion DetectedVehicle::getOrientation() const
{
Ogre::Vector3 speed = getSpeed() ;
Ogre::Vector3 side(-speed.y,speed.x,-speed.z) ;
side.normalise() ;
Ogre::Vector3 forward = speed ;
forward.normalise() ;
Ogre::Vector3 up = forward.crossProduct(side) ;
up.normalise() ;
return Ogre::Quaternion(side,up,forward) ;
}
示例10: roll_q
std::pair<Ogre::Vector3, Ogre::Quaternion>
CombatCamera::CameraPositionAndOrientation(Ogre::Real distance) const
{
// Here, we calculate where m_camera should be relative to its parent
// m_camera_node. m_camera_node always stays on the ecliptic, and the
// camera moves away from it a bit to look at the position it occupies.
// This code was originally written using the high-level Ogre::Camera API,
// but now the camera position sometimes needs to be known without
// actually moving the camera. The original lines of code are preserved
// here as comments, and under each one is the equivalent code cut from
// OgreCamera.cpp.
std::pair<Ogre::Vector3, Ogre::Quaternion> retval;
// Ogre::Camera::setPosition(Ogre::Vector3::ZERO);
retval.first = Ogre::Vector3::ZERO;
// Ogre::Camera::setDirection(Ogre::Vector3::NEGATIVE_UNIT_Z);
{
Ogre::Vector3 zAdjustVec = -Ogre::Vector3::NEGATIVE_UNIT_Z;
Ogre::Vector3 xVec = Ogre::Vector3::UNIT_Y.crossProduct( zAdjustVec );
xVec.normalise();
Ogre::Vector3 yVec = zAdjustVec.crossProduct( xVec );
yVec.normalise();
retval.second.FromAxes( xVec, yVec, zAdjustVec );
}
// Ogre::Camera::roll(m_roll);
{
Ogre::Vector3 zAxis = retval.second * Ogre::Vector3::UNIT_Z;
Ogre::Quaternion roll_q(m_roll, zAxis);
roll_q.normalise();
retval.second = roll_q * retval.second;
}
// Ogre::Camera::pitch(m_pitch);
{
Ogre::Vector3 xAxis = retval.second * Ogre::Vector3::UNIT_X;
Ogre::Quaternion pitch_q(m_pitch, xAxis);
pitch_q.normalise();
retval.second = pitch_q * retval.second;
}
// Ogre::Camera::moveRelative(Ogre::Vector3(0, 0, distance));
{
Ogre::Vector3 trans = retval.second * Ogre::Vector3(0, 0, distance);
retval.first += trans;
}
return retval;
}
示例11: injectMouseMove
void OrientationControlet::injectMouseMove(int _absx, int _absy, int _absz){
if( mPick &&
(_absx!=mMouseX ||
_absy!=mMouseY) ){
/*计算和摇杆球面的交点
*/
Game& game = Game::getSingleton();
int sx = game.getScreenWidth();
int sy = game.getScreenHeight();
Ogre::Vector3 eye = game.getCamera()->getPosition();
Ogre::Ray A = game.getCamera()->getCameraToViewportRay(
(Ogre::Real)mMouseX/(Ogre::Real)sx,
(Ogre::Real)mMouseY/(Ogre::Real)sy
);
Ogre::Ray B = game.getCamera()->getCameraToViewportRay(
(Ogre::Real)_absx/(Ogre::Real)sx,
(Ogre::Real)_absy/(Ogre::Real)sy
);
//计算和旋转盘的交点,旋转盘是一个平面
//平面的法向量是Local Z轴,平面通过Local原点
Ogre::Matrix3 m3 = mNode->getLocalAxes();
Ogre::Vector3 v3 = mNode->getPosition();
Ogre::Vector3 axis = m3.GetColumn(2);
Ogre::Sphere S(v3,mRaduis);
Math3d::CalcResult result1 = Math3d::CalcRaySphereNearFarPoint(A,S,mNearFar);
Math3d::CalcResult result2 = Math3d::CalcRaySphereNearFarPoint(B,S,mNearFar);
if( result1.first && result2.first ){//都相交
//然后使用直线的参数方程计算出具体的焦点
Ogre::Vector3 a = result1.second;
Ogre::Vector3 b = result2.second;
a -= v3;b -= v3;
a.normalise();
b.normalise();
Ogre::Vector3 c = b.crossProduct(a);
Ogre::Real sinv = c.length();
Ogre::Real ang = -asinf(sinv);
c.normalise();
mNode->rotate( c,Ogre::Radian(ang),Ogre::Node::TS_WORLD );
mNotify( mName,c,ang );
}
mMouseX = _absx;
mMouseY = _absy;
}
mouseFocus( _absx,_absy );
}
示例12: setDirection
void setDirection( const Ogre::Vector3 &dir )
{
assert(mIndicatorSceneNode);
// 分别计算出节点三个轴上的方向
Ogre::Vector3 yAdjustVec = -dir;
yAdjustVec.normalise();
Ogre::Vector3 xVec = mIndicatorSceneNode->getOrientation().zAxis().crossProduct( yAdjustVec );
xVec.normalise();
Ogre::Vector3 zVec = xVec.crossProduct( yAdjustVec );
zVec.normalise();
mIndicatorSceneNode->setOrientation(Ogre::Quaternion( xVec, yAdjustVec, zVec ));
}
示例13: setInheritedVelOmega
void PhysicsRagDoll::setInheritedVelOmega(const Ogre::Vector3& vel, const Ogre::Vector3& omega)
{
// find main position.
Ogre::Vector3 mainpos = mNode->_getDerivedPosition();
for (RagBoneMapIterator it = mRagBonesMap.begin(); it != mRagBonesMap.end(); it++)
{
Ogre::Vector3 pos;
Ogre::Quaternion orient;
if (it->second->getBody())
{
it->second->getBody()->getPositionOrientation(pos, orient);
it->second->getBody()->setVelocity(vel + omega.crossProduct(pos - mainpos));
}
}
}
示例14: sprintf
//.........这里部分代码省略.........
orient_direction = direction;
Ogre::Vector3 target_point = Ogre::Vector3::NEGATIVE_UNIT_Z*10000;
Ogre::Quaternion orientation = scen->GetOrientation();
target_point = orientation * target_point;
target_point = own_pos + target_point;
pf->SetTargetPoint(target_point);
}
}
//if (phys)
// orient_direction = -phys->GetForwardDirection();
}
break;
case FA1_BREAKAWAY:
//if (FA1_FLEEING2SEEKING == FlyNAttack1State)
{
FleeingTime = 0;
if (direction.squaredLength()>(MinDistance+BufferZone)*(MinDistance+BufferZone))
{
#ifdef FNAS1_DEBUG
sprintf(log,"BREAKAWAY switch off\n");
Debugging::Log("fnas",log);
#endif
FlyNAttack1State = FA1_FLEEING;
} else
{
#ifdef FNAS1_DEBUG
sprintf(log,"BREAKAWAY go on\n");
Debugging::Log("fnas",log);
#endif
actual_rotation_fps = actual_rotation_fps*5;
if (pf)
{
orient_direction = direction;
Ogre::Vector3 target_point = Ogre::Vector3::NEGATIVE_UNIT_Z*10000;
Ogre::Quaternion orientation = scen->GetOrientation();
target_point = orientation * target_point;
target_point = own_pos + target_point;
pf->SetTargetPoint(target_point);
}
}
//if (phys)
// orient_direction = -phys->GetForwardDirection();
}
break;
};
#ifdef FNAS1_DEBUG
sprintf(log,"end: %d\n", (int)FlyNAttack1State);
Debugging::Log("fnas",log);
#endif
}/* else
{
actual_rotation_fps = actual_rotation_fps*5;
if (pf)
{
orient_direction = direction;
Ogre::Vector3 target_point = Ogre::Vector3::NEGATIVE_UNIT_Z*10000;
Ogre::Quaternion orientation = scen->GetOrientation();
target_point = orientation * target_point;
target_point = own_pos + target_point;
pf->SetTargetPoint(target_point);
}
}*/
if (!orient_direction.isZeroLength() && PrevOrientDirection != orient_direction)
{
Ogre::Quaternion OurOrientation = scen->GetOrientation();
//Ogre::Vector3 direction = Target->GetPosition()-scen->GetPosition();
orient_direction.normalise();
Ogre::Vector3 up =CommonDeclarations::GetUpVector();
Vector3 xVec = up.crossProduct(orient_direction);
xVec.normalise();
Vector3 yVec = orient_direction.crossProduct(xVec);
yVec.normalise();
Quaternion unitZToTarget = Quaternion(xVec, yVec, orient_direction);
Quaternion targetOrientation = Quaternion(-unitZToTarget.y, -unitZToTarget.z, unitZToTarget.w, unitZToTarget.x);
PrevOrientDirection = orient_direction;
RotationUnit.StartRotation(OurOrientation, targetOrientation, actual_rotation_fps);
}
if(RotationUnit.mRotating)
{
RotationUnit.Step();
if(RotationUnit.mRotating) // Process timed rotation
{
Ogre::Quaternion delta = RotationUnit.Slerp();
scen->SetOrientation(delta);
}
}
}
示例15: plane
bool
AxisRenderable::collideAxis(Ogre::Ray& ray)
{
Ogre::Vector3 dir = getWorldPosition() - ray.getOrigin();
Ogre::Real mAxisGizmoProjLen = mLength / mViewport->getActualWidth() * dir.length() * Ogre::Math::Tan(mCamera->getFOVy());
dir.normalise();
mAxisGizmoSelAxis = -1;
// find axis to use...
for(unsigned int i = 0; i < 3; i++)
{
Ogre::Vector3 up, normal;
up = dir.crossProduct(mAxisGizmoVector[i]);
normal = up.crossProduct(mAxisGizmoVector[i]);
if(normal.isZeroLength())
break;
Ogre::Plane plane(normal,getWorldPosition());
// width of the axis poly is 1/10 the run
Ogre::Vector3 a = up * mAxisGizmoProjLen / 10;
Ogre::Vector3 b = mAxisGizmoVector[i] * mAxisGizmoProjLen;
Ogre::Vector3 poly [] =
{
Ogre::Vector3(getWorldPosition() + a),
Ogre::Vector3(getWorldPosition() + a + b),
Ogre::Vector3(getWorldPosition() - a + b),
Ogre::Vector3(getWorldPosition() - a)
};
Ogre::Vector3 end = ray.getPoint(mProjectDistance);
Ogre::Real t = intersect(&plane,ray.getOrigin(), end);
if(t >= 0 && t <= 1)
{
Ogre::Vector3 pos = interpolate(ray.getOrigin(), end, t);
// check if inside our 'poly' of this axis vector...
bool inside = true;
for(unsigned int j = 0; inside && (j < 4); j++)
{
unsigned int k = (j+1) % 4;
Ogre::Vector3 vec1 = poly[k] - poly[j];
Ogre::Vector3 vec2 = pos - poly[k];
if(vec1.dotProduct(vec2) >0.f)
inside = false;
}
//
if(inside)
{
mAxisGizmoSelAxis = i;
return(true);
}
}
}
return(false);
}