Exemplo n.º 1
0
TEST(WheelSoilTEST, getForce)
{
  Soil soil;
  Wheel wheel;
  wheel.r = 0.055;
  wheel.b = 0.064;
  wheel.velocity(0) = 5.0;
  wheel.velocity(1) = 2.0;
  wheel.velocity(2) = -1.0;

  Terradyn wheel_soil(soil, wheel);
  double beta = wheel_soil.getBeta();
  double slip = 0.9;
  double theta1 = toRadian(20);
  double theta2 = toRadian(10);
  double fe[5];

  tCalc_Fe_positive(slip, beta, theta1, theta2, wheel.velocity(2), 0.0, fe);

  auto force = wheel_soil.getForce(slip, theta1, theta2);

  EXPECT_NEAR(0.0, force(0)/fe[0] - 1, 0.15);
  EXPECT_NEAR(0.0, force(1)/fe[1] - 1, 0.15);
  EXPECT_NEAR(0.0, force(2)/fe[2] - 1, 0.15);
}
Exemplo n.º 2
0
light::light()
{
	/* attributes */
	mColor = colorNull();
	mNear = 1;
	mFar = 600;
	mHotspot = toRadian(15);
	mFalloff = toRadian(60);

	/* misc */
	mEnabled = true;
}
Exemplo n.º 3
0
double getBearing(double longtitude_start, double latitude_start, double longtitude_end, double latitude_end)
{
    double rad_latitude_start = toRadian(latitude_start);
    
    double rad_latitude_end = toRadian(latitude_end);
    
    double deltaLongtitude = toRadian(longtitude_end)- toRadian(longtitude_start);
    
    double x = sin(deltaLongtitude)*cos(rad_latitude_end);
    
    double y = cos(rad_latitude_start)*sin(rad_latitude_end)-sin(rad_latitude_start)*cos(rad_latitude_end)*cos(deltaLongtitude);
    
    return toBearing(atan2(x, y));
    
}
Exemplo n.º 4
0
sf::Vector2f Math::rotate(sf::Vector2f vector, float angle)
{
	angle=toRadian(angle);
	sf::Vector2f res;
	res.x=vector.x*cos(angle)+vector.y*-sin(angle);
	res.y=vector.x*sin(angle)+vector.y*cos(angle);
	return res;
}
Exemplo n.º 5
0
Point3D* SkyDome::getMoonPos(int time){
  double t = getT(time, 0.53, 0.45);
  double a = t*M_PI;
  if(a > M_PI || a < 0){
    a = 3*M_PI/2;
  }
  double r = m_radius-2000;
  Point3D *ret = new Point3D(r*cos(a), r*sin(a), -150);
  *ret = rotation(toRadian(40), 'x') * (*ret);
  return ret;
}
int main()
{
    int gdriver = DETECT, gmode;
    initgraph(&gdriver, &gmode, "");
    setbkcolor(WHITE);

    Point p[4] =
    {
        Point{0,0},
        Point{100,0},
        Point{100,100},
        Point{0,100}
    };
    int ch;
    cleardevice();
    drawAxis(BLACK);
    for(int i = 0; i<4; i++)
    {
        Line l = {p[i], p[(i+1)%4]};
        l.plotLineDDA(RED);
    }
    while((ch = getKeyCode())!=ESC)
    {
        switch(ch)
        {
        case 'A' :
            for(int i = 0; i<4; i++)
            {
                rotateSingle(&p[i], toRadian(10));
            }
            break;
        case 'W' :
            for(int i = 0; i<4; i++)
            {
                translateSingle(&p[i], 10,10);
            }
            break;
        case 'D' :
            for(int i = 0; i<4; i++)
            {
                scaleSingle(&p[i], 1.5, 1.5);
            }
            break;
        }
        cleardevice();
        drawAxis(BLACK);
        for(int i = 0; i<4; i++)
        {
            Line l = {p[i], p[(i+1)%4]};
            l.plotLineDDA(RED);
        }
    }
    return 0;
}
Exemplo n.º 7
0
void Vector3f::rotate(float angle, const Vector3f axis)
{
    const float sinHalfAngle = sinf(toRadian(angle / 2));
    const float cosHalfAngle = cosf(toRadian(angle / 2));

    const float rx = axis.x() * sinHalfAngle;
    const float ry = axis.y() * sinHalfAngle;
    const float rz = axis.z() * sinHalfAngle;
    const float rw = cosHalfAngle;

    Quaternion rotationQ(rx, ry, rz, rw);

    Quaternion conjugateQ = rotationQ.conjugate();

    Quaternion w = rotationQ * (*this) * conjugateQ;

    m_[0] = w.x();
    m_[1] = w.y();
    m_[2] = w.z();
}
Exemplo n.º 8
0
void Rubik3D::motion(int x, int y)
{
  if (moving) 
  {
    chi-= (x - beginx);
    beginx = x;
    phi-= (y - beginy);
    beginy=y;
    GLfloat rad_phi=toRadian(phi);
    GLfloat rad_chi=toRadian(chi);
    cameraZ=radius*sin(rad_phi)*cos(rad_chi);
    cameraX=radius*sin(rad_phi)*sin(rad_chi);
    cameraY=radius*cos(rad_phi);
    
    upZ=sin(rad_phi-PI/2)*cos(rad_chi);
    upX=(rad_phi-PI/2)*sin(rad_chi);
    upY=radius*cos(rad_phi-PI/2);
    
    glutPostRedisplay();
  }
}
Exemplo n.º 9
0
TEST(WheelSoilTEST, getTorque)
{
  Soil soil;
  Wheel wheel;
  wheel.velocity(0) = 4.0;
  wheel.velocity(1) = 2.0;
  wheel.velocity(2) = -1.0;

  Terradyn wheel_soil(soil, wheel);
  double beta = wheel_soil.getBeta();
  double slip = 0.6;
  double theta1 = toRadian(20);
  double theta2 = toRadian(10);
  double fe[5];

  tCalc_Fe_positive(slip, beta, theta1, theta2, -1.0, 0.0, fe);

  auto torque = wheel_soil.getTorque(slip, theta1, theta2);

  EXPECT_NEAR(0, torque(0), 0.15);
  EXPECT_NEAR(0.0, torque(1)/fe[3] -1.0, 0.15);
  EXPECT_NEAR(0.0, torque(2)/fe[4] -1.0, 0.15);
}
Exemplo n.º 10
0
void Aircraft::updateMovementPattern(sf::Time dt)
{
    const std::vector<Direction>& directions = Table[mType].directions;
    if (!directions.empty())
    {
        float distanceToTravel = directions[mDirectionIndex].distance;
        if (mTravelledDistance > distanceToTravel)
        {
            mDirectionIndex = (mDirectionIndex + 1) % directions.size();
            mTravelledDistance = 0.f;
        }
        
        float Radians = toRadian(directions[mDirectionIndex].angle + 90.f);
        float vx = getSpeed() * std::cos(Radians);
        float vy = getSpeed() * std::sin(Radians);
        setVelocity(vx, vy);
        mTravelledDistance += getSpeed() * dt.asSeconds();
    }
}
Exemplo n.º 11
0
void Aircraft::updateMovementPattern(sf::Time dt)
{
	// Enemy airplane: Movement pattern
	const std::vector<Direction>& directions = Table[mType].directions;
	if (!directions.empty())
	{
		// Moved long enough in current direction: Change direction
		if (mTravelledDistance > directions[mDirectionIndex].distance)
		{
			mDirectionIndex = (mDirectionIndex + 1) % directions.size();
			mTravelledDistance = 0.f;
		}

		// Compute velocity from direction
		float radians = toRadian(directions[mDirectionIndex].angle + 90.f);
		float vx = getMaxSpeed() * std::cos(radians);
		float vy = getMaxSpeed() * std::sin(radians);

		setVelocity(vx, vy);

		mTravelledDistance += getMaxSpeed() * dt.asSeconds();
	}
}
Exemplo n.º 12
0
// Hyperboloid Method Definitions
Hyperboloid::Hyperboloid(const Transform *o2w, const Transform *w2o, bool ro,
        const Point &point1, const Point &point2, float tm)
    : Shape(o2w, w2o, ro) {
    p1 = point1;
    p2 = point2;
    phiMax = toRadian(Clamp(tm, 0.0f, 360.0f));
    float radius1 = sqrtf(p1.x*p1.x + p1.y*p1.y);
    float radius2 = sqrtf(p2.x*p2.x + p2.y*p2.y);
    rmax = max(radius1, radius2);
    zmin = min(p1.z, p2.z);
    zmax = max(p1.z, p2.z);
    // Compute implicit function coefficients for hyperboloid
    if (p2.z == 0.) swap(p1, p2);
    Point pp = p1;
    float xy1, xy2;
    do {
        pp += 2.f * (p2-p1);
        xy1 = pp.x*pp.x + pp.y*pp.y;
        xy2 = p2.x*p2.x + p2.y*p2.y;
        a = (1.f/xy1 - (pp.z*pp.z)/(xy1*p2.z*p2.z)) /
            (1 - (xy2*pp.z*pp.z)/(xy1*p2.z*p2.z));
        c = (a * xy2 - 1) / (p2.z*p2.z);
    } while (isinf(a) || isnan(a));
}
Exemplo n.º 13
0
Arquivo: Math.cpp Projeto: jdmack/tlb
Matrix4f Math::genPersProjTransform(float fov, float width, float height, float zNear, float zFar)
{
    const float ar = width / height;
    const float zRange = zNear - zFar;
    const float tanHalfFOV = tanf(toRadian(fov / 2.0f));
    
    float m[4][4];

    m[0][0] = 1.0f / (tanHalfFOV * ar); m[0][1] = 0.0f;              m[0][2] = 0.0f;                     m[0][3] = 0.0;
    m[1][0] = 0.0f;                     m[1][1] = 1.0f / tanHalfFOV; m[1][2] = 0.0f;                     m[1][3] = 0.0;
    //m[2][0] = 0.0f;                     m[2][1] = 0.0f;              m[2][2] = (-zNear - zFar) / zRange; m[2][3] = 2.0f* zFar * zNear / zRange;
    m[2][0] = 0.0f;                     m[2][1] = 0.0f;              m[2][2] = (zNear + zFar) / zRange; m[2][3] = 2.0f* zFar * zNear / zRange;
    m[3][0] = 0.0f;                     m[3][1] = 0.0f;              m[3][2] = -1.0f;                     m[3][3] = 0.0;

    Matrix4f perspectiveMatrix;

    for (int row = 0; row < 4; row++) {
        for (int col = 0; col < 4; col++) {
            perspectiveMatrix.set(row, col, m[row][col]);
        }
    }

    return perspectiveMatrix;
}
Exemplo n.º 14
0
double getDistance(double longtitude_start, double latitude_start, double longtitude_end, double latitude_end)
{
    
    double rad_latitude_start = toRadian(latitude_start);
    
    double rad_latitude_end = toRadian(latitude_end);
    
    double deltaLongtitude = fabs(toRadian(longtitude_end)- toRadian(longtitude_start));
    
    double deltaLatitude = fabs(toRadian(latitude_end) - toRadian(latitude_start));
    
    double x = pow(sin(deltaLatitude/2),2);
    
    double y = cos(rad_latitude_start)*cos(rad_latitude_end)*pow(sin(deltaLongtitude/2),2);
    
    double c = 2 * atan2(sqrt(x+y),sqrt(1-(x+y)));
    
    return EARTH_RADIUS *c;
    
}
Exemplo n.º 15
0
/* now with normals! */
void drawHead( void )
{
	int theta;
	GLfloat r = 6.0;	/* we use 6 as the default radius, and multiply it for smaller/larger */

	/* the very top portion is like a cone...	*/
	glBegin( GL_TRIANGLE_FAN );
		glVertex3f( 0.0, 48.0, 0.0 );	/* top of the head */

		for( theta=0; theta<=360; theta+=DELTA_THETA )
		{
			createNormal( 0.0, 48.0, 0.0,
				r*cos(toRadian(theta)), 45.0, r*sin(toRadian(theta)),
				r*cos(toRadian(theta + DELTA_THETA)), 45.0, r*sin(toRadian(theta + DELTA_THETA)) );
			
				glVertex3f( r*cos(toRadian(theta)), 45.0, r*sin(toRadian(theta)) );
		}
	glEnd( );

	/* the next portion is like a cylindar going down from that... */
	glBegin( GL_QUAD_STRIP );
		for( theta=0; theta<=360; theta+=DELTA_THETA )
		{
			createNormal( r*cos(toRadian(theta)), 45.0, r*sin(toRadian(theta)),
				r*cos(toRadian(theta))*1.3, 38.0, r*sin(toRadian(theta))*1.3,
				r*cos(toRadian(theta + DELTA_THETA)), 45.0, r*sin(toRadian(theta + DELTA_THETA)) );
                                

			glVertex3f( r*cos(toRadian(theta)), 45.0, r*sin(toRadian(theta)) );
			glVertex3f( r*cos(toRadian(theta))*1.3, 38.0, r*sin(toRadian(theta))*1.3 );
		}
	glEnd( );

	/* the next portion is like another cylindar, but with different slope... */
	glBegin( GL_QUAD_STRIP );
		for( theta=0; theta<=360; theta+=DELTA_THETA )
		{
			createNormal( r*cos(toRadian(theta))*1.3, 38.0, r*sin(toRadian(theta))*1.3,
				 r*cos(toRadian(theta))*1.3, 33.0, r*sin(toRadian(theta))*1.3,
				 r*cos(toRadian(theta + DELTA_THETA))*1.3, 38.0, r*sin(toRadian(theta + DELTA_THETA))*1.3 );

			glVertex3f( r*cos(toRadian(theta))*1.3, 38.0, r*sin(toRadian(theta))*1.3 );
			glVertex3f( r*cos(toRadian(theta))*1.3, 33.0, r*sin(toRadian(theta))*1.3 );
		}
	glEnd( );

	/* yet another cylinder like thing */
	glBegin( GL_QUAD_STRIP );
		for( theta=0; theta<=360; theta+=DELTA_THETA )
		{
			createNormal( r*cos(toRadian(theta))*1.3, 33.0, r*sin(toRadian(theta))*1.3,
				r*cos(toRadian(theta)), 26.0, r*sin(toRadian(theta)),
				r*cos(toRadian(theta + DELTA_THETA))*1.3, 33.0, r*sin(toRadian(theta + DELTA_THETA))*1.3 );

			glVertex3f( r*cos(toRadian(theta))*1.3, 33.0, r*sin(toRadian(theta))*1.3 );
			glVertex3f( r*cos(toRadian(theta)), 26.0, r*sin(toRadian(theta)) );
		}
	glEnd( );
}
Exemplo n.º 16
0
/* now with normals! */
void drawLeftWing( void )
{
	/* first we must find the points to connect the wing to 
	(just like we did for the beak ) */

	GLfloat theta1 = toRadian( 180 - DELTA_THETA );
	GLfloat theta2 = toRadian( 180 + DELTA_THETA );
	GLfloat r = 6.0;

	/* now we calculate the four corners where the wing should connect to */
	GLfloat up_left_x = r*cos( theta1 )*2.5;
	GLfloat up_left_y = 20.0;
	GLfloat up_left_z = -r*sin( theta1 )*2.5;

	GLfloat down_left_x = r*cos( theta1 )*2.8;
	GLfloat down_left_y = 5.0;
	GLfloat down_left_z = -r*sin( theta1 )*2.8;


	GLfloat up_right_x = r*cos( theta2 )*2.5;
	GLfloat up_right_y = 20.0;
	GLfloat up_right_z = -r*sin( theta2)*2.5;

	GLfloat down_right_x = r*cos( theta2 )*2.8;
	GLfloat down_right_y = 5.0;
	GLfloat down_right_z = -r*sin( theta2 )*2.8;


	/* We must perform the rotation here */
	/* We must first translate the wing so that it goes about the joint correctly */
	glPushMatrix( );
	glTranslatef( up_left_x, (up_left_y + down_left_y) / 2.0, (up_left_z + up_right_z) / 2.0 );
	glRotatef( wing_flap_amount, 0.0, 0.0, 1.0 );
	glTranslatef( -up_left_x, (up_left_y + down_left_y) / -2.0, (up_left_z + up_right_z) / -2.0 );

	/* we render the wing as a few parallelograms (quad strip)
	   followed by a pyramid (triangle fan) */

	glBegin( GL_QUAD_STRIP );
		/* first quad */
		createNormal( up_left_x - 15.0, up_left_y - 25.0, up_left_z,
			down_left_x, down_left_y, down_left_z,
						up_left_x, up_left_y, up_left_z );

		glVertex3f( up_left_x, up_left_y, up_left_z );
		glVertex3f( up_left_x - 15.0, up_left_y - 25.0, up_left_z );
		glVertex3f( down_left_x, down_left_y, down_left_z );		
		glVertex3f( up_left_x - 15.0, down_left_y - 20.0, down_left_z );

		/* second */
		createNormal( up_left_x - 15.0, down_left_y - 20.0, down_left_z,
			up_left_x - 15.0, down_left_y - 20.0, down_right_z,
			down_right_x, down_right_y, down_right_z );		

		glVertex3f( down_right_x, down_right_y, down_right_z );
		glVertex3f( up_left_x - 15.0, down_left_y - 20.0, down_right_z );

		/* third */
		createNormal(  up_left_x - 15.0, down_left_y - 20.0, down_right_z,
			up_left_x - 15.0, up_left_y - 25, up_right_z,
			up_right_x, up_right_y, up_right_z );

		glVertex3f( up_right_x, up_right_y, up_right_z );
		glVertex3f( up_left_x - 15.0, up_left_y - 25, up_right_z );

		/* connect it back to the first */
		createNormal( up_left_x - 15.0, up_left_y - 25, up_right_z,
			up_left_x - 15.0, up_left_y - 25.0, up_left_z,
			up_left_x, up_left_y, up_left_z );

		glVertex3f( up_left_x, up_left_y, up_left_z );
		glVertex3f( up_left_x - 15.0, up_left_y - 25.0, up_left_z );
	glEnd( );

	glBegin( GL_TRIANGLE_FAN );
		/* the point of the wing */
		glVertex3f( down_left_x - 20.0, down_left_y - 25.0, 0.0 );

		/* the other points (same as ones above...) */
		createNormal( down_left_x - 20.0, down_left_y - 25.0, 0.0,
			up_left_x - 15.0, down_left_y - 20.0, down_left_z,
			up_left_x - 15.0, up_left_y - 25.0, up_left_z );
		glVertex3f( up_left_x - 15.0, up_left_y - 25.0, up_left_z );
		glVertex3f( up_left_x - 15.0, down_left_y - 20.0, down_left_z );

		createNormal( down_left_x - 20.0, down_left_y - 25.0, 0.0,
			up_left_x - 15.0, down_left_y - 20.0, down_left_z,
			up_left_x - 15.0, down_left_y - 20.0, down_right_z );
		glVertex3f( up_left_x - 15.0, down_left_y - 20.0, down_right_z );

		createNormal( down_left_x - 20.0, down_left_y - 25.0, 0.0,
			up_left_x - 15.0, up_left_y - 25, up_right_z,
			up_left_x - 15.0, down_left_y - 20.0, down_right_z );
		glVertex3f( up_left_x - 15.0, up_left_y - 25, up_right_z );

		createNormal( down_left_x - 20.0, down_left_y - 25.0, 0.0,
			up_left_x - 15.0, up_left_y - 25.0, up_left_z,
			up_left_x - 15.0, up_left_y - 25, up_right_z );
		glVertex3f( up_left_x - 15.0, up_left_y - 25.0, up_left_z );
	glEnd( );

	glPopMatrix( );
}
Exemplo n.º 17
0
/* now with normals! */
void drawBeak( void )
{
    /* we must calculate where the beak is based on
       what the value of DELTA_THETA is so that
       the penguin remains a properly connected entity
       the downside is that his beak size changes based on this */

	GLfloat theta1 = toRadian( 270 - DELTA_THETA );
	GLfloat theta2 = toRadian( 270 + DELTA_THETA );
	GLfloat r = 6.0;

	/* now we calculate the four corners based on these angles */
	GLfloat up_left_x = r*cos( theta1 )*1.3;
	GLfloat up_left_y = 38.0;
	GLfloat up_left_z = r*sin( theta1 )*1.3;

	GLfloat down_left_x = r*cos( theta1 )*1.3;
	GLfloat down_left_y = 33.0;
	GLfloat down_left_z = r*sin( theta1 )*1.3;


	GLfloat up_right_x = r*cos( theta2 )*1.3;
	GLfloat up_right_y = 38.0;
	GLfloat up_right_z = r*sin( theta2)*1.3;

	GLfloat down_right_x = r*cos( theta2 )*1.3;
	GLfloat down_right_y = 33.0;
	GLfloat down_right_z = r*sin( theta2 )*1.3;
	
	
	/* We draw the beak as a pyramid with a triangle fan... */
	glBegin( GL_TRIANGLE_FAN );
		/* the point of the beak... */
		glVertex3f( 0.0, 35.5, -30.0 );
		
		/* other points... */

		createNormal( 0.0, 35.5, -30.0,
			up_right_x, up_right_y, up_right_z,
			up_left_x, up_left_y, up_left_z );
		glVertex3f( up_right_x, up_right_y, up_right_z );
		glVertex3f( up_left_x, up_left_y, up_left_z );
		
		createNormal( 0.0, 35.5, -30.0,
			up_left_x, up_left_y, up_left_z,
			down_left_x, down_left_y, down_left_z );
		glVertex3f( down_left_x, down_left_y, down_left_z );
		

		createNormal( 0.0, 35.5, -30.0,
			down_left_x, down_left_y, down_left_z,
			down_right_x, down_right_y, down_right_z );
		glVertex3f( down_right_x, down_right_y, down_right_z );
		

		createNormal( 0.0, 35.5, -30.0,
			down_right_x, down_right_y, down_right_z,
			up_right_x, up_right_y, up_right_z );
		glVertex3f( up_right_x, up_right_y, up_right_z );
	glEnd( );
}
Exemplo n.º 18
0
/* now with normals */
void drawLeftFoot( void )
{
	/* Again, we must calculate the points to connect to the body */
	GLfloat theta1 = toRadian( 270 - 2*DELTA_THETA );
	GLfloat theta2 = toRadian( 270 - DELTA_THETA );
	GLfloat r = 6.0;

	GLfloat front_left_x = r*cos( theta1 )*1.9;
	GLfloat front_left_y = -18.0;
	GLfloat front_left_z = r*sin( theta1 )*1.9;

	GLfloat back_left_x = r*cos( theta1 );
	GLfloat back_left_y = -20.0;
	GLfloat back_left_z = r*sin( theta1 );

	
	GLfloat front_right_x = r*cos( theta2 )*1.9;
	GLfloat front_right_y = -18.0;
	GLfloat front_right_z = r*sin( theta2 )*1.9;

	GLfloat back_right_x = r*cos( theta2 );
	GLfloat back_right_y = -20.0;
	GLfloat back_right_z = r*sin( theta2 );


	/* We rotate the foot to give the illusion of walking */
	glPushMatrix( );

	/* We must translate to the joint and back so his foot pivots properly */
	glTranslatef( (front_left_x + front_right_x) /2.0, front_left_y, (front_left_z + front_right_z) / 2.0  );
	glRotatef( foot_move_amount, 1.0, 0.0, 0.0 );
	glTranslatef( (front_left_x + front_right_x) /-2.0, -front_left_y, (front_left_z + front_right_z) / -2.0  );


	/* We render a guad strip for the 'leg' part... */
	glBegin( GL_QUAD_STRIP );
		createNormal( back_left_x, back_left_y, back_left_z,
			back_left_x, back_left_y - 10.0, back_left_z,
			front_left_x, front_left_y, front_left_z );
		glVertex3f( back_left_x, back_left_y, back_left_z );
		glVertex3f( back_left_x, back_left_y - 10.0, back_left_z );
		glVertex3f( front_left_x, front_left_y, front_left_z );
		glVertex3f( front_left_x, front_left_y - 7.0, front_left_z );

		createNormal( front_right_x, front_right_y, front_right_z,
			front_left_x, front_left_y - 7.0, front_left_z,
			front_right_x, front_right_y - 7.0, front_right_z );
		glVertex3f( front_right_x, front_right_y, front_right_z );
		glVertex3f( front_right_x, front_right_y - 7.0, front_right_z );

		createNormal( back_right_x, back_right_y, back_right_z,
			front_right_x, front_right_y - 7.0, front_right_z,
			back_right_x, back_right_y - 10.0, back_right_z );
		glVertex3f( back_right_x, back_right_y, back_right_z );
		glVertex3f( back_right_x, back_right_y - 10.0, back_right_z );

		createNormal( back_left_x, back_left_y, back_left_z,
			back_right_x, back_right_y - 10.0, back_right_z,
			back_left_x, back_left_y - 10.0, back_left_z );
		glVertex3f( back_left_x, back_left_y, back_left_z );
		glVertex3f( back_left_x, back_left_y - 10.0, back_left_z );
	glEnd( );

	/* now we draw 2 triangles for the sides of his foot */
	glBegin( GL_TRIANGLES );
		/* left side */
		createNormal( front_left_x, back_left_y - 10.0, back_left_z - 20.0,
			front_left_x, front_left_y - 7.0, front_left_z,
			back_left_x, back_left_y - 10.0, back_left_z );
		glVertex3f( front_left_x, back_left_y - 10.0, back_left_z - 20.0 );
		glVertex3f( back_left_x, back_left_y - 10.0, back_left_z );
		glVertex3f( front_left_x, front_left_y - 7.0, front_left_z );

		/* right side */
		createNormal( front_right_x, back_right_y - 10.0, back_right_z - 20.0,
			back_right_x, back_right_y - 10.0, back_right_z,
			front_right_x, front_right_y - 7.0, front_right_z );
		glVertex3f( front_right_x, back_right_y - 10.0, back_right_z - 20.0 );
		glVertex3f( front_right_x, front_right_y - 7.0, front_right_z );
		glVertex3f( back_right_x, back_right_y - 10.0, back_right_z );
	glEnd( );

	/* now we draw 2 quads to fill in the gaps */
	glBegin( GL_QUADS );
		/* top of foot */
		createNormal( front_left_x, back_left_y - 10.0, back_left_z - 20.0,
			front_right_x, back_right_y - 10.0, back_right_z - 20.0,
			front_left_x, front_left_y - 7.0, front_left_z );
		glVertex3f( front_left_x, front_left_y - 7.0, front_left_z );
		glVertex3f( front_left_x, back_left_y - 10.0, back_left_z - 20.0 );
		glVertex3f( front_right_x, back_right_y - 10.0, back_right_z - 20.0 );
		glVertex3f( front_right_x, front_right_y - 7.0, front_right_z );

		/* bottom of foot */
		createNormal( back_right_x, back_right_y - 10.0, back_right_z,
			front_right_x, back_right_y - 10.0, back_right_z - 20.0,
			back_left_x, back_left_y - 10.0, back_left_z );			
		glVertex3f( back_left_x, back_left_y - 10.0, back_left_z );
		glVertex3f( back_right_x, back_right_y - 10.0, back_right_z );
		glVertex3f( front_right_x, back_right_y - 10.0, back_right_z - 20.0 );
		glVertex3f( front_left_x, back_left_y - 10.0, back_left_z - 20.0 );
	glEnd( );

	glPopMatrix( );
}
Exemplo n.º 19
0
void a4_render(// What to render
               SceneNode* root,
               // Where to output the image
               const std::string& filename,
               // Image size
               int width, int height,
               // Viewing parameters
               const Point3D& eye, const Vector3D& view,
               const Vector3D& up, double fov,
               // Lighting parameters
               const Colour& ambient,
               const std::list<Light*>& lights,
               double fogDist
               )
{
  // Fill in raytracing code here.

  std::cerr << "Stub: a4_render(" << root << ",\n     "
            << filename << ", " << width << ", " << height << ",\n     "
            << eye << ", " << view << ", " << up << ", " << fov << ",\n     "
            << ambient << ",\n     {";

  for (std::list<Light*>::const_iterator I = lights.begin(); I != lights.end(); ++I) {
    if (I != lights.begin()) std::cerr << ", ";
    std::cerr << **I;
  }
  std::cerr << "});" << std::endl;

  Vector3D viewVector = view;
  Vector3D upVector = up;
  Vector3D sideVector = viewVector.cross(upVector);
  viewVector.normalize();
  upVector.normalize();
  sideVector.normalize();
  
  Image img(width, height, 3);

  int progress = 0;
  int numPixels = width*height;
  for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
      int newProgress = (int)((double)(y*width + x)/numPixels*100);
      if(newProgress >= progress+5){
        progress = newProgress;
        std::cerr << progress << std::endl;
      }

      double d = height/2.0/tan(toRadian(fov)/2);
      Vector3D dir = (x-(width/2.0))*sideVector + 
          ((height/2.0)-y)*upVector + d*viewVector;
      dir.normalize();
      Ray ray = Ray(eye, dir);

      bool fogOn = true;
      if(fogDist <= 0)
        fogOn = false;
      Colour* color = rayTrace(ambient, eye, ray, root, lights, 5, fogDist);
      Colour fog(1,1,1);
      if(color == NULL) {
        // sunset colours
        Colour horizon(0.94, 0.55, 0.05);
        Colour zenith(0.2, 0.27, 0.4);
        Colour bg = zenith*(1-(double)y/height) + horizon*((double)y/height);
        if(fogOn)
          color = new Colour(0.8,0.8,0.8);
        else
          color = new Colour(bg);
      }

      img(x, y, 0) = color->R();
      img(x, y, 1) = color->G();
      img(x, y, 2) = color->B();
    }
  }
  img.savePng(filename);
  
}
Exemplo n.º 20
0
/* now with normals! */
void drawBody( void )
{
	int theta;
	GLfloat r = 6.0;

	/* this quad strip connects the head with the body some... */
	glBegin( GL_QUAD_STRIP );
		for( theta=0; theta<=360; theta+=DELTA_THETA )
		{
			createNormal( r*cos(toRadian(theta)), 26.0, r*sin(toRadian(theta)),
				r*cos(toRadian(theta))*2, 24.0, r*sin(toRadian(theta))*2,
				r*cos(toRadian(theta + DELTA_THETA)), 26.0, r*sin(toRadian(theta + DELTA_THETA)) );

			glVertex3f( r*cos(toRadian(theta)), 26.0, r*sin(toRadian(theta))  );
			glVertex3f( r*cos(toRadian(theta))*2, 24.0, r*sin(toRadian(theta))*2 );
		}
	glEnd( );

	/* this quad strip extends the body out some more... */
	glBegin( GL_QUAD_STRIP );
		for( theta=0; theta<=360; theta+=DELTA_THETA )
		{
			createNormal( r*cos(toRadian(theta))*2, 24.0, r*sin(toRadian(theta))*2,
				r*cos(toRadian(theta))*2.5, 20.0, r*sin(toRadian(theta))*2.5,
				r*cos(toRadian(theta + DELTA_THETA))*2, 24.0, r*sin(toRadian(theta + DELTA_THETA))*2 );

			glVertex3f( r*cos(toRadian(theta))*2, 24.0, r*sin(toRadian(theta))*2  );
			glVertex3f( r*cos(toRadian(theta))*2.5, 20.0, r*sin(toRadian(theta))*2.5 );
		}
	glEnd( );

	/* this quad strip extends is much longer, making up much of the torso */
	glBegin( GL_QUAD_STRIP );
		for( theta=0; theta<=360; theta+=DELTA_THETA )
		{
			createNormal( r*cos(toRadian(theta))*2.5, 20.0, r*sin(toRadian(theta))*2.5,
				r*cos(toRadian(theta))*2.8, 5.0, r*sin(toRadian(theta))*2.8,
				r*cos(toRadian(theta + DELTA_THETA))*2.5, 20.0, r*sin(toRadian(theta + DELTA_THETA))*2.5 );

			glVertex3f( r*cos(toRadian(theta))*2.5, 20.0, r*sin(toRadian(theta))*2.5 );
			glVertex3f( r*cos(toRadian(theta))*2.8, 5.0, r*sin(toRadian(theta))*2.8 );
		}
	glEnd( );

	/* this quad strip begins the taper back in */
	glBegin( GL_QUAD_STRIP );
		for( theta=0; theta<=360; theta+=DELTA_THETA )
		{
			createNormal( r*cos(toRadian(theta))*2.8, 5.0, r*sin(toRadian(theta))*2.8,
				r*cos(toRadian(theta))*2.5, -10.0, r*sin(toRadian(theta))*2.5,
				r*cos(toRadian(theta + DELTA_THETA))*2.8, 5.0, r*sin(toRadian(theta + DELTA_THETA))*2.8 );

			glVertex3f( r*cos(toRadian(theta))*2.8, 5.0, r*sin(toRadian(theta))*2.8 );
			glVertex3f( r*cos(toRadian(theta))*2.5, -10.0, r*sin(toRadian(theta))*2.5 );
		}
	glEnd( );

	/* this quad strip slopes the body in even further */
	glBegin( GL_QUAD_STRIP );
		for( theta=0; theta<=360; theta+=DELTA_THETA )
		{
			createNormal( r*cos(toRadian(theta))*2.5, -10.0, r*sin(toRadian(theta))*2.5,
				r*cos(toRadian(theta))*1.9, -18.0, r*sin(toRadian(theta))*1.9,
				r*cos(toRadian(theta + DELTA_THETA))*2.5, -10.0, r*sin(toRadian(theta + DELTA_THETA))*2.5 );

			glVertex3f( r*cos(toRadian(theta))*2.5, -10.0, r*sin(toRadian(theta))*2.5 );
			glVertex3f( r*cos(toRadian(theta))*1.9, -18.0, r*sin(toRadian(theta))*1.9 );
		}
	glEnd( );

	/* this quad strip almost closes the body */
	glBegin( GL_QUAD_STRIP );
		for( theta=0; theta<=360; theta+=DELTA_THETA )
		{
			createNormal( r*cos(toRadian(theta))*1.9, -18.0, r*sin(toRadian(theta))*1.9,
				r*cos(toRadian(theta)), -20.0, r*sin(toRadian(theta)),
				r*cos(toRadian(theta + DELTA_THETA))*1.9, -18.0, r*sin(toRadian(theta + DELTA_THETA))*1.9 );

			glVertex3f( r*cos(toRadian(theta))*1.9, -18.0, r*sin(toRadian(theta))*1.9 );
			glVertex3f( r*cos(toRadian(theta)), -20.0, r*sin(toRadian(theta)) );
		}
	glEnd( );

	/* this triangle fan closes the penguin at the bottom (it is a circle) */
	glBegin( GL_TRIANGLE_FAN );
		glVertex3f( 0.0, -20.0, 0.0 );	/* bottom of the penguin */

		for( theta=0; theta<=360; theta+=DELTA_THETA )
		{
			createNormal( 0.0, -20.0, 0.0,
				r*cos(toRadian(theta)), -20.0, r*sin(toRadian(theta)),
				r*cos(toRadian(theta + DELTA_THETA)), -20.0, r*sin(toRadian(theta + DELTA_THETA)) );

			glVertex3f( r*cos(toRadian(theta)), -20.0, r*sin(toRadian(theta)) );
		}
	glEnd( );
}
Exemplo n.º 21
0
bool glc::compareAngle(double p1, double p2)
{
	const double anglePrecision= toRadian(comparedPrecision);
	return qAbs(p1 - p2) <= anglePrecision;
}
Exemplo n.º 22
0
inline void Angle::setAngle( const double angle, const Angle::AngleValueType angleValueType ) {
    radian_ = ( angleValueType == DegreeAngleValue ) ? toRadian(angle) : angle;
}
Exemplo n.º 23
0
inline void Angle::setDegree( const double degree ) {
    radian_ = toRadian(degree);
}
Exemplo n.º 24
0
float ParticleSystem::linearVelocityY(float& angle) const
{
	return std::sin(toRadian(360.f - angle));
}