void  OgreWidget::mouseMoveEvent(QMouseEvent * e)
{
  if (m_oldPos != InvalidMousePoint)
    {
      Ogre::Real deltaX = e->pos().x() - m_oldPos.x();
      Ogre::Real deltaY = e->pos().y() - m_oldPos.y();

      if (m_mouseButtonsPressed.testFlag(Qt::MiddleButton))
        {
          if(e->modifiers().testFlag(Qt::ControlModifier))
            m_camera->zoom(-deltaY);
          else if (e->modifiers().testFlag(Qt::ShiftModifier))
            m_camera->rotate(deltaX, -deltaY);
          else
            m_camera->shift(-deltaX, -deltaY);
        }
      else if (m_mouseButtonsPressed.testFlag(Qt::LeftButton) && !m_selectionManager.isEmpty())
        {
          if (m_constraintedX && e->modifiers().testFlag(Qt::ShiftModifier))
            m_selectionManager.pitch(Ogre::Degree(deltaX));
          else if (m_constraintedY && e->modifiers().testFlag(Qt::ShiftModifier))
            m_selectionManager.yaw(Ogre::Degree(deltaX));
          else if (m_constraintedZ && e->modifiers().testFlag(Qt::ShiftModifier))
            m_selectionManager.roll(Ogre::Degree(deltaX));
          else
            {
              Ogre::Plane plane;

              if (m_constraintedX)
                plane.redefine(Ogre::Vector3(1, 0, 0), m_selectionManager.getPosition());
              else if (m_constraintedY)
                plane.redefine(Ogre::Vector3(0, 1, 0), m_selectionManager.getPosition());
              else if (m_constraintedZ)
                plane.redefine(Ogre::Vector3(0, 0, 1), m_selectionManager.getPosition());

              Ogre::Ray                   oldRay = m_camera->getCamera()->getCameraToViewportRay(e->pos().x() / (float)width(), e->pos().y() / (float)height());
              Ogre::Ray                   ray = m_camera->getCamera()->getCameraToViewportRay(m_oldPos.x() / (float)width(), m_oldPos.y() / (float)height());
              std::pair<bool, Ogre::Real> oldResult = oldRay.intersects(plane);
              std::pair<bool, Ogre::Real> result = ray.intersects(plane);

              if (result.first && oldResult.first)
                {
                  Ogre::Vector3 point;

                  point = oldRay.getPoint(oldResult.second) - ray.getPoint(result.second);
                  m_selectionManager.translate(point.x, point.y, point.z);
                }
            }
          emit itemMoved();
        }
      m_oldPos = e->pos();

      update();
      e->accept();
    }
  else
    {
      e->ignore();
    }
}
Beispiel #2
0
void CObjectTitle::update(Ogre::SceneNode *pUnitObjectNode, Ogre::SceneNode *pCameraNode)
{
   
   float distance = getDistance(pUnitObjectNode->getPosition().x, pUnitObjectNode->getPosition().z,
                                pCameraNode->getPosition().x, pCameraNode->getPosition().z);
   if(distance > 50) {
      m_pOverlay->hide();
      return;
   }

   if(!m_pObject->isInScene()) {
      m_pOverlay->hide();
      return;
   }

   // Derive the average point between the top-most corners of the object's bounding box
   const Ogre::AxisAlignedBox &AABB = m_pObject->getWorldBoundingBox(true);
   Ogre::Vector3 point = (AABB.getCorner(Ogre::AxisAlignedBox::FAR_LEFT_TOP)
                        + AABB.getCorner(Ogre::AxisAlignedBox::FAR_RIGHT_TOP)
                        + AABB.getCorner(Ogre::AxisAlignedBox::NEAR_LEFT_TOP)
                        + AABB.getCorner(Ogre::AxisAlignedBox::NEAR_RIGHT_TOP)) / 4;

   // Is the camera facing that point? If not, hide the overlay and return.
   Ogre::Plane cameraPlane = Ogre::Plane(Ogre::Vector3(m_pCamera->getDerivedOrientation().zAxis()), m_pCamera->getDerivedPosition());
   if(cameraPlane.getSide(point) != Ogre::Plane::NEGATIVE_SIDE) {
      m_pOverlay->hide();
      return;
   }

   // Derive the 2D screen-space coordinates for that point
   point = m_pCamera->getProjectionMatrix() * (m_pCamera->getViewMatrix() * point);

   // Transform from coordinate space [-1, 1] to [0, 1]
   Ogre::Real x = (point.x / 2) + 0.5f;
   Ogre::Real y = 1 - ((point.y / 2) + 0.5f);

   // Update the position (centering the text)
   m_pContainer->setPosition(x - (m_textDim.x / 6), y - 0.05f);
   m_pOverlay->show();
}
void ObjectTitle::update()
{
    if(!object->isInScene())
    {
	setVisible(false);
        overlay->hide();
        return;
    }
 
    // Derive the average point between the top-most corners of the object's bounding box
    const Ogre::AxisAlignedBox &AABB = object->getWorldBoundingBox(true);
    Ogre::Vector3 point = (AABB.getCorner(AxisAlignedBox::FAR_LEFT_TOP)
        + AABB.getCorner(AxisAlignedBox::FAR_RIGHT_TOP)
        + AABB.getCorner(AxisAlignedBox::NEAR_LEFT_TOP)
        + AABB.getCorner(AxisAlignedBox::NEAR_RIGHT_TOP)) / 4;
 
    // Is the camera facing that point? If not, hide the overlay and return.
    Ogre::Plane cameraPlane = Plane(Vector3(camera->getDerivedOrientation().zAxis()), camera->getDerivedPosition());
    if(cameraPlane.getSide(point) != Plane::NEGATIVE_SIDE)
    {
	setVisible(false);
        overlay->hide();
        return;
    }
 
    // Derive the 2D screen-space coordinates for that point
    point = camera->getProjectionMatrix() * (camera->getViewMatrix() * point);
 
    // Transform from coordinate space [-1, 1] to [0, 1]
    Real x = (point.x / 2) + 0.5f;
    Real y = 1 - ((point.y / 2) + 0.5f);
 
    // Update the position (centering the text)
    container->setPosition(x - (textDim.x / 2), y);
    setVisible(true);
    overlay->show();
}
void MovableTextOverlay::_getMinMaxEdgesOfTopAABBIn2D(Ogre::Real& MinX, Ogre::Real& MinY, Ogre::Real& MaxX, Ogre::Real& MaxY)
{
	const Ogre::Camera* mpCam = mAttrs->getCamera();

	MinX = 0;
	MinY = 0;
	MaxX = 0;
	MaxY = 0;

	Ogre::Real X[4];// the 2D dots of the AABB in screencoordinates
	Ogre::Real Y[4];

	if (!mpMov->isInScene())
	   return;

	const Ogre::AxisAlignedBox &AABB = mpMov->getWorldBoundingBox(true);// the AABB of the target
	const Ogre::Vector3 CornersOfTopAABB[4] = {	AABB.getCorner(AxisAlignedBox::FAR_LEFT_TOP),
										AABB.getCorner(AxisAlignedBox::FAR_RIGHT_TOP),
										AABB.getCorner(AxisAlignedBox::NEAR_LEFT_TOP),
										AABB.getCorner(AxisAlignedBox::NEAR_RIGHT_TOP)};

	Ogre::Vector3 CameraPlainNormal = mpCam->getDerivedOrientation().zAxis();//The normal vector of the plaine.this points directly infront of the cam

	Ogre::Plane CameraPlain = Plane(CameraPlainNormal,mpCam->getDerivedPosition());//the plaine that devides the space bevor and behin the cam

	for (int i = 0; i < 4; i++)
	{
	  X[i] = 0;
	  Y[i] = 0;
	  
	  _getScreenCoordinates(CornersOfTopAABB[i],X[i],Y[i]);// transfor into 2d dots

	  
	  if (CameraPlain.getSide(CornersOfTopAABB[i]) == Plane::NEGATIVE_SIDE)
	  {
	     
		 if (i == 0)// accept the first set of values, no matter how bad it might be.
		 {
			MinX = X[i];
			MinY = Y[i];
			MaxX = X[i];
			MaxY = Y[i];
		 }
		 else// now compare if you get "better" values
		 {
			if (MinX > X[i])// get the x minimum
			{
			   MinX = X[i];
			}
			if (MinY > Y[i])// get the y minimum
			{
			   MinY = Y[i];
			}
			if (MaxX < X[i])// get the x maximum
			{
			   MaxX = X[i];
			}
			if (MaxY < Y[i])// get the y maximum
			{
			   MaxY = Y[i];
			}
		 }
	  }
	  else
	  {
		MinX = 0;
		MinY = 0;
		MaxX = 0;
		MaxY = 0;
		break;
	  }
	}
} 
Beispiel #5
0
void TextCanvasBatch::update()
{
    std::vector<TextCanvas*> visibleTexts;

    for( TextCanvasMap::iterator i = mTextMap.begin(); i != mTextMap.end(); i++)
    {
        if( !i->second->mTarget ) continue;
        if( !i->second->mTarget->isInScene() ) continue;

        // Derive the average point between the top-most corners of the object's bounding box
        const Ogre::AxisAlignedBox &AABB = i->second->mTarget->getWorldBoundingBox(true);
        Ogre::Vector3 point = (AABB.getCorner(Ogre::AxisAlignedBox::FAR_LEFT_TOP)
            + AABB.getCorner(Ogre::AxisAlignedBox::FAR_RIGHT_TOP)
            + AABB.getCorner(Ogre::AxisAlignedBox::NEAR_LEFT_TOP)
            + AABB.getCorner(Ogre::AxisAlignedBox::NEAR_RIGHT_TOP)) / 4;

        // Is the camera facing that point? If not, hide the overlay and return.
        Ogre::Plane cameraPlane = Ogre::Plane(Ogre::Vector3(mCamera->getDerivedOrientation().zAxis()), mCamera->getDerivedPosition());
        if(cameraPlane.getSide(point) != Ogre::Plane::NEGATIVE_SIDE)
            continue;

        Ogre::Real distance = mCamera->getDerivedPosition().distance(point);

        // scale [40, 400] to [5, 0]: (-5 / 360)x + (50 / 9) = y
        distance = Ogre::Math::Floor((-10 / 360.0)*distance + (100 / 9.0));

        if(distance < 0) distance = 0; 
        else if(distance > 10) distance = 10;

        // Derive the 2D (x,y) screen-space coordinates for that point
        point = mCamera->getProjectionMatrix() * (mCamera->getViewMatrix() * point);
        Ogre::Real x = (point.x / 2) + 0.5f;
        Ogre::Real y = 1 - ((point.y / 2) + 0.5f);

        i->second->mPosition = Ogre::Vector3(x, y, distance);

        visibleTexts.push_back( i->second ); 
    }

    mCanvas.clear();

    const Ogre::uint charPerLine = 24;
    const Ogre::uint maxCharPerLine = 36;

    for(std::vector<TextCanvas*>::iterator i = visibleTexts.begin(); i != visibleTexts.end(); i++)
    {
        int x = (*i)->mPosition.x * mCamera->getViewport()->getActualWidth();
        int y = (*i)->mPosition.y * mCamera->getViewport()->getActualHeight();

        Ogre::uint fontSize = (*i)->mPosition.z + 10;
        Ogre::Real fontHeight = mAtlas.getFontMetrics(mFont, fontSize).height;
        Ogre::Real avgAdvance = mAtlas.getGlyphInfo(mFont, fontSize, 'x').advance;
        Ogre::Real spaceAdvance = mAtlas.getGlyphInfo(mFont, fontSize, 'i').advance;
        Ogre::Real pen = x = x - (std::min((*i)->mCaption.length(), charPerLine) * avgAdvance) / 2;

        y -= ((*i)->mCaption.length() / charPerLine) * fontHeight;

        Ogre::uint lineCharCount = 0;

        for(Ogre::String::const_iterator j = (*i)->mCaption.begin(); j != (*i)->mCaption.end(); j++)
        {
            lineCharCount++;

            if(*j == ' ')
            {
                if(lineCharCount > charPerLine)
                {
                    pen = x;
                    y += fontHeight;
                    lineCharCount = 0;
                }
                else
                {
                    pen += spaceAdvance;
                }
                continue;
            }

            if(lineCharCount > maxCharPerLine)
            {
                pen = x;
                y += fontHeight;
                lineCharCount = 0;
            }

            GlyphInfo glyph = mAtlas.getGlyphInfo(mFont, fontSize, (*j));
            mCanvas.drawGlyph(glyph, glyph.bearingX + pen + 1, y - glyph.bearingY + 1, glyph.texInfo.width, glyph.texInfo.height, Ogre::ColourValue(0, 0, 0, 0.7));
            mCanvas.drawGlyph(glyph, glyph.bearingX + pen, y - glyph.bearingY, glyph.texInfo.width, glyph.texInfo.height, toColour<Ogre::ColourValue>( (*i)->mColour ));
            pen += glyph.advance;
        }
    }
}
Beispiel #6
0
Ogre::Real RoomSurface::distanceAbove(Ogre::Vector3 position) {
  std::pair<Ogre::Matrix4, Ogre::Plane> world_transform_and_plane = getWorldTransformAndPlane(0.0);
  const Ogre::Plane plane = world_transform_and_plane.second;
  return plane.getDistance(position);
}
void EC_OgreMovableTextOverlay::Update()
{
    if (!node_ || !visible_ || !placeable_ || renderer_.expired())
        return;

    if(!node_->isInSceneGraph())
    {
        overlay_->hide();
        return;
    }

    Ogre::Camera* camera = renderer_.lock()->GetCurrentCamera();
    if (!camera)
        return;

    Ogre::Viewport* viewport = camera->getViewport();
    Ogre::Vector3 point = node_->_getDerivedPosition();

    // Is the camera facing that point? If not, hide the overlay and return.
    Ogre::Plane cameraPlane = Ogre::Plane(Ogre::Vector3(camera->getDerivedOrientation().zAxis()), camera->getDerivedPosition());
    if(cameraPlane.getSide(point) != Ogre::Plane::NEGATIVE_SIDE)
    {
        overlay_->hide();
        return;
    }

    // Hide the overlay if it's too far.
    Ogre::Vector3 res = camera->getDerivedPosition() - point;
    float distance = sqrt(res.x * res.x + res.y * res.y + res.z * res.z);

    if (distance > MAX_VISIBILITY_DISTANCE)
    {
        overlay_->hide();
        return;
    }

    // Set the alpha channel for the overlay.
    if (materialHasAlpha_)
        SetAlphaChannelIntensity(distance);

    // Derive the 2D screen-space coordinates for node point.
    point = camera->getProjectionMatrix() * (camera->getViewMatrix() * point);

    // Transform from coordinate space [-1, 1] to [0, 1]
    float x = (point.x / 2) + 0.5f;
    float y = 1 - ((point.y / 2) + 0.5f);

    // Update the position (centering the text)
    container_->setPosition(x - (textDim_.x / 2), y);

    // Update the dimensions also if the window is resized.
    if (windowWidth_ != viewport->getActualWidth() ||
        windowHeight_ != viewport->getActualHeight())
    {
        windowWidth_ = viewport->getActualWidth();
        windowHeight_ = viewport->getActualHeight();
        
        textDim_ = GetTextDimensions(text_);
        container_->setDimensions(textDim_.x, textDim_.y);
    }

    ///\todo Scale the text and width and height of the container?
//        text_element_->setMetricsMode(Ogre::GMM_RELATIVE);
//        text_element_->setPosition(textDim_.x, textDim_.y);
//        text_element_->setPosition(textDim_.x / 10, 0.01);
//        text_element_->setCharHeight(max_x - min_x/*2*0.0175f*///);

    overlay_->show();
}
Beispiel #8
0
	void QCharacterController::update(float delta)
	{
		mAccumulation += delta;

		while(mAccumulation>=mTimeStep)
		{
			btVector3 upVectorFinal = QVector3Nx(mPhysicsManager->getLocalGravity(Vector3(NxVector3(mController->getPosition()))));//gmgr->gvmgr->getGravityLocalCCT(NxVector3(mController->getPosition()));
			NxVec3 GravityVector = upVectorFinal;
			upVectorFinal.normalize();
			upVectorFinal*=-1;

			bool testing = false;

			NxVec3 opo = NxVec3(0,0,0);
			NxVec3 fpo = NxVec3(0,0,0);

			float abbc = mPhysicsManager->getLocalGravity(NxVector3(mController->getPosition()+mController->getUpVector())).length();//gmgr->gvmgr->getGravityLocalCCT(NxVector3(mController->getPosition()+mController->getUpVector())).magnitude();
			q_1 = q_2;

			if(mController->getUpVector()!=upVectorFinal&&Ogre::Degree(NxVector3(mController->getUpVector()).angleBetween(NxVector3(upVectorFinal)))>Ogre::Degree(0.075f)&&abbc>0.2f)
			{
				testing = true;

				Ogre::Vector3 up1 = NxVector3(mController->getUpVector());

				//std::cout<<"pos1: "<<mController->cctp[0]->getPosition().x()<<"\n";
				mController->setUpVector(upVectorFinal,mTimeStep);
				//std::cout<<"pos2: "<<mController->cctp[0]->getPosition().x()<<"\n";

				Ogre::Vector3 up2 = NxVector3(mController->getUpVector());
				Ogre::Quaternion q2 = up1.getRotationTo(up2,Ogre::Vector3::UNIT_X);
				q_2 = Quaternion(q2*q_1.toOgre());
			}

			//dnode02->setOrientation(Ogre::Quaternion::IDENTITY);
			//dnode02->setDirection(NxVector3(mController->getUpVector()),Ogre::SceneNode::TS_LOCAL,Ogre::Vector3::UNIT_Y);

			opo = mController->position;

			bool mMidair = false;// = inAir();
			float playerSpeed = 0;

			if(mController->move_)
			{
				Ogre::Vector3 v3 = Ogre::Vector3(moveV.x,moveV.y,moveV.z);
				Ogre::Plane pln = Ogre::Plane(NxVector3(mController->getUpVector()),0);
				pln.projectVector(v3);
				v3.normalise();
				moveV = Ogre::Vector3(moveV.x,moveV.y,moveV.z);
				/// run = 6.225
				/// walk = 2.225
				float spdd = mPlayerSpeedStart*(1-mPlayerSpeedInterpolation)+mPlayerSpeedTop*(mPlayerSpeedInterpolation);//7.0f;//2.225f*(1-runTimer) + 6.225*runTimer

				if(abbc<0.2)
				{
					mController->move(NxVec3(moveV.x,moveV.y,moveV.z)*mTimeStep*spdd,true,mTimeStep,true);
				}
				else
				{
					//std::cout<<"Try move....\n";
					mController->move(NxVec3(moveV.x,moveV.y,moveV.z)*mTimeStep*spdd,true,mTimeStep);
				}
				fpo = mController->position;
				playerSpeed = Ogre::Math::Abs((fpo-opo).length());
				//playerMotionDir = NxVector3(fpo-opo);
				//std::cout<<"Speed: "<<playerSpeed/(gmgr->tmgr->getTimeSpeed()/60.0f)<<"\n";
			}
			else
			{
				playerSpeed = 0;
				//playerMotionDir = Ogre::Vector3(0,0,0);
			}

			mMidair = inAir();

			float lastSpeed = mPlayerSpeedLast;
			mPlayerSpeedLast = playerSpeed;

			if(mPlayerSpeedLast>lastSpeed)
			{
				mPlayerSpeedInterpolation+=(mTimeStep/mPlayerSpeedAccel);
				mGracePeriod = 0;
			}
			else if((mPlayerSpeedLast<mPlayerSpeedStart*mTimeStep||mHittingGround)&&!mMidair)
			{
				// we give a little bit of padding so if a gravity issue ir something stops it for a frame
				// it doesn't slow abruptly.
				++mGracePeriod;
				if(mGracePeriod>=2)
				{
					mPlayerSpeedInterpolation=0;
				}
			}
			else
			{
				mGracePeriod = 0;
			}

			if(mMidair)
			{
				//mPlayerSpeedLast = 0;
			}

			if(mPlayerSpeedInterpolation<0)
			{
				mPlayerSpeedInterpolation = 0;
			}
			if(mPlayerSpeedInterpolation>1)
			{
				mPlayerSpeedInterpolation = 1;
			}


			NxVec3 gravityCont = QVector3Nx(mPhysicsManager->getLocalGravity(NxVector3(mController->getPosition()+mController->getUpVector())))*0.9f;//gmgr->gvmgr->getGravityLocalCCT(NxVector3(mController->getPosition()+mController->getUpVector()))*0.9f;
			NxVec3 gcN = gravityCont;
			gcN.normalize();
			if(NxVector3(gcN).angleBetween(Ogre::Vector3(0,1,0))<Ogre::Degree(1))
			{
				gravityCont = NxVec3(0,1,0)*gravityCont.length();
			}
			if(NxVector3(gcN).angleBetween(Ogre::Vector3(0,-1,0))<Ogre::Degree(1))
			{
				gravityCont = NxVec3(0,-1,0)*gravityCont.length();
			}

				//||NxVector3(gravityCont).angleBetween(Ogre::Vector3(0,-1,0))<Ogre::Degree(1))
			if(mIsJumping)
			{
				gravityCont = gravityCont - gravityCont*mJumpFactor;
				mJumpFactor -= 1.f*static_cast<Real>(mTimeStep);
				if(mJumpFactor<0)
				{
					mJumpFactor = 0;
					mIsJumping = false;
				}

			}
			NxVec3 ogp = mController->getPosition();

			float ff = 1.0;
			if(testing )
			{
				ff=0.5f*(1-mController->mUpInterp)+(mController->mUpInterp*1.0f);
				mPlayerGravityInterpolation = mPlayerGravityInterpolation/5;
			}

			if(abbc>0.2f)
			{
				mController->move(ff*((gravityCont*(mPlayerGravityBase*(1-mPlayerGravityInterpolation)+mPlayerGravityTerminal*(mPlayerGravityInterpolation)))*mTimeStep),false,mTimeStep);
			}

			NxVec3 pogp = mController->getPosition();

			float lastGravity = mPlayerGravityLast;
			mPlayerGravityLast = btVector3(ogp-pogp).length();

			if(mMidair&&!mHittingGround)
			{
				mGroundImpact = mPlayerGravityLast/mTimeStep*1.45f;
			}

			if(mPlayerGravityLast>lastGravity)
			{
				mPlayerGravityInterpolation+=(mTimeStep/mPlayerGravityAccel);
			}
			else if(mPlayerGravityLast<mPlayerGravityBase*mTimeStep)
			{
				mPlayerGravityInterpolation=0;
			}

			if(mPlayerGravityInterpolation<0)
			{
				mPlayerGravityInterpolation = 0;
			}
			if(mPlayerGravityInterpolation>1)
			{
				mPlayerGravityInterpolation = 1;
			}


			if(mIsJumping&&mJumpFactor>1)
			{
				NxVec3 fgp = mController->getPosition();
				Ogre::Vector3 dirT = NxVector3(fgp-ogp);
				dirT.normalise();
				Ogre::Vector3 upVC = NxVector3(gravityCont*mTimeStep*ff);
				upVC.normalise();
				if(!dirT.directionEquals(upVC,Ogre::Radian(Ogre::Degree(45.0f))))
				{
					mJumpFactor = 1;
				}
			}
			//Ogre::Vector3 pMoDir = NxVector3(opo - player->position);

			// takes gravity into account
			//Ogre::Vector3 velocity = pMoDir/deltaTT;
			//float vel[] = {velocity.x,velocity.y,velocity.z};
			//alListenerfv(AL_VELOCITY,vel);
			if(mCrouching)
			{
				if(mCrouched)
				{
					float oldCrouch = mController->offset;
					mCrouchLevel+=mTimeStep*1.f;
					if(mCrouchLevel>mOffset)
					{
						mCrouchLevel = mOffset;
						mCrouched = false;
						mCrouching = false;
					}
					mController->offset = mCrouchLevel;
					if(!mController->setPosition(mController->getPosition(),false,mController->getUpVector(),false))
					{
						mController->offset = oldCrouch;
						mCrouchLevel = oldCrouch;
					}
					else
					{

					}
				}
				else
				{
					float oldCrouch = mController->offset;
					mCrouchLevel-=mTimeStep*0.5f;
					if(mCrouchLevel<0.06f)
					{
						mCrouchLevel = 0.06f;
						mCrouched = true;
						mCrouching = false;
					}
					mController->offset = mCrouchLevel;
					if(!mController->setPosition(mController->getPosition(),false,mController->getUpVector(),false))
					{
						mController->offset = oldCrouch;
						mCrouchLevel = oldCrouch;
					}
					else
					{

					}
				}
			}


			if(mInAirLast2&&!mHittingGround)
			{
				mHittingGround = true;
				if(mGroundImpact>0.05&&false)
				{
				mGroundImpactSpd = mGroundImpact;
				mGroundImpact/=40.f;
				}
				else
				{
					mHittingGround = false;
					mGroundImpactSpd = 0.f;
					mGroundImpact = 0.f;
				}
				//mGroundImpact
			}

			if(mImpactLevel>0)
			{
				//float recoverSpeed = 1.0f;

				mImpactLevel-=mTimeStep*1.6f;
				if(mImpactLevel<0)
				{
					mImpactLevel = 0;
				}
			}

			if(mHittingGround)
			{
				float spdC = 1.0f;
				spdC = 0.9f*((mGroundImpact/(mGroundImpactSpd/40)))+(0.095f*(1-(mGroundImpact/(mGroundImpactSpd/40))));
				mImpactLevel+=mTimeStep*mGroundImpactSpd*spdC;
				if(mImpactLevel>0.8f)
				{
					mImpactLevel = 0.8f;
				}
				mGroundImpact-=mTimeStep*(mGroundImpactSpd*0.5f)*spdC;
				if(mGroundImpact<0)
				{
					mGroundImpact = 0;
					mHittingGround = false;
				}
			}


			if(mBobSwap)
			{
				if(!mMidair)
					mBobPeriod+=mPlayerSpeedLast*1.2f;
			}
			else
			{
				if(!mMidair)
					mBobPeriod-=mPlayerSpeedLast*1.2f;
			}
			if(abs(mBobPeriod)>=1.0f)
			{
				if(mBobPeriod>0)
				{
					mBobPeriod = 0.99f;
				}
				else
				{
					mBobPeriod = -0.99f;
					mBobLR = !mBobLR;
					if(mBobLRPeriod>0)
					{
						mBobLRPeriod = 1.99f;
					}
					else
					{
						mBobLRPeriod = -1.99f;
					}

				}
				mBobSwap = !mBobSwap;
			}

			NxVec3 upvv = mController->getUpVector();
			upvv*=(mImpactLevel+mBobPeriod*0.f);
			Vector3 right1 = Ogre::Root::getSingletonPtr()->getSceneManager("mSceneManager")->getCamera("mMainCam")->getDerivedRight();


			if(mBobLR)
			{
				if(!mMidair)
					mBobLRPeriod -= mPlayerSpeedLast*1.2f;
			}
			else
			{
				if(!mMidair)
					mBobLRPeriod += mPlayerSpeedLast*1.2f;
			}

			if(mBobLRPeriod>0)
			{
				right1*=(0.0625f*((mBobLRPeriod)));
			}
			else
			{
				right1*=(0.0625f*((mBobLRPeriod)));
			}
			right1*=0;

			p_2 = p_1;
			//p_1 = Vector3(mController->getEyePosition().x(),mController->getEyePosition().y(),mController->getEyePosition().z());
			p_1 = Vector3(mController->getEyePosition().x()-upvv.x()-right1.x,mController->getEyePosition().y()-upvv.y()-right1.y,mController->getEyePosition().z()-upvv.z()-right1.z);
			// if our speed has gone up then increment the interpolation thingy

			mAccumulation -= mTimeStep;
		}

		mInterpolation = mAccumulation/mTimeStep;
	}