本文整理汇总了C++中Quaternion::FromLookRotation方法的典型用法代码示例。如果您正苦于以下问题:C++ Quaternion::FromLookRotation方法的具体用法?C++ Quaternion::FromLookRotation怎么用?C++ Quaternion::FromLookRotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Quaternion
的用法示例。
在下文中一共展示了Quaternion::FromLookRotation方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetFaceCameraRotation
Quaternion Camera::GetFaceCameraRotation(const Vector3& position, const Quaternion& rotation, FaceCameraMode mode, float minAngle)
{
if (!node_)
return rotation;
switch (mode)
{
case FC_ROTATE_XYZ:
return node_->GetWorldRotation();
case FC_ROTATE_Y:
{
Vector3 euler = rotation.EulerAngles();
euler.y_ = node_->GetWorldRotation().EulerAngles().y_;
return Quaternion(euler.x_, euler.y_, euler.z_);
}
case FC_LOOKAT_XYZ:
{
Quaternion lookAt;
lookAt.FromLookRotation(position - node_->GetWorldPosition());
return lookAt;
}
case FC_LOOKAT_Y:
case FC_LOOKAT_MIXED:
{
// Mixed mode needs true look-at vector
const Vector3 lookAtVec(position - node_->GetWorldPosition());
// While Y-only lookat happens on an XZ plane to make sure there are no unwanted transitions or singularities
const Vector3 lookAtVecXZ(lookAtVec.x_, 0.0f, lookAtVec.z_);
Quaternion lookAt;
lookAt.FromLookRotation(lookAtVecXZ);
Vector3 euler = rotation.EulerAngles();
if (mode == FC_LOOKAT_MIXED)
{
const float angle = lookAtVec.Angle(rotation * Vector3::UP);
if (angle > 180 - minAngle)
euler.x_ += minAngle - (180 - angle);
else if (angle < minAngle)
euler.x_ -= minAngle - angle;
}
euler.y_ = lookAt.EulerAngles().y_;
return Quaternion(euler.x_, euler.y_, euler.z_);
}
default:
return rotation;
}
}
示例2: LookAt
bool SpatialNode::LookAt(const Vector3& target, const Vector3& up, TransformSpace space)
{
SpatialNode* parentNode = SpatialParent();
Vector3 worldSpaceTarget;
switch (space)
{
case TS_LOCAL:
worldSpaceTarget = WorldTransform() * target;
break;
case TS_PARENT:
worldSpaceTarget = !parentNode ? target : parentNode->WorldTransform() * target;
break;
case TS_WORLD:
worldSpaceTarget = target;
break;
}
Vector3 lookDir = worldSpaceTarget - WorldPosition();
// Check if target is very close, in that case can not reliably calculate lookat direction
if (lookDir.Equals(Vector3::ZERO))
return false;
Quaternion newRotation;
// Do nothing if setting look rotation failed
if (!newRotation.FromLookRotation(lookDir, up))
return false;
SetWorldRotation(newRotation);
return true;
}
示例3: GetFaceCameraRotation
Quaternion Camera::GetFaceCameraRotation(const Vector3& position, const Quaternion& rotation, FaceCameraMode mode)
{
if (!node_)
return rotation;
switch (mode)
{
default:
return rotation;
case FC_ROTATE_XYZ:
return node_->GetWorldRotation();
case FC_ROTATE_Y:
{
Vector3 euler = rotation.EulerAngles();
euler.y_ = node_->GetWorldRotation().EulerAngles().y_;
return Quaternion(euler.x_, euler.y_, euler.z_);
}
case FC_LOOKAT_XYZ:
{
Quaternion lookAt;
lookAt.FromLookRotation(position - node_->GetWorldPosition());
return lookAt;
}
case FC_LOOKAT_Y:
{
// Make the Y-only lookat happen on an XZ plane to make sure there are no unwanted transitions
// or singularities
Vector3 lookAtVec(position - node_->GetWorldPosition());
lookAtVec.y_ = 0.0f;
Quaternion lookAt;
lookAt.FromLookRotation(lookAtVec);
Vector3 euler = rotation.EulerAngles();
euler.y_ = lookAt.EulerAngles().y_;
return Quaternion(euler.x_, euler.y_, euler.z_);
}
}
}
示例4: LookAt
bool Node::LookAt(const Vector3& target, const Vector3& up)
{
Vector3 lookDir = target - GetWorldPosition();
// Check if target is very close, in that case can not reliably calculate lookat direction
if (lookDir.Equals(Vector3::ZERO))
return false;
Quaternion rotation;
// Do nothing if setting look rotation failed
if (!rotation.FromLookRotation(lookDir, up))
return false;
SetRotation((parent_ == scene_ || !parent_) ? rotation : parent_->GetWorldRotation().Inverse() * rotation);
return true;
}
示例5: HandleUpdate
void Bird::HandleUpdate(StringHash eventType, VariantMap &eventData)
{
if (dead_ && GetPosition().y_ < -5.0f) Disable();
float timeStep = eventData[SceneUpdate::P_TIMESTEP].GetFloat();
if (sinceSpeciesSet_ < morphTime_){
Morph();
}
sinceSpeciesSet_ += timeStep;
if (sinceStateChange_ > stateDuration_){
switch (state_) {
case BirdState::Flying: {
SetState(BirdState::Landing);
} break;
case BirdState::Standing: {
SetState(BirdState::Flying);
} break;
default:
break;
}
}
if(!(first_ && state_ == BirdState::Standing)) sinceStateChange_ += timeStep;
switch (state_) {
case BirdState::Flying: {
Fly(timeStep);
} break;
case BirdState::Landing: {
Land(timeStep);
} break;
case BirdState::Standing: {
Stand(timeStep);
} break;
default:
break;
}
//Move bird
rootNode_->Translate(velocity_*timeStep, TS_WORLD);
//Update rotation in accordance with the birds movement.
if (velocity_.Length() > 0.01f){
Quaternion rotation = rootNode_->GetWorldRotation();
Quaternion aimRotation = rotation;
aimRotation.FromLookRotation(velocity_);
rootNode_->SetRotation(rotation.Slerp(aimRotation, 2.0f * timeStep * velocity_.Length()));
}
}
示例6: HandleSceneUpdate
void Player::HandleSceneUpdate(StringHash eventType, VariantMap &eventData)
{
//Take the frame time step, which is stored as a double
float timeStep = eventData[Update::P_TIMESTEP].GetFloat();
//Pulse and spin the counters' apples and hearts
UpdateGUI(timeStep);
//Only handle input when player is active
if (!rootNode_->IsEnabled()) return;
Input* input = GetSubsystem<Input>();
//Movement values
Vector3 move = Vector3::ZERO;
Vector3 moveJoy = Vector3::ZERO;
Vector3 moveKey = Vector3::ZERO;
float thrust = pilotMode_ ? 256.0f : 2323.0f;
float maxSpeed = pilotMode_? 1.8f : 23.0f; //Firing values
Vector3 fire = Vector3::ZERO;
Vector3 fireJoy = Vector3::ZERO;
Vector3 fireKey = Vector3::ZERO;
//Read input
if (input->GetJoystickByIndex(0)){
moveJoy = Vector3::RIGHT * input->GetJoystickByIndex(0)->GetAxisPosition(0) +
Vector3::BACK * input->GetJoystickByIndex(0)->GetAxisPosition(1);
fireJoy = Vector3::RIGHT * input->GetJoystickByIndex(0)->GetAxisPosition(2) +
Vector3::BACK * input->GetJoystickByIndex(0)->GetAxisPosition(3);
}
moveKey = Vector3::LEFT * input->GetKeyDown(KEY_A) +
Vector3::RIGHT * input->GetKeyDown(KEY_D) +
Vector3::FORWARD * input->GetKeyDown(KEY_W) +
Vector3::BACK * input->GetKeyDown(KEY_S);
fireKey = Vector3::LEFT * (input->GetKeyDown(KEY_J) || input->GetKeyDown(KEY_KP_4)) +
Vector3::RIGHT * (input->GetKeyDown(KEY_L) || input->GetKeyDown(KEY_KP_6)) +
Vector3::FORWARD * (input->GetKeyDown(KEY_I) || input->GetKeyDown(KEY_KP_8)) +
Vector3::BACK * (input->GetKeyDown(KEY_K) || input->GetKeyDown(KEY_KP_2) || input->GetKeyDown(KEY_KP_5)) +
Quaternion(45.0f, Vector3::UP)*Vector3::LEFT * input->GetKeyDown(KEY_KP_7) +
Quaternion(45.0f, Vector3::UP)*Vector3::RIGHT * input->GetKeyDown(KEY_KP_3) +
Quaternion(45.0f, Vector3::UP)*Vector3::FORWARD * input->GetKeyDown(KEY_KP_9) +
Quaternion(45.0f, Vector3::UP)*Vector3::BACK * input->GetKeyDown(KEY_KP_1);
//Pick most significant input
moveJoy.Length() > moveKey.Length() ? move = moveJoy : move = moveKey;
fireJoy.Length() > fireKey.Length() ? fire = fireJoy : fire = fireKey;
//Restrict move vector length
if (move.Length() > 1.0f) move /= move.Length();
//Deadzone
else if (move.Length() < 0.1f) move *= 0.0f;
if (fire.Length() < 0.1f) fire *= 0.0f;
else fire.Normalize();
//When in pilot mode
if (pilotMode_){
//Apply movement
Vector3 force = move * thrust * timeStep;
if (rigidBody_->GetLinearVelocity().Length() < maxSpeed ||
(rigidBody_->GetLinearVelocity().Normalized() + force.Normalized()).Length() < 1.0f) {
rigidBody_->ApplyForce(force);
}
//Update rotation according to direction of the player's movement.
Vector3 velocity = rigidBody_->GetLinearVelocity();
Vector3 lookDirection = velocity + 2.0f*fire;
Quaternion rotation = rootNode_->GetWorldRotation();
Quaternion aimRotation = rotation;
aimRotation.FromLookRotation(lookDirection);
rootNode_->SetRotation(rotation.Slerp(aimRotation, 7.0f * timeStep * velocity.Length()));
//Update animation
if (velocity.Length() > 0.05f){
animCtrl_->PlayExclusive("Resources/Models/WalkRelax.ani", 0, true, 0.15f);
animCtrl_->SetSpeed("Resources/Models/WalkRelax.ani", velocity.Length()*2.3f);
animCtrl_->SetStartBone("Resources/Models/WalkRelax.ani", "MasterBone");
}
else {
animCtrl_->PlayExclusive("Resources/Models/IdleRelax.ani", 0, true, 0.15f);
animCtrl_->SetStartBone("Resources/Models/IdleRelax.ani", "MasterBone");
}
// When in ship mode
} else {
//Update shield
Quaternion randomRotation = Quaternion(Random(360.0f),Random(360.0f),Random(360.0f));
shieldNode_->SetRotation(shieldNode_->GetRotation().Slerp(randomRotation, Random(1.0f)));
Color shieldColor = shieldMaterial_->GetShaderParameter("MatDiffColor").GetColor();
Color newColor = Color(shieldColor.r_ * Random(0.6f, 0.9f),
shieldColor.g_ * Random(0.7f, 0.95f),
shieldColor.b_ * Random(0.8f, 0.9f));
shieldMaterial_->SetShaderParameter("MatDiffColor", shieldColor.Lerp(newColor, Min(timeStep * 23.5f, 1.0f)));
//Float
ship_.node_->SetPosition(Vector3::UP *masterControl_->Sine(2.3f, -0.1f, 0.1f));
//Apply movement
Vector3 force = move * thrust * timeStep;
if (rigidBody_->GetLinearVelocity().Length() < maxSpeed ||
(rigidBody_->GetLinearVelocity().Normalized() + force.Normalized()).Length() < 1.0f) {
rigidBody_->ApplyForce(force);
}
//.........这里部分代码省略.........
示例7: update
//.........这里部分代码省略.........
else
as_reversing->SetWeight(0.0);
if(jumping==1&&jump_force_applied<max_jump_force_applied) // jump higher if we are jumping and the limit has not been reached
{
if(jump_force_applied>max_jump_force_applied)
{
// do nothing if max jump force reached
}
else if(jump_force_applied+timeStep*800>max_jump_force_applied)
{
// I want to limit the jump height more exactly by limiting the force pumped into it and applieng the remaining rest here. Doesn't fully work yet.
//float f=0;//(max_jump_force_applied-jump_force_applied)*timeStep*2000;
//moveDir+=Vector3::UP*2*f;
//moveDir_global=result.normal_*1*f;
jump_force_applied+=timeStep*900;
}
else
{
float f=1;
moveDir+=Vector3::UP*0.6*f;
moveDir_global=result.normal_*0.3*f;
jump_force_applied+=timeStep*800;
}
}
if(jumping!=1)
jump_force_applied=0;
}
float f=0.5; // for walking or sprinting
if(input->GetKeyDown(KEY_SHIFT))
f=1.0;
Quaternion quat;
quat.FromLookRotation(node_camera->GetDirection()*Vector3(1,0,1),Vector3::UP);
body->SetRotation(quat);
float speed_old=vel.Length();
vel+=rot*moveDir*timeStep*4000*f/body->GetMass();
float speed_new=vel.Length();
if(speed_new>10*f&&speed_new>speed_old) // over limit. Don't increase speed further but make direction change possible.
vel=vel.Normalized()*speed_old;
body->SetLinearVelocity(Vector3(vel.x_,body->GetLinearVelocity().y_+(rot*moveDir*timeStep*4500/body->GetMass()).y_,vel.z_));
body->ApplyImpulse(moveDir_global*timeStep*4000);
{
auto vec_rot=body->GetLinearVelocity()*Vector3(1,0,1);
float s=vec_rot.Length();
vec_rot.Normalize();
float yaw=asin(vec_rot.x_)*180/M_PI;
if(vec_rot.z_<0)
yaw=180-yaw;
node_model->SetPosition(node->GetPosition());
if(s>1&&!camera_first_person)
{
node_model->SetDirection(Vector3::FORWARD);
node_model->Yaw(yaw);
}
}
{ // physic raycast to avoid the player glitching through stuff when moving very fast
Vector3 player_pos=body->GetPosition()+Vector3(0,1,0);
PhysicsRaycastResult result;
Ray ray(pos_last,player_pos-pos_last);
float l=(player_pos-pos_last).Length();
if(l>0.5)
{
globals::instance()->physical_world->SphereCast(result,ray,0.2,l,2);