Example #1
0
void Camera::update()
{
	Vec3 up, pos, rot;
	Matrix rotationMatrix;
	float radianConv = (float)(PI)/180; //Used to convert from degree to radians

	//Setup up-, pos- and look-vectors
	up = Vec3(0,1,0);
	pos = position;

	//Set yaw, pitch and roll rotations in radians
	rot.x = rotation.x * radianConv;
	rot.y = rotation.y * radianConv;
	rot.z = rotation.z * radianConv;

	//Create rotation matrix
	rotationMatrix = yawPitchRoll(rot);

	//Transform lookAt and up vector by rotation matrix
	transformCoord(lookAt, lookAt, rotationMatrix);
	transformCoord(up, up, rotationMatrix);


	//Translate rotated camera position to location of viewer
	lookAt = pos + Vec3(0,0,1);

	//Create view matrix from vectors

    lookAtLHP(viewMatrix, lookAt, up, pos);

	MatrixInversion(viewInv, viewMatrix);

#ifdef _WIN32
	CBCameraMove cb;

	cb.cameraPos = pos;
	cb.cameraDir = lookAt - pos;

	cb.View = viewMatrix;
	cb.ViewInv = viewInv;

	GraphicsDX11::getInstance()->updateCBCameraMove(cb);
#endif
}
// create a game object from lua
int LuaInternalScriptExports::CreateGameObject(const char* objectArchetype, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaYawPitchRoll)
{
	// lua position must be a table
	if (!luaPosition.IsTable())
	{
		CB_ERROR("Invalid object passed to CreateGameObject(). Type = " + std::string(luaPosition.TypeName()));
		return INVALID_GAMEOBJECT_ID;
	}
	// lua yawPitchRoll must be a table
	if (!luaYawPitchRoll.IsTable())
	{
		CB_ERROR("Invalid object passed to CreateGameObject(). Type = " + std::string(luaYawPitchRoll.TypeName()));
		return INVALID_GAMEOBJECT_ID;
	}

	Vec3 position(luaPosition["x"].GetFloat(), luaPosition["y"].GetFloat(), luaPosition["z"].GetFloat());
	Vec3 yawPitchRoll(luaYawPitchRoll["x"].GetFloat(), luaYawPitchRoll["y"].GetFloat(), luaYawPitchRoll["z"].GetFloat());
	// build the transform for the object
	Mat4x4 transform;
	transform.BuildYawPitchRoll(yawPitchRoll.x, yawPitchRoll.y, yawPitchRoll.z);
	transform.SetPosition(position);

	// create the object
	TiXmlElement* overloads = nullptr;
	StrongGameObjectPtr pObject = g_pApp->m_pGame->CreateGameObject(objectArchetype, overloads, &transform);

	// fire the new object created event
	if (pObject)
	{
		shared_ptr<Event_NewGameObject> pNewObjectEvent(CB_NEW Event_NewGameObject(pObject->GetId()));
		IEventManager::Get()->QueueEvent(pNewObjectEvent);
		return pObject->GetId();
	}

	return INVALID_GAMEOBJECT_ID;
}
Example #3
0
  //--------------------------------------------------------------------------------------
  // Update the view matrix based on user input & elapsed time
  //--------------------------------------------------------------------------------------
  void CFirstPersonCamera::FrameMove( double fElapsedTime )
  {
      if( IsKeyDown( mKeys[CAM_RESET] ) ) {
          Reset();
      }

      if (IsKeyDown(mKeys[CAM_ACCELERATE])) {
        if (mKeyboardMoveScaler < 10000.0) {
          mKeyboardMoveScaler *= 1.2;
        }

        if (mMouseMoveScaler < 10000.0) {
          mMouseMoveScaler *= 1.2;
        }
        //since accelerating shouldn't be done continously, force key up here
        HandleKeys(CAM_ACCELERATE, false);
      }
      if (IsKeyDown(mKeys[CAM_THROTTLE])) {
        if (mKeyboardMoveScaler > 0.1) {
          mKeyboardMoveScaler /= 1.2;
        }

        if (mMouseMoveScaler > 0.1) {
          mMouseMoveScaler /= 1.2;
        }

        HandleKeys(CAM_THROTTLE, false);
      }

      // Get keyboard/mouse/gamepad input
      GetInput( mEnablePositionMovement, ( mActiveButtonMask & mCurrentButtonMask ) || mRotateWithoutButtonDown,
                true, mResetCursorAfterMove );

      // Get amount of velocity based on the keyboard input and drag (if any)
      UpdateVelocity( fElapsedTime );

      // Simple euler method to calculate position delta
      dvec3 vPosDelta = mVelocity * fElapsedTime;

      // If rotating the camera 
      if (mMouseRotates) {
        if( ( mActiveButtonMask & mCurrentButtonMask ) || mRotateWithoutButtonDown) {

            // Update the pitch & yaw angle based on mouse movement
          double fYawDelta = mRotVelocity.x;
          double fPitchDelta = mRotVelocity.y;

            // Invert pitch if requested
            if( mInvertPitch )
                fPitchDelta = -fPitchDelta;

            mCameraPitchAngle -= fPitchDelta;
            mCameraYawAngle -= fYawDelta;

            // Limit pitch to straight up or straight down
            mCameraPitchAngle = std::max( -pi<double>() * 0.499, mCameraPitchAngle );
            mCameraPitchAngle = std::min( +pi<double>() * 0.499, mCameraPitchAngle );
        }
      }

      // Make a rotation matrix based on the camera's yaw & pitch
      dmat4 mCameraRot = yawPitchRoll(mCameraYawAngle, mCameraPitchAngle, 0.0);


      // Transform vectors based on camera's rotation matrix
      dvec3 vWorldUp, vWorldAhead;
      const dvec3 vLocalUp = dvec3( 0, 1, 0 );
      const dvec3 vLocalAhead = dvec3( 0, 0, -1 );

      vWorldUp = Vec3TransformCoord(vLocalUp, mCameraRot);
      vWorldAhead = Vec3TransformCoord(vLocalAhead, mCameraRot);

      // Transform the position delta by the camera's rotation 
      dvec3 vPosDeltaWorld;
      if( !mEnableYAxisMovement )
      {
          // If restricting Y movement, do not include pitch
          // when transforming position delta vector.
          mCameraRot = yawPitchRoll(mCameraYawAngle, 0.0, 0.0 );
      }

      vPosDeltaWorld = Vec3TransformCoord(vPosDelta, mCameraRot );

      // Move the eye position 
      mEye += vPosDeltaWorld;
      if( mClipToBoundary )
          ConstrainToBoundary( &mEye );

      // Update the lookAt position based on the eye position 
      mLookAt = mEye + vWorldAhead;

      // Update the view matrix
      mViewMatrix = lookAt(mEye, mLookAt, vWorldUp );

      mCameraWorld = inverse(mViewMatrix );
  }
Example #4
0
 void Transform::setRotationEuler(glm::vec3 angles){
     assert(!glm::any(glm::isnan(angles)));
     mat4 rot = yawPitchRoll(angles.y, angles.x, angles.z);
     setRotation(quat_cast(rot));
 }
Example #5
0
 void Transform::setLocalRotationEuler(glm::vec3 angles){
     assert(!glm::any(glm::isnan(angles)));
     mat4 rot = yawPitchRoll(angles.y, angles.x, angles.z);
     mLocalRotationQuat = quat_cast(rot);
     markLocalDirty();
 }