コード例 #1
0
ファイル: Camera.cpp プロジェクト: xamarin/Urho3D
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
0
ファイル: Camera.cpp プロジェクト: Boshin/Urho3D
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_);
        }
    }
}
コード例 #3
0
ファイル: ActorManager.cpp プロジェクト: karmalis/Romuva
int RomCommon::ActorManager::GetActorRotation(lua_State* L)
{
	lua_State* lState = LuaManager::getInstance()->CheckState(L);
	std::string name("");

	UINT16 n = lua_gettop(lState);
	if(n == 1)
	{
		LuaManager::getInstance()->GetFunctionArg(name, lState);
	}

	if(!name.empty())
	{
		boost::shared_ptr<Actor> actor = ActorManager::getInstance()->FindActorByName(name);
		if(actor)
		{
			
			Quaternion q = actor->GetOrientation();
			Vector3D rotation = q.EulerAngles();

			lua_newtable(lState);
			n = lua_gettop(lState);

			lua_pushstring(lState, "X");
			lua_pushnumber(lState, rotation.X);
			lua_settable(lState, n);

			lua_pushstring(lState, "Y");
			lua_pushnumber(lState, rotation.Y);
			lua_settable(lState, n);

			lua_pushstring(lState, "Z");
			lua_pushnumber(lState, rotation.Z);

			lua_settable(lState, n);

			return 1;

		} else {
			Logger::getInstance()->Log("ActorManager :: GetActorRotation - Could not find the specified actor", LOG_WARNING);
		}
	} else {
		Logger::getInstance()->Log("ActorManager :: GetActorRotation - No actor name specified", LOG_WARNING);
	}

	lua_pushboolean(lState, false);
	return 1;
}
コード例 #4
0
ファイル: bird.cpp プロジェクト: Modanung/Finchy
void Bird::Land(float timeStep)
{
    Vector3 targetDelta = target_ - GetPosition();
    if (targetDelta.Length() < 0.5f){
        if (!touchDown_){
            touchDown_ = true;
            animCtrl_->StopAll(0.1f);
            animCtrl_->Play("Resources/Models/Land.ani", 0, false, 0.1f);
        }
        Quaternion rotation = rootNode_->GetWorldRotation();
        Vector3 eulerRotation = rotation.EulerAngles();
        Quaternion aimRotation = Quaternion(0.0f, eulerRotation.y_, 0.0f);
        if (first_) aimRotation = Quaternion(0.0f, rootNode_->GetDirection().x_ > 0.0f? 90.0f : -90.0f, 0.0f);
        rootNode_->SetRotation(rotation.Slerp(aimRotation, 5.0f*timeStep));

        if (targetDelta.Length() < 0.2f || targetDelta.y_ > 0.0f) {
            SetState(BirdState::Standing);
        }
    }
    velocity_ += 23.0f * timeStep * targetDelta.Normalized() * Clamp( targetDelta.Length()*0.5f, 2.0f, 4.0f ) - Finchy::Scale(velocity_, Vector3(0.023f, 0.23f, 0.023f));
    velocity_ *= Clamp( 0.2f + targetDelta.Length() * 0.666f, 0.2f, 0.95f );
    velocity_.x_ = Clamp(velocity_.x_, -targetDelta.Length(), targetDelta.Length());
    velocity_.y_ = Clamp(velocity_.y_, -targetDelta.Length(), targetDelta.Length());
}