Example #1
0
int TCamera::setAttribute (const string& rktNAME, NAttribute nVALUE, EAttribType eTYPE)
{

  if ( rktNAME == "up" )
  {
    if ( eTYPE == FX_VECTOR )
    {
      setUp (*((TVector*) nVALUE.pvValue));
    }
    else
    {
      return FX_ATTRIB_WRONG_TYPE;
    }
  }
  else if ( rktNAME == "look_at" )
  {
    if ( eTYPE == FX_VECTOR )
    {
      setLookAt (*((TVector*) nVALUE.pvValue));
    }
    else
    {
      return FX_ATTRIB_WRONG_TYPE;
    }
  }
  else
  {
    return TEntity::setAttribute (rktNAME, nVALUE, eTYPE);
  }

  return FX_ATTRIB_OK;

}  /* setAttribute() */
Example #2
0
void Camera::updateCameraRotation() {

	double xPos, yPos;
	glfwGetCursorPos(m_window, &xPos, &yPos); // get current mouse position
	
	// if mouse still in window center, no need to recalculate view matrix
	if (xPos == m_windowWidth / 2 && yPos == m_windowHeight / 2) {
		return;
	}
	centerMouse();

	m_horizontalAngle += float(m_windowWidth / 2 - xPos) * m_mouseSpeed;
	m_verticalAngle += float(m_windowHeight / 2 - yPos) * m_mouseSpeed;

	glm::vec3 oldLookIn = getLookAt() - getCenter();
	glm::vec3 lookInHorizontal = glm::vec3(sin(m_horizontalAngle), oldLookIn.y, cos(m_horizontalAngle));
	glm::vec3 lookInVertical = glm::vec3(oldLookIn.x * cos(m_verticalAngle), sin(m_verticalAngle), oldLookIn.z * cos(m_verticalAngle));
	glm::vec3 newLookIn = glm::normalize(lookInHorizontal + lookInVertical);
	
	setLookAt(getCenter() + newLookIn);

	float rightHorizontalAngle = m_horizontalAngle - PI / 2.0f;
	setRight(glm::vec3(sin(rightHorizontalAngle), getRight().y, cos(rightHorizontalAngle)));

	setUp(glm::normalize(glm::cross(getRight(), newLookIn)));
}
Example #3
0
void Camera::updateCameraMovement(double prevTime) {
	double currTime = glfwGetTime();
	float deltaTime = float(currTime - prevTime);

	glm::vec3 position = getCenter();
	glm::vec3 lookIn = getLookAt() - getCenter();
	glm::vec3 forward = glm::vec3(lookIn.x, 0, lookIn.z);

	bool moved = false;

	// Move forward
	if (glfwGetKey(m_window, GLFW_KEY_W) == GLFW_PRESS){
		position += forward * deltaTime * m_moveSpeed;
		moved = true;
	}
	// Move backward
	if (glfwGetKey(m_window, GLFW_KEY_S) == GLFW_PRESS){
		position -= forward * deltaTime * m_moveSpeed;
		moved = true;
	}
	// Strafe right
	if (glfwGetKey(m_window, GLFW_KEY_D) == GLFW_PRESS){
		position += getRight() * deltaTime * m_moveSpeed;
		moved = true;
	}
	// Strafe left
	if (glfwGetKey(m_window, GLFW_KEY_A) == GLFW_PRESS){
		position -= getRight() * deltaTime * m_moveSpeed;
		moved = true;
	}

	setCenter(position);
	setLookAt(getCenter() + lookIn);
}
Example #4
0
void Camera::tic(uint64_t time) {
  vec3 temp1, temp2;
  vec3 tempVec;
   mat4 tempMatrix;
   float pathAccOffset = 0.0;

  // Find the angle between the two paths
// float rotAngle = m_pathAngle * (m_head->getPosition() - m_pathPos).Length()
// / ((m_head->getPosition() - m_tail->getPosition()).Length()
// - CAMERA_LOOK_AHEAD_DISTANCE);

  // If we are turning our forward, but the angle between ourselves and
  // the intended is close enough, stop turning to allow for rotation
  /*if (m_turning && .5 > 
      angleBetween(m_head->getPosition() - m_tail->getPosition(), 
		   m_pathRef - m_pathPos)) {
		   m_turning = false;
    m_pathPos = m_pathRef - ((m_head->getPosition() 
			      - m_tail->getPosition()).Normalized() 
			     * CAMERA_LOOK_AHEAD_DISTANCE);
    //  m_pathUp = m_tail->getUp();
    //} 
  
  // If we aren't turning, its safe to rotate
  //if (!m_turning) {*/
     temp1 = m_tail->getUp() * (m_head->getPosition() - m_pathRef).Length() / 
	(m_head->getPosition() - m_tail->getPosition()).Length();
     temp2 = m_head->getUp() * (m_pathRef - m_tail->getPosition()).Length() / 
	(m_head->getPosition() - m_tail->getPosition()).Length();
     m_pathUp = (temp1 + temp2).Normalized();
   //  }

  // Move our reference point down the path
  if (m_boosting) {
     m_boostTime += time;
     if (m_boostTime > 2000) {
m_boostTime = 2000;
     }


     pathAccOffset = (CAMERA_BOOST_ACC * m_boostTime);

  }
  else {
     m_boostTime -= time * 3;
     if(m_boostTime < 0) {
	m_boostTime = 0;
     }

  }

  m_pathRef += (((m_head->getPosition() - m_pathRef).Normalized()) * 
		   ((time * CAMERA_DEF_VELOCITY) + pathAccOffset));
  
  calculateSide();
  tempVec = (m_pathRef - m_pathPos).Normalized();
  m_pathPos = m_pathRef - (tempVec * CAMERA_LOOK_AHEAD_DISTANCE);

  setLookAt();
}
Example #5
0
void DisplayItem::touchEvent(QTouchEvent* event) {
  if (event->touchPointStates() & Qt::TouchPointPressed) {
    if (event->touchPoints().size() == 2) {
      QPointF p1 = mapFromScreen(event->touchPoints()[0].pos());
      QPointF p2 = mapFromScreen(event->touchPoints()[1].pos());

      m_distance = QVector2D(p1 - p2).length();
    }
  }

  if (event->touchPoints().size() == 1) {
    if (flickable()) {
      QPointF p1 = mapFromScreen(event->touchPoints().front().lastPos());
      QPointF p2 = mapFromScreen(event->touchPoints().front().pos());

      setLookAt(effectiveLookAt() - p2 + p1);
    } else
      event->ignore();
  } else if (event->touchPoints().size() == 2) {
    QPointF p1 = mapFromScreen(event->touchPoints()[0].pos());
    QPointF p2 = mapFromScreen(event->touchPoints()[1].pos());

    qreal distance = QVector2D(p1 - p2).length();

    setFactor(factor() * distance / m_distance);
  } else
    event->ignore();
}
Example #6
0
FreeCamera::FreeCamera(glm::vec3 pos, glm::vec3 center, float acc, float max_speed) :
	BaseCamera(pos, center, 4), acc(acc), max_speed(max_speed) {
	keys[FORWARD] = 'w';
	keys[BACK] = 's';
	keys[LEFT] = 'a';
	keys[RIGHT] = 'd';
	setLookAt(center);
	min_limit = 0;
	max_limit = 100000000000;
}
Example #7
0
void Camera::turn (float const x, float const y, float const speed){
	glm::vec3 newVec3;
	glm::vec3 right;

	//Translate to the origin
	translateOrigin();

	//calculate right vector

	//Rotate about x
	setLookAt(glm::mat3(glm::rotate(speed * y, getRight()))*lookAt);

	//Rotate about y
	glm::vec3 currentUp = getCurrentUp();
	setLookAt(glm::mat3(glm::rotate(speed * x, currentUp))*lookAt);

	//Translate back to previous position
	translatePosition();
}
Example #8
0
void
Camera::calcLookAt()
{
    // this is true when a "lookat" is not used in the config file
    if (m_lookAt.x != FLT_MAX)
    {
        setLookAt(m_lookAt);
        m_lookAt.set(FLT_MAX, FLT_MAX, FLT_MAX);
    }
}
void Camera::dragMouse( int x, int y )
{
	Vec3f mouseDelta   = Vec3f(x,y,0.0f) - mLastMousePosition;
	mLastMousePosition = Vec3f(x,y,0.0f);

	switch(mCurrentMouseAction)
	{
	case kActionTranslate:
		{
			calculateViewingTransformParameters();

			double xTrack =  -mouseDelta[0] * kMouseTranslationXSensitivity;
			double yTrack =  mouseDelta[1] * kMouseTranslationYSensitivity;

			Vec3f transXAxis = mUpVector ^ (mPosition - mLookAt);
			transXAxis /= sqrt((transXAxis*transXAxis));
			Vec3f transYAxis = (mPosition - mLookAt) ^ transXAxis;
			transYAxis /= sqrt((transYAxis*transYAxis));

			setLookAt(getLookAt() + transXAxis*xTrack + transYAxis*yTrack);
			
			break;
		}
	case kActionRotate:
		{
			float dAzimuth		=   -mouseDelta[0] * kMouseRotationSensitivity;
			float dElevation	=   mouseDelta[1] * kMouseRotationSensitivity;
			
			setAzimuth(getAzimuth() + dAzimuth);
			setElevation(getElevation() + dElevation);

			if (getAzimuth() > M_PI) 
				mAzimuth -= 2.0*M_PI;
			if (getElevation() > M_PI) 
				mElevation -= 2.0*M_PI;

			fprintf(stderr, "az %f, elev %f\n", mAzimuth, mElevation);

			break;
		}
	case kActionZoom:
		{
			float dDolly = -mouseDelta[1] * kMouseZoomSensitivity;
			setDolly(getDolly() + dDolly);
			break;
		}
	case kActionTwist:
		// Not implemented
	default:
		break;
	}

}
Example #10
0
Camera::Camera(void)
{
	_lookAt = std::vector<GLfloat>(3,0.0f);
	_distance = std::vector<GLfloat>(3,0.0f);
	_extraRot = std::vector<GLfloat>(3,0.0f);

	setLookAt(0.0f,0.0f,0.0f);

	_distance[0] = 4.0f;
	_distance[1] = 1.0f;
	_distance[2] = 4.0f;
}
Example #11
0
void Camera::moveForward(float units){
	glm::vec3 newPosition = position - lookAt;
	newPosition = glm::normalize(newPosition);

	//move both position and lookAt
	setPosition(position.x - (units*newPosition.x),
			position.y - (units*newPosition.y),
			position.z - (units*newPosition.z));
	setLookAt(lookAt.x - (units*newPosition.x),
			lookAt.y - (units*newPosition.y),
			lookAt.z - (units*newPosition.z));

}
Example #12
0
Camera::Camera(GLFWwindow *window) {
	m_window = window;
	getWindowDimensions();
	centerMouse();

	initVars();

	setCenter(glm::vec3(0, 0, 5));
	setLookAt(glm::vec3(0, 0, 4));
	setUp(glm::vec3(0, 1, 0));
	setRight(glm::vec3(1, 0, 0));
	updateViewMatrix();
}
Example #13
0
SpotLight::SpotLight( const Vector3f& position, const Vector3f& center, const Vector3f& up,
          float fovYRadians, float zNear, float zFar, float aspect,
          const Vector3f& color, const Vector3f& distanceFalloff ) :

    m_fovYRadians( fovYRadians ),
    m_zNear( zNear ),
    m_zFar( zFar ),

    m_aspect( aspect ),

    m_color( color ),
    m_distanceFalloff( distanceFalloff )

