Exemple #1
0
/*
 * Get the perpective camera that includes the triangle in 3D.
 *
 *    equi_image: original equirectangular image
 *    vertices: 3D coordinates on unit sphere
 *   
 *    coordinate system: x: depth, y:left-right, z:bottom-top
 */
PersCamera Triangle::getPersCamParams(Mat equi_image, Vec9f vertices){
  // store in Point3d;
  vector<Point3d> points = convVec9fToPoint3d(vertices);

  // get the center of vertices in 3D.
  Point3d center = triangleCenter3d(points);
  center = normalizePoint(center);
  EquiTrans tran;
  double pan = 0.0, tilt = 0.0;
  tran.convSpherePointToAngles(center, &pan, &tilt);

  ViewDirection vd;
  vd.pan = pan;
  vd.tilt = tilt;

  // Obtained the initial field of view.
  double h_fov = -1.0, v_fov = -1.0;
  getFOV(points, vd, center, h_fov, v_fov);


  // set the intial camera.
  PersCamera cam;
  cam.setCamera(equi_image, h_fov, v_fov, vd);

  // adjust the camera.
  //PersCamera n_cam = adjustPersCam(equi_image, cam, points);

  return cam;
}
Exemple #2
0
sf::Vector2f Zombie::think(MainCharacter& main)
{
	if (m_state == charState::Dead)
		return sf::Vector2f(0, 0);

	//if (!getFOV().getGlobalBounds().intersects(main.getSprite().getGlobalBounds()))
	if (!getFOV().getGlobalBounds().contains(main.getPosition()))
	{
		if (m_targetChange > m_targetNext)
		{
			m_target.y = position.y - 250.0f + (rand() % 500);
			m_target.x = position.x - 250.0f + (rand() % 500);
			//target = sf::Vector2f(500.0f, 500.0f);
			m_targetChange = 0;
			m_targetNext = 1000 + (rand() % 2000);
		}
		m_targetChange += 1.0f;
		//return normalize(target);
		sf::Vector2f diff = m_target - position;
		if (diff.x > -5 && diff.y > -5 && diff.x < 5 && diff.y < 5)
			return sf::Vector2f(0, 0);
		m_hasTracked = false;
	}
	else
	{
		sf::Vector2f distvec = position - main.getPosition();
		float dist = sqrtf(powf(distvec.x, 2.0f) + powf(distvec.y, 2.0f));

		if (main.getFlashlightSwitch() || m_hasTracked || dist < 100.0f)
		{
			if (m_hasTracked == false)
			{
				scream.setPosition(position.x, position.y, 0);
				scream.play();
			}
			m_hasTracked = true;
			m_target = main.getPosition();
		}
	}

	sf::Vector2f tmp = normalize(m_target - this->getPosition());
	//this->setRotation((atan2f(tmp.y, tmp.x) * 180 / 3.1415f) - 90.0f);
	return tmp;
}
Exemple #3
0
void FirstPersonCamera::draw(int winWidth, int winHeight, MatrixStack &proj)
{
  proj.loadIdentity();
  proj.perspective(getFOV(),
                   (GLfloat)winWidth / (GLfloat)winHeight,
                   getNearClippingPlaneDist(),
                   getFarClippingPlaneDist());
  proj.rotateZ(m_attitude.roll);
  proj.rotateX(-m_attitude.pitch);
  proj.rotateY(-m_attitude.yaw);
  proj.translate(-m_pos.x, -m_pos.y, -m_pos.z);
  
  m_lookVector = glm::vec3(proj.getCurrent() * glm::vec4(0.f, 0.f, -1.f, 1.f));
  m_upVector = glm::vec3(proj.getCurrent() * glm::vec4(0.f, 1.f, 0.f, 1.f));
  
  //Update the GL stack, for now (will need until switch completely to
  //shader-based rendering)
  proj.syncToGlStack(GL_PROJECTION);
}
void Frustum::generateFrustumPlanes( Camera* camera, Plane* frustum ) {
	// Generate planes
	float nearHeight = 2 * tan( getFOV() / 2 ) * getNear();
	float nearWidth  = nearHeight * getAspect();
	
	//float farHeight  = 2 * tan( getFOV() / 2 ) * getFar();
	//float farWidth = farHeight * getAspect();
		
	Vector3 fc, nc, tmp;
	
	Vector3 ynh, xnw, X, Y, Z;
	
	Z = Vector3( camera->getCenterOfProjection() );
	Z.sub( Z, camera->getLookAtPoint() );
	Z.normalize();
	
	X.cross( camera->getUp(), Z );
	X.normalize();
	
	Y.cross( Z, X );
	
	ynh = Vector3( Y );
	ynh.scale( nearHeight / 2 );
	
	xnw = Vector3( X );
	xnw.scale( nearWidth / 2 );
	
	tmp = Vector3( Z );
	tmp.scale( getNear() );
	nc = Vector3( camera->getCenterOfProjection() ); 
	nc.sub( nc, tmp );
			
	tmp = Vector3( Z );
	tmp.scale( getFar() );
	fc = Vector3( camera->getCenterOfProjection() );
	fc.sub( fc, tmp );
			
	Vector3 aux, normal;
	
	frustum[ NEAR ].setNormal( Z.getX(), Z.getY(), Z.getZ() );
	frustum[ NEAR ].setPoint( nc );
		
	frustum[ FAR  ].setNormal( -Z.getX(), -Z.getY(), -Z.getZ() );	
	frustum[ FAR  ].setPoint( fc );
	
	aux = Vector3( nc );
	aux.add( aux, ynh );
	frustum[ TOP  ].setPoint( aux );
	
	aux.sub( aux, camera->getCenterOfProjection() );
	aux.normalize();
	normal.cross( aux, X );
	frustum[ TOP  ].setNormal( normal.getX(), normal.getY(), normal.getZ() );
	
	aux = Vector3( nc );
	aux.sub( aux, ynh );
	frustum[ BOTTOM ].setPoint( aux );
	
	aux.sub( aux, camera->getCenterOfProjection() );
	aux.normalize();
	normal.cross( X, aux );
	frustum[ BOTTOM ].setNormal( normal.getX(), normal.getY(), normal.getZ() );
	
	aux = Vector3( nc );
	aux.sub( aux, xnw );
	frustum[ LEFT ].setPoint( aux );
	
	aux.sub( aux, camera->getCenterOfProjection() );
	aux.normalize();
	normal.cross( aux, Y );
	frustum[ LEFT ].setNormal( normal.getX(), normal.getY(), normal.getZ() );
	
	aux = Vector3( nc );
	aux.add( aux, xnw );
	frustum[ RIGHT ].setPoint( aux );
	
	aux.sub( aux, camera->getCenterOfProjection() );
	aux.normalize();
	normal.cross( Y, aux );
	frustum[ RIGHT ].setNormal( normal.getX(), normal.getY(), normal.getZ() );
}