{
    setLookAt( position, center, up );
}
Example #14
0
void bsCamera::animate(void)
{
#if 0
	if(mNumFrames>0 && mAnimation)
	{
		double pos[3],dir[3],up[3];
		int gotpos, gotdir;
		GetCamera(mAnimation,mCurrentTime,&gotpos,pos,&gotdir,dir,up);
		if(gotpos) setPosition(Vec3f(pos[0],pos[1],pos[2]));
		if(gotdir)
		{
			setLookAt(Vec3f(pos[0]+dir[0],pos[1]+dir[1],pos[2]+dir[2]));
			setUpVector(Vec3f(up[0],up[1],up[2]));
		}
	}
#endif
}
Example #15
0
void Camera::moveRight(float units){
	//Translate to origin
	translateOrigin();

	//Calculate right vector
	glm::vec3 right = getRight();

	//Normalize right vector
	right = glm::normalize(right);
	glm::mat4 transMat = glm::translate(right*units);

	//Translate back
	translatePosition();

	//move both position and lookAt
	setLookAt(glm::vec3(transMat*glm::vec4(lookAt, 1)));
	setPosition(glm::vec3(transMat*glm::vec4(position, 1)));

}
Example #16
0
//----------------------------------------
ofx2DCam::ofx2DCam(){
    setLookAt(OFX2DCAM_FRONT);
    lastTap	= 0;
    
    bApplyInertia =false;
    bDoTranslate = false;

    bDistanceSet = false;
    bDoScale = false;
  
    reset();
    parameters.setName("ofx2Dcam");
    parameters.add(bEnableMouse.set("Enable Mouse Input", false));
    parameters.add(dragSensitivity.set("Drag Sensitivity", 1, 0, 3));
    parameters.add(scrollSensitivity.set("Scroll Sensitivity", 10, 0, 30));
    parameters.add(drag.set("Drag", 0.9, 0, 1));
    parameters.add(farClip.set("Far Clip", 2000, 5000, 10000));
    parameters.add(nearClip.set("Near Clip", -1000, -5000, 10000));
    
    bEnableMouse.addListener(this, &ofx2DCam::enableMouseInputCB);
    enableMouseInput();

}
Camera::Camera()
{
	setPerspective(glm::radians(60.0f), 1280.0f / 720.0f, 0.1f, 1000.f);
	setLookAt(vec3(-5, 10, 4), vec3(4, 0, 4), vec3(0, 1, 0));
}
Example #18
0
void Camera::dragMouse( int x, int y )
{
	Vec3f mouseDelta   = Vec3f(x,y,0.0f) - mLastMousePosition;

	switch(mCurrentMouseAction)
	{
	case kActionTranslate:
		{
			// Determine mouse movement
			double xTrack =  -mouseDelta[0] * kMouseTranslationXSensitivity;
			double yTrack =  mouseDelta[1] * kMouseTranslationYSensitivity;

			// Recalculate stuff if needed
			if (m_bDirtyTransform)
			{
				updateTransform();
			}

			// Determine directions of motion in scene space
			Vec3f direction = m_vPosition - m_vLookAt;
			Vec3f transXAxis = m_vUpVector ^ direction;
			transXAxis /= sqrt((transXAxis*transXAxis));
			Vec3f transYAxis = direction ^ transXAxis;
			transYAxis /= sqrt((transYAxis*transYAxis));

			// Move the camera's look-at point
			setLookAt(getLookAt() + transXAxis*xTrack + transYAxis*yTrack);
			
			break;
		}
	case kActionRotate:
		{
			// Store the rotation in this quarternion
			float quat[4];

			// Get the mouse coordinates in a range between -1.0 and 1.0
			float viewHalfWidth = (m_iViewportWidth / 2.f), viewHalfHeight = (m_iViewportHeight / 2.f);
			float oldX = mLastMousePosition[0] * 2.f / (m_iViewportWidth - 1) - 1.f,
				  oldY = mLastMousePosition[1] * 2.f / (m_iViewportHeight - 1) - 1.f,
				  newX = x * 2.f / (m_iViewportWidth - 1) - 1.f,
				  newY = y * 2.f / (m_iViewportHeight - 1) - 1.f;

			// Get the quaternion to rotate around, from the trackball code.
			trackball( quat, oldX, -oldY, newX, -newY );

			// Add the new quaternion to the current one.
			float oldQuat[4];
			memcpy(oldQuat, m_fQuat, sizeof(float) * 4);
			//add_quats(oldQuat, quat, m_fQuat);
			add_quats(quat, oldQuat, m_fQuat);

			// Update the transform parameters.
			updateTransform();

			break;
		}
	case kActionZoom:
		{
			// Determine dolly movement.
			float fDollyDelta = -mouseDelta[1] * kMouseZoomSensitivity;

			// Add to dolly
			setDolly(getDolly() + fDollyDelta);

			updateTransform();

			break;
		}
	case kActionTwist:
		{
			break;
		}
	default:
		break;
	}

	mLastMousePosition = Vec3f(x,y,0.0f);

}
Example #19
0
void nRenderer::bindCam(nCamera *c) {
	activeCam = c;
	if(c) {
		setLookAt(c->getPosition(), c->getLookAt());
	}
}
Example #20
0
void DisplayItem::mouseMoveEvent(QMouseEvent* event) {
  if (!m_buttonDown) return event->ignore();

  QPointF p = mapFromScreen(event->pos());
  setLookAt(effectiveLookAt() - p + m_startPoint);
}
Example #21
0
void CCCameraBase::setLookAtY(const float y)
{
    setLookAt( CCVector3( lookAt.x, y, lookAt.z ) );
}
Example #22
0
void DisplayItem::focusedObjectPositionChanged() {
  setLookAt(-focusedObject()->matrix() * QPointF(0, 0));
}