예제 #1
0
파일: astar.cpp 프로젝트: DavidMChan/hog2
void SFBDSAStar<graphState,graphMove>::OpenGLDraw( QueueNode q, bool side, GLdouble rad ) const {

	GLdouble x,y,z;

	if( side )
		glColor3f(1.,0.,0.);
	else
		glColor3f(0.,0.,1.);
	// draw the start
	node *n = ((GraphEnvironment*)env)->GetGraph()->GetNode( q.s1 );
	x = n->GetLabelF(GraphSearchConstants::kXCoordinate);
	y = n->GetLabelF(GraphSearchConstants::kYCoordinate);
	z = n->GetLabelF(GraphSearchConstants::kZCoordinate);
	DrawSphere( x, y, z, rad );

	if( side )
		glColor3f(0.,0.,1.);
	else
		glColor3f(1.,0.,0.);
	n = ((GraphEnvironment*)env)->GetGraph()->GetNode( q.s2 );
	x = n->GetLabelF(GraphSearchConstants::kXCoordinate);
	y = n->GetLabelF(GraphSearchConstants::kYCoordinate);
	z = n->GetLabelF(GraphSearchConstants::kZCoordinate);
	DrawSphere( x, y, z, rad );

	return;
};
void MainUserLoop()
{
//	Vector3 point(Vector3(3,5,1));
//	float radius = 1.4f;
//	Vector3 t1(0,1.5,0);
//	Vector3 t2(1,0.5,1);
//	Vector3 t3(0,2,3);
//
//	DrawSphere(point, radius);
//
//	DrawPoint(point);
//	DrawTriPlane(t1, t2, t3);
//
//	bool intersect = SphereTriangleIntersection(point, radius, t1, t2, t3);

	Vector3 rayStartWS(781, 49.5, 535);
	Vector3 rayDirWS(0.226, -0.515, 0.826);
	Vector3 sphereCentreWS(800, 5.31, 601);
	DrawLine(rayStartWS, rayStartWS + rayDirWS * 20.0f);
	DrawSphere(sphereCentreWS, 20.5f);

	Vector3 rayStartLS1(-4.19, 4.95, -5.4);
	Vector3 rayDirLS1(0.816, -0.515, 0.262);
	Vector3 sphereCentreLS1(-0.407, 0.897, -0.765);
	DrawLine(rayStartLS1, rayStartLS1 + rayDirLS1 * 20.0f);
	DrawSphere(sphereCentreLS1, 20.5f);
}
예제 #3
0
///////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
	{
	// Clear the window with current clearing color
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Save the matrix state and do the rotations
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();

	// Translate the whole scene out and into view	
	glTranslatef(0.0f, 0.0f, -300.0f);	

	// Initialize the names stack
	glInitNames();
	glPushName(0);

	
	// Draw the Earth
	glPushMatrix();
	glColor3f(0.0f, 0.0f, 1.0f);
	glTranslatef(-100.0f,0.0f,0.0f);
	glLoadName(EARTH);
	DrawSphere(30.0f);
	
	// Draw the Moon
	glTranslatef(45.0f, 0.0f, 0.0f);
	glColor3f(0.85f, 0.85f, 0.85f);
	glPushName(MOON1);
	DrawSphere(5.0f);
	glPopName();
	glPopMatrix();

	// Draw Mars
	glColor3f(1.0f, 0.0f, 0.0f);
	glPushMatrix();
	glTranslatef(100.0f, 0.0f, 0.0f);
	glLoadName(MARS);
	DrawSphere(20.0f);

	// Draw Moon1
	glTranslatef(-40.0f, 40.0f, 0.0f);
	glColor3f(0.85f, 0.85f, 0.85f);
	glPushName(MOON1);
	DrawSphere(5.0f);
	glPopName();

	// Draw Moon2
	glTranslatef(0.0f, -80.0f, 0.0f);
	glPushName(MOON2);
	DrawSphere(5.0f);
	glPopName();
	glPopMatrix();

	// Restore the matrix state
	glPopMatrix();	// Modelview matrix

	glutSwapBuffers();
	}
예제 #4
0
/*******************************************************************
**	座標軸の描画
**		width			: 座標軸の幅
**		length			: 座標軸の長さ
*******************************************************************/
void OpenGL::DrawCoordinateAxis(double length, const double width)
{
	glPushMatrix();
		// x軸の描画(赤)
		/////////////////////////////////////////////////////////////////////////////
		glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialAmbDiffRed );
		glLineWidth( (GLfloat)width );
		glBegin(GL_LINES);
			glVertex3f( 0.0f,	0.0f,	0.0f );
			glVertex3f( (GLfloat)length,	0.0f,	0.0f );
		glEnd();

		glTranslatef( (GLfloat)length, 0.0f, 0.0f );
		DrawSphere(150.0);
	glPopMatrix();

	glPushMatrix();
		// y軸の描画(緑)
		/////////////////////////////////////////////////////////////////////////////
		glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialAmbDiffGreen);
		glLineWidth( (GLfloat)width );
		glBegin(GL_LINES);
			glVertex3f( 0.0f,	0.0f,	0.0f );
			glVertex3f( 0.0f,	(GLfloat)length,	0.0f );
		glEnd();

		glTranslatef( 0.0f, (GLfloat)length, 0.0f );
		DrawSphere(150.0);
	glPopMatrix();

	glPushMatrix();
		// z軸の描画(青)
		/////////////////////////////////////////////////////////////////////////////
		glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialAmbDiffBlue);
		glLineWidth( (GLfloat)width );
		glBegin(GL_LINES);
			glVertex3f( 0.0f,	0.0f,	0.0f );
			glVertex3f( 0.0f,	0.0f,	(GLfloat)length );
		glEnd();

		glTranslatef( 0.0f, 0.0f, (GLfloat)length );
		DrawSphere(150.0);
	glPopMatrix();

	glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialAmbDiffYellow);
	DrawSphere(200.0);

	return;
}
예제 #5
0
void MeshDrawer::DrawMaxMinPoints() const
{
        // Draw Max-Points
        glColor3f(1.0f,0.0f,0.0f);
        for(set<size_t>::iterator it=p_MaxPointID->begin(); it!=p_MaxPointID->end(); ++it)
        {
                DrawSphere((*p_vtx)[*it]->getCoord());
        }
        // Draw Min-Points
        glColor3f(0.0f,0.0f,1.0f);
        for(set<size_t>::iterator it=p_MinPointID->begin();it!=p_MinPointID->end(); ++it)
        {
                DrawSphere((*p_vtx)[*it]->getCoord());
        }
}
예제 #6
0
void TrailMaxUnit<graphState,graphMove,AbstractionGraphEnvironment>::OpenGLDraw( int, AbstractionGraphEnvironment *env, SimulationInfo<graphState,graphMove,AbstractionGraphEnvironment>* ) {
	node *n  = env->GetGraph()->GetNode( current_pos );
	GLdouble x, y, z, rad = env->Scale()/2.;
	x = n->GetLabelF(GraphAbstractionConstants::kXCoordinate);
	y = n->GetLabelF(GraphAbstractionConstants::kYCoordinate);
	z = n->GetLabelF(GraphAbstractionConstants::kZCoordinate);
	if( done )
		glColor3d( 0., 1., 0. ); // turn green when done
	else
		glColor3f( r, g, b );
	DrawSphere( x, y, z, rad );

	// draw the path in front of us
	if( pathcache.size() > 0 && !done) {
		glBegin(GL_LINE_STRIP);
		glVertex3f( x, y, z-rad/2 );
		for( unsigned int i = 0; i < pathcache.size(); i++ ) {
			n  = env->GetGraph()->GetNode( pathcache[i] );
			x = n->GetLabelF(GraphAbstractionConstants::kXCoordinate);
			y = n->GetLabelF(GraphAbstractionConstants::kYCoordinate);
			z = n->GetLabelF(GraphAbstractionConstants::kZCoordinate);
			glVertex3f( x, y, z-rad/2 );
		}
		glEnd();
	}

	return;

};
예제 #7
0
///////////////////////////////////////////////////////////
// Render the torus and sphere
void DrawObjects(void)
	{
	// Save the matrix state and do the rotations
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();

	// Translate the whole scene out and into view	
	glTranslatef(-0.75f, 0.0f, -2.5f);	

	// Initialize the names stack
	glInitNames();
	glPushName(0);

	// Set material color, Yellow
	// torus
	glColor3f(1.0f, 1.0f, 0.0f);
	glLoadName(TORUS);
	glPassThrough((GLfloat)TORUS);
	DrawTorus(40, 20);


	// Draw Sphere
	glColor3f(0.5f, 0.0f, 0.0f);
	glTranslatef(1.5f, 0.0f, 0.0f);
	glLoadName(SPHERE);
	glPassThrough((GLfloat)SPHERE);	
	DrawSphere(0.5f);

	// Restore the matrix state
	glPopMatrix();	// Modelview matrix
	}
예제 #8
0
//-------------------------------------------------------------------------------
// @ Player::Render()
//-------------------------------------------------------------------------------
// Render stuff
//-------------------------------------------------------------------------------
void 
Player::Render()                                    
{   
    // build 4x4 matrix
    IvMatrix44 transform;

    int i,j;
    for (j = 0; j <=0 ; j++)
    {
        for (i = 0; i <= 0; i++)
        {
            transform(0, 3) = 5.0f * i;
            transform(2, 3) = 5.0f * j;
            
            IvVector3 lightDir = transform.AffineInverse().Transform(mLightDir);

            mShader->GetUniform("dirLightPosition")->SetValue(lightDir, 0);

            ::IvSetWorldMatrix(transform);

            // draw geometry
            DrawSphere();
        }
    }

}   // End of Player::Render()
예제 #9
0
void TXGLDrawer::DrawBoundingSpheres()
{
	/*
	Application().LogMessage(L"[TXGLDrawer] Nb SubGeometries : "+(CString)(ULONG)_geom->_subgeometries.size());
	*/
	std::vector<TXGeometry*>::iterator it = _geom->_subgeometries.begin();
	
	glEnable (GL_BLEND); 
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	for(;it<_geom->_subgeometries.end();it++)
	{
		Application().LogMessage(L"Sub Geometrie In Frustrum : "+(CString)(*it)->_infrustrum);
		//OUT
		if((*it)->_infrustrum == OUTSIDE)glColor4f(1,0,0,0.1);
		//INTERSECT
		else if((*it)->_infrustrum == INTERSECT)glColor4f(0,1,0,0.1);
		//IN
		else if((*it)->_infrustrum == INSIDE)glColor4f(0,0,1,0.1);
		//Error
		else glColor4f(0,0,0,1);

		glPushMatrix();
		glTranslatef((*it)->_spherecenter.GetX(),(*it)->_spherecenter.GetY(),(*it)->_spherecenter.GetZ());
		DrawSphere((*it)->_sphereradius,12, 12); 
		glPopMatrix();
	}
	glDisable(GL_BLEND);
}
예제 #10
0
//-------------------------------------------------------------------------------
// @ Player::Render()
//-------------------------------------------------------------------------------
// Render stuff
//-------------------------------------------------------------------------------
void 
Player::Render()                                    
{   
    // build 4x4 matrix
    IvMatrix44 transform(mRotate);

    transform(0,0) *= mScale;
    transform(1,0) *= mScale;
    transform(2,0) *= mScale;
    transform(0,1) *= mScale;
    transform(1,1) *= mScale;
    transform(2,1) *= mScale;
    transform(0,2) *= mScale;
    transform(1,2) *= mScale;
    transform(2,2) *= mScale;
    transform(0,3) = mTranslate.x;
    transform(1,3) = mTranslate.y;
    transform(2,3) = mTranslate.z;

    ::IvSetWorldMatrix(transform);

    // draw geometry
    DrawSphere();

}   // End of Player::Render()
예제 #11
0
///////////////////////////////////////////////////////////
// Render the torus and sphere
void DrawObjects(void)
{
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();

  glTranslatef(-0.75f, 0.0f, -2.5f);	

  //初始化名称栈 
  glInitNames();
  glPushName(0);

  //圆环
  glColor3f(1.0f, 1.0f, 0.0f);
  //圆环的名称
  glLoadName(TORUS);
  //设置一个自定义的过渡标记,与圆环的名称相同,以便后面的解析判断
  glPassThrough((GLfloat)TORUS);
  DrawTorus(40, 20);


  //球体
  glColor3f(0.5f, 0.0f, 0.0f);
  glTranslatef(1.5f, 0.0f, 0.0f);
  //球体的名称
  glLoadName(SPHERE);
  //球体的过渡标记
  glPassThrough((GLfloat)SPHERE);	
  DrawSphere(0.5f);

  glPopMatrix();	
}
예제 #12
0
void DrawShape(NxShape* shape, const NxVec3& color)
{
    switch(shape->getType())
    {
		case NX_SHAPE_PLANE:
			DrawPlane(shape);
		break;
		case NX_SHAPE_BOX:
			DrawBox(shape, color);
		break;
		case NX_SHAPE_SPHERE:
			DrawSphere(shape, color);
		break;
		case NX_SHAPE_CAPSULE:
			DrawCapsule(shape, color);
		break;
		case NX_SHAPE_CONVEX:
			DrawConvex(shape, color);
		break;
		case NX_SHAPE_MESH:
			DrawMesh(shape, color);
		break;
		case NX_SHAPE_WHEEL:
			DrawWheelShape(shape);
		break;
		default:
		break;
	}
}
예제 #13
0
void TrailMaxUnit<xyLoc,tDirection,MapEnvironment>::OpenGLDraw( int, MapEnvironment *env, SimulationInfo<xyLoc,tDirection,MapEnvironment>* ) {
	GLdouble xx, yy, zz, rad;
	Map *m = env->GetMap();
	if( current_pos.x >= m->GetMapWidth() || current_pos.y >= m->GetMapHeight() ) {
		fprintf( stderr, "Warning: TrailMaxUnit is out of bounds. Could not draw it.\n" );
		return;
	}
	m->GetOpenGLCoord( current_pos.x, current_pos.y, xx, yy, zz, rad );
	if( done )
		glColor3d( 0., 1., 0. ); // turn green when done
	else
		glColor3f( r, g, b );
	DrawSphere( xx, yy, zz, rad );

	// draw the path in front of us
	if( pathcache.size() > 0 && !done) {
		glBegin(GL_LINE_STRIP);
		glVertex3f( xx, yy, zz-rad/2 );
		for( unsigned int i = 0; i < pathcache.size(); i++ ) {
			m->GetOpenGLCoord( pathcache[i].x, pathcache[i].y, xx, yy, zz, rad );
			glVertex3f( xx, yy, zz-rad/2 );
		}
		glEnd();
	}

	return;
};
예제 #14
0
파일: Ball.cpp 프로젝트: unicodon/haribote
GLuint CBall::MakeDisplayList_Wire()
{
	GLuint dispList = glGenLists(1);
	glNewList(dispList, GL_COMPILE);
		material.setMaterial();
		DrawSphere(radius, true);
	glEndList();

	return dispList;
}
예제 #15
0
void FleeUnit::OpenGLDraw(const SteeringEnvironment *e,
						  const SimulationInfo<steeringState, steeringAction, SteeringEnvironment> *) const
{
	e->SetColor(1.0, 1.0, 0.0, 1.0);
	e->OpenGLDraw(currentLoc);
	//e->SetColor(1.0, 0.0, 0.0, 0.5);
	//e->OpenGLDraw(goalLoc);
	glColor4f(1.0, 0.0, 0.0, 0.5);
	DrawSphere(goalLoc.x/worldRadius, goalLoc.y/worldRadius, 0.0, 1/worldRadius);
}
예제 #16
0
//Drawing of the planets
void DrawPlanet(planet plan)
{
	glRotated(plan.cAxisAng, 0, 1, 0);
	glRotated(plan.axisAng, 1, 0, 0);
	glTranslated(plan.orbitRadius, 0, 0);
	glRotated(plan.cOrbitAng, 0, 1, 0);

	DrawSphere(plan.radius);

	return;
}
void BulletOpenGLApplication::DrawShape(btScalar* transform, const btCollisionShape* pShape, const btVector3 &color) {
	// set the color
	glColor3f(color.x(), color.y(), color.z());

	// push the matrix stack
	glPushMatrix();
	glMultMatrixf(transform);

	// make a different draw call based on the object type
	switch(pShape->getShapeType()) {
		// an internal enum used by Bullet for boxes
	case BOX_SHAPE_PROXYTYPE:
		{
			// assume the shape is a box, and typecast it
			const btBoxShape* box = static_cast<const btBoxShape*>(pShape);
			// get the 'halfSize' of the box
			btVector3 halfSize = box->getHalfExtentsWithMargin();
			// draw the box
			DrawBox(halfSize);
			break;
		}

/*ADD*/		case SPHERE_SHAPE_PROXYTYPE:
/*ADD*/			{
/*ADD*/				// assume the shape is a sphere and typecast it
/*ADD*/				const btSphereShape* sphere = static_cast<const btSphereShape*>(pShape);
/*ADD*/				// get the sphere's size from the shape
/*ADD*/				float radius = sphere->getMargin();
/*ADD*/				// draw the sphere
/*ADD*/				DrawSphere(radius);
/*ADD*/				break;
/*ADD*/			}
/*ADD*/	
/*ADD*/		case CYLINDER_SHAPE_PROXYTYPE:
/*ADD*/			{
/*ADD*/				// assume the object is a cylinder
/*ADD*/				const btCylinderShape* pCylinder = static_cast<const btCylinderShape*>(pShape);
/*ADD*/				// get the relevant data
/*ADD*/				float radius = pCylinder->getRadius();
/*ADD*/				float halfHeight = pCylinder->getHalfExtentsWithMargin()[1];
/*ADD*/				// draw the cylinder
/*ADD*/				DrawCylinder(radius,halfHeight);
/*ADD*/	
/*ADD*/				break;
/*ADD*/			}

	default:
		// unsupported type
		break;
	}

	// pop the stack
	glPopMatrix();
}
예제 #18
0
//Renders and rotates a planet
void Planet::Render()
{
	glm::mat4 model = glm::mat4(1.0f);
	model = glm::rotate(model, rotation, glm::vec3(0, 1, 0));//Rotate the planet around the origin
	model = glm::translate(model, position);//Move the planet to its position
	model = glm::rotate(model, rotation, glm::vec3(0, 1, 0));//Rotate the planet
	model = glm::scale(model, scale);//Scale the planet to its scale
	glUniformMatrix4fv(model_id, 1, GL_FALSE, &model[0][0]);
	DrawSphere();
	rotation += rotation_speed;
}
예제 #19
0
파일: Ball.cpp 프로젝트: unicodon/haribote
GLuint CBall::MakeDisplayList_Shadow()
{
	GLuint dispList = glGenLists(1);
	glNewList(dispList, GL_COMPILE);
		glDisable(GL_LIGHTING);
		glColor4fv(dif_shadow);		
		DrawSphere(radius, false);
		glEnable(GL_LIGHTING);
	glEndList();

	return dispList;
}
예제 #20
0
    void ExtraLife::Draw3D()
    {
        ColourRGBA sphereColour(POWERUP_SPHERE_COLOUR);
        const float blinkTime = (GAME.GetTime() - m_spawnTime) - (POWERUP_LIFETIME - POWERUP_BLINK_TIME);
        if (blinkTime > 0.0f) {
            sphereColour[ColourRGBA::COLOUR_ALPHA] = POWERUP_SPHERE_COLOUR.GetAlpha() *
                abs(cosf((blinkTime / POWERUP_BLINK_TIME) * static_cast<float>(M_PI) * POWERUP_BLINK_SPEED));
        }

        glPushMatrix();
            glTranslatef(m_origin[0], m_origin[1], m_origin[2]);
            glScalef(20.0f, 20.0f, 20.0f);
            DrawSphere(ColourRGBA(sphereColour));
        glPopMatrix();
    }
예제 #21
0
//------------------------------------------------------------------------------
// void DrawSpacecraft(float radius, GlColorType *color1, GlColorType *color2,
//                     bool drawSphere = true)
//------------------------------------------------------------------------------
void DrawSpacecraft(float radius, GlColorType *color1, GlColorType *color2,
                    bool drawSphere)
{
   if (drawSphere)
   {
      glColor3ub(color1->red, color1->green, color1->blue);
      DrawSphere(radius, 50, 50, GLU_FILL);
   }
   else
   {
      glColor3ub(color1->red, color1->green, color1->blue);
      DrawCube(radius, radius, radius*2);
      glColor3ub(color2->red, color2->green, color2->blue);
      DrawCube(radius/4, radius*4, radius*1.5);
   }
}
예제 #22
0
void DrawMaennchen(float angle) {

	//float overallScaleFactor = 0.2 * cos(GL_PI / 200 * angle) + 1;
	float jumpFactor = abs(cos(GL_PI/10 * angle));

	/**
	* Rumpf zeichnen
	**/
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Rotate(angle, 0, -1, 0);
	// generelle Verschiebung aus dem Mittelpunkt heraus
	modelViewMatrix.Translate(200.0f, 0.0f, 0.0f);
	// Verschiebung fuer Huepfbahn
	modelViewMatrix.Translate(0.0f, 30 * jumpFactor, 0);
	//modelViewMatrix.Scale(overallScaleFactor, overallScaleFactor, overallScaleFactor);

	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.9, 1.0, 0.7);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCylinder();
	modelViewMatrix.PopMatrix();

	// Hals
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0.0f, 55.0f, 0.0f);
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.25, 0.15, 0.25);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCylinder();
	modelViewMatrix.PopMatrix();

	// Kopf
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0.0f, 40.0f, 0.0f);
	modelViewMatrix.Scale(0.72, 0.72, 0.72);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawSphere();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	
	// Giedmaßen zeichnen - abhaengig vom Rumpf!
	DrawLimbs(angle);

	modelViewMatrix.PopMatrix();
}
예제 #23
0
void DrawPxShapes::DrawShape( PxShape* shape )
{
	PxGeometryType::Enum type = shape->getGeometryType();

	switch ( type )
	{
	case PxGeometryType::eBOX:
		DrawBox( shape );
		break;

	case PxGeometryType::eSPHERE:
		DrawSphere( shape );
		break;

	default:
		break;
	}
}
예제 #24
0
VOID DebugDraw::DrawBound( const Bound& bound, D3DCOLOR Color )
{
    switch( bound.GetType() )
    {
        case Bound::Sphere_Bound:
            DrawSphere( bound.GetSphere(), Color );
            return;
        case Bound::Frustum_Bound:
            DrawFrustum( bound.GetFrustum(), Color );
            return;
        case Bound::AABB_Bound:
            DrawAabb( bound.GetAabb(), Color );
            return;
        case Bound::OBB_Bound:
            DrawObb( bound.GetObb(), Color );
            return;
    }
}
예제 #25
0
void TextureRender()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glMatrixMode(GL_MODELVIEW);    
    glLoadIdentity();
    glRotatef (30, 1.0f, 0.0f, 0.0f);
    glRotatef (-45, 0.0f, 1.0f, 0.0f);

    DrawAxis ();
    //DrawTexRect ();
    glRotatef (texangx, 1.0f, 0.0f, 0.0f);
    glRotatef (texangy, 0.0f, 1.0f, 0.0f);
    glRotatef (texangz, 0.0f, 0.0f, 1.0f);
    DrawSphere ();

    if (texangx >= 360.0f)
    {
        texangx = 1.0f;
    }
    else
    {
        texangx += 1.0f;
    }

    if (texangy >= 360.0f)
    {
        texangy = 2.0f;
    }
    else
    {
        texangy += 2.0f;
    }

    if (texangz >= 360.0f)
    {
        texangz = 3.0f;
    }
    else
    {
        texangz += 3.0f;
    }
}
예제 #26
0
static void DrawActorShadow(NxActor* actor, const float* ShadowMat)
{
	glPushMatrix();
	glMultMatrixf(ShadowMat);

	glDisable(GL_LIGHTING);
	glColor4f(0.05f, 0.1f, 0.15f, 1.0f);
	
	NxShape*const* shapes = actor->getShapes();
	NxU32 nShapes = actor->getNbShapes();
	while (nShapes--)
	{
		//Ignore the shapes below d=0 plane
		if(shapes[nShapes]->getGlobalPosition().y < 0)
			continue;
		switch(shapes[nShapes]->getType())
		{
		    case NX_SHAPE_BOX:
			    DrawBox(shapes[nShapes]);
			break;
		    case NX_SHAPE_SPHERE:
			    DrawSphere(shapes[nShapes]);
			break;
		    case NX_SHAPE_CAPSULE:
			    DrawCapsule(shapes[nShapes]);
			break;
		    case NX_SHAPE_CONVEX:
			    DrawConvex(shapes[nShapes]);
			break;	
			default:
			break;
		}
	}	
	
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glEnable(GL_LIGHTING);

	glPopMatrix();
}
예제 #27
0
파일: astar.cpp 프로젝트: DavidMChan/hog2
void SFBDSAStar<graphState,graphMove>::OpenGLDraw( GLdouble rad ) const {

	if( OpenGLDrawState == NULL ) return;

	unsigned int num_states = ((GraphEnvironment*)env)->GetGraph()->GetNumNodes();

	// draw closed list in green
	glColor3f(0., 1., 0.);

	for( unsigned int i = 0; i < num_states; i++ ) {
		if( OpenGLDrawState[i] ) {
			GLdouble x,y,z;

			// draw start state
			node* n = ((GraphEnvironment*)env)->GetGraph()->GetNode( i );
			x = n->GetLabelF(GraphSearchConstants::kXCoordinate);
			y = n->GetLabelF(GraphSearchConstants::kYCoordinate);
			z = n->GetLabelF(GraphSearchConstants::kZCoordinate);
			DrawSphere( x, y, z, rad );
		}
	}

	return;
};
예제 #28
0
	void VrmlGame::Draw3DFromVRML(openvrml::node *obj)
	{
		try
		{
			//可能抛出openvrml::unsupported_interface异常
			const openvrml::field_value &fv_appearance = obj->field("appearance");
			if (fv_appearance.type() == openvrml::field_value::sfnode_id)
			{
				//std::cout<<"appearance"<<std::endl;
				const openvrml::sfnode &sfn = dynamic_cast<const openvrml::sfnode&>(fv_appearance);
				openvrml::vrml97_node::appearance_node *vrml_app =
					static_cast<openvrml::vrml97_node::appearance_node*>(sfn.value.get()->to_appearance());
				const openvrml::node_ptr &vrml_material_node = vrml_app->material();
				const openvrml::node_ptr &vrml_texture_node = vrml_app->texture();

				const openvrml::vrml97_node::material_node *vrml_material =
					dynamic_cast<const openvrml::vrml97_node::material_node *>(vrml_material_node.get());
				if (vrml_material != NULL)
				{
					GLfloat temp_material_mat[4];
					temp_material_mat[0] = vrml_material->ambient_intensity();
					temp_material_mat[1] = vrml_material->ambient_intensity();
					temp_material_mat[2] = vrml_material->ambient_intensity();
					temp_material_mat[3] = 1.0;
					glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, temp_material_mat);
					temp_material_mat[0] = vrml_material->diffuse_color().r();
					temp_material_mat[1] = vrml_material->diffuse_color().g();
					temp_material_mat[2] = vrml_material->diffuse_color().b();
					temp_material_mat[3] = 1.0;
					glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, temp_material_mat);
					temp_material_mat[0] = vrml_material->emissive_color().r();
					temp_material_mat[1] = vrml_material->emissive_color().g();
					temp_material_mat[2] = vrml_material->emissive_color().b();
					temp_material_mat[3] = 1.0;
					glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, temp_material_mat);
					temp_material_mat[0] =vrml_material->specular_color().r();
					temp_material_mat[1] =vrml_material->specular_color().g();
					temp_material_mat[2] =vrml_material->specular_color().b();
					temp_material_mat[3] = 1.0;
					glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, temp_material_mat);
					glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, vrml_material->shininess());

					if (vrml_material->transparency() > 0.0f)
					{
						//设置透明性
					}
					else
					{

					}
					//std::cout<<"material"<<std::endl;
				}

				//bind texture
				const openvrml::vrml97_node::image_texture_node *vrml_texture = 
					dynamic_cast<const openvrml::vrml97_node::image_texture_node *>(vrml_texture_node.get());
				if (vrml_texture != 0)
				{
					const openvrml::field_value &texture_url_fv = vrml_texture->field("url");
					const openvrml::mfstring &mfs = dynamic_cast<const openvrml::mfstring &>(texture_url_fv);

					std::pair<set<std::string>::iterator, bool> ret;

					//修改后缀为bmp
					std::string url = mfs.value[0];
					std::string dot(".");
					std::size_t found;
					found = url.find(dot);
					if (found != std::string::npos)
					{
						std::string bmp("bmp");
						url.replace(found+1,3,bmp);
						ret = textureUrls.insert(url);
						//std::cout<< url.c_str() << std::endl;
					}
					if (ret.second == true)  //如果url插入成功了,即来了一个新的url,则设置isBindTexture,使得之后生成新的纹理
					{
						isBindTexture = false;
					}

					//即查找现在的url为第一个纹理
					int count = 0;
					for (std::set<std::string>::iterator it=textureUrls.begin(); it!=textureUrls.end(); it++,count++)
					{
						if (*it == *ret.first)
						{
							textureNum = count;
							//std::cout<< count << std::endl;
							break;
						}
					}
					//绑定纹理
					if (!isBindTexture)
					{
						glBindTexture(GL_TEXTURE_2D, texture[textureNum]);
						AUX_RGBImageRec *texImage;
						texImage = auxDIBImageLoad(url.c_str());

						if (texImage == NULL)
						{
							std::cout << "no texture file,please convert rgb file to bmp file"<< std::cout;
							return;
						}
						glTexImage2D(GL_TEXTURE_2D, 0, 3,texImage->sizeX, texImage->sizeY,
							0, GL_RGB, GL_UNSIGNED_BYTE, texImage->data);
						glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
						glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

						if(texImage)
						{
							if(texImage->data)
							{
								free(texImage->data);
							}
							free(texImage);
						}
						//std::cout<< texture << std::endl;
						//std::cout<<"bind texture ok"<<std::endl;
						isBindTexture = true;
					}
					
					//读rgb文件有问题,暂时用bmp文件代替 
					//用read_texture函数返回的结果有问题,都是空格
					//int width = 180;
					//int height = 180;
					//int components = 4;
					//GLubyte *texels = (GLubyte *)read_texture(url.c_str(),&width,&height,&components);
					//std::cout<< url.c_str() << std::endl;
					//std::cout<< *read_texture(url.c_str(),&width,&height,&components) << std::endl;
				}
			}
		}
		catch(openvrml::unsupported_interface&)
		{

		}
		

		std::string name = obj->id();
		if (obj->type.id == "Group")
		{
			//std::cout<<"Group"<<std::endl;
			openvrml::vrml97_node::group_node *vrml_group;
			vrml_group = dynamic_cast<openvrml::vrml97_node::group_node *>(obj);

			try
			{
				const openvrml::field_value &fv = obj->field("children");

				if (fv.type() == openvrml::field_value::mfnode_id)
				{
					const openvrml::mfnode &mfn = dynamic_cast<const openvrml::mfnode &>(fv);
					for (unsigned int i=0; i<mfn.value.size(); i++)
					{
						openvrml::node *node = mfn.value[i].get();
						Draw3DFromVRML(node);
					}
				}
			}
			catch (openvrml::unsupported_interface&)
			{
				//no children
			}
		}
		else if (obj->type.id == "Transform")
		{
			//std::cout<<"Transform"<<std::endl;
			openvrml::vrml97_node::transform_node* vrml_transform;
			vrml_transform = dynamic_cast<openvrml::vrml97_node::transform_node*>(obj);

			openvrml::mat4f vrml_m = vrml_transform->transform();

			//opengl 添加转换
			glPushMatrix();
			GLfloat temp_trans[] = {vrml_m[0][0], vrml_m[0][1], vrml_m[0][2], vrml_m[0][3], vrml_m[1][0], vrml_m[1][1], vrml_m[1][2], vrml_m[1][3], vrml_m[2][0], vrml_m[2][1], vrml_m[2][2], vrml_m[2][3], vrml_m[3][0], vrml_m[3][1], vrml_m[3][2], vrml_m[3][3]};
			//glMultTransposeMatrixf(temp_trans);  
			glMultMatrixf(temp_trans);	//不需要转制,列优先

			//add 12.9
			glMatrixMode(GL_TEXTURE);
			glActiveTextureARB(GL_TEXTURE7);
			glPushMatrix();
			glMultMatrixf(temp_trans);
			try
			{
				const openvrml::field_value &fv = obj->field("children");

				if (fv.type() == openvrml::field_value::mfnode_id)
				{
					const openvrml::mfnode &mfn = dynamic_cast<const openvrml::mfnode &>(fv);
					for (unsigned int i=0; i<mfn.value.size(); i++)
					{
						openvrml::node *node = mfn.value[i].get();
						Draw3DFromVRML(node);
					}
				}
			}
			catch(openvrml::unsupported_interface&)
			{
				//no children
			}
			glPopMatrix();
			glMatrixMode(GL_MODELVIEW);
			glPopMatrix();
		}
		else if(obj->type.id == "Shape")
		{
			const openvrml::field_value &fv = obj->field("geometry");
			if (fv.type() == openvrml::field_value::sfnode_id)
			{
				const openvrml::sfnode &sfn = dynamic_cast<const openvrml::sfnode&>(fv);

				openvrml::vrml97_node::abstract_geometry_node* vrml_geom =
					static_cast<openvrml::vrml97_node::abstract_geometry_node*>(sfn.value.get()->to_geometry());

				if (openvrml::vrml97_node::indexed_face_set_node* vrml_ifs = dynamic_cast<openvrml::vrml97_node::indexed_face_set_node *>(vrml_geom))
				{
					DrawIndexedFaceSet(vrml_ifs);
				}
				else if (openvrml::vrml97_node::box_node* vrml_box = dynamic_cast<openvrml::vrml97_node::box_node*>(vrml_geom))
				{
					//opengl box
					//const openvrml::vec3f& size = static_cast<const openvrml::sfvec3f&>(vrml_box->field("size")).value;
					std::cout<<"box"<<std::endl;
					DrawBox(vrml_box);
				}
				else if (openvrml::vrml97_node::sphere_node* vrml_sphere = dynamic_cast<openvrml::vrml97_node::sphere_node*>(vrml_geom))
				{
					//sphere
					std::cout<<"sphere"<<std::endl;
					DrawSphere(vrml_sphere);
				}
				else if (openvrml::vrml97_node::cone_node* vrml_cone = dynamic_cast<openvrml::vrml97_node::cone_node*>(vrml_geom))
				{
					//cone
				}
				else if (openvrml::vrml97_node::cylinder_node* vrml_cylinder = dynamic_cast<openvrml::vrml97_node::cylinder_node*>(vrml_geom))
				{
					//cylinder
				}
				else
				{

				}
			}
		}
	}
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");

    // Define the camera to look into our 3d world
    Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, FOVY_PERSPECTIVE, CAMERA_PERSPECTIVE };

    SetTargetFPS(60);   // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        if (IsKeyPressed(KEY_SPACE)) 
        {
            if (camera.type == CAMERA_PERSPECTIVE) 
            {
                camera.fovy = WIDTH_ORTHOGRAPHIC;
                camera.type = CAMERA_ORTHOGRAPHIC;
            } 
            else 
            {
                camera.fovy = FOVY_PERSPECTIVE;
                camera.type = CAMERA_PERSPECTIVE;
            }
        }
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            BeginMode3D(camera);

                DrawCube((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, RED);
                DrawCubeWires((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, GOLD);
                DrawCubeWires((Vector3){-4.0f, 0.0f, -2.0f}, 3.0f, 6.0f, 2.0f, MAROON);

                DrawSphere((Vector3){-1.0f, 0.0f, -2.0f}, 1.0f, GREEN);
                DrawSphereWires((Vector3){1.0f, 0.0f, 2.0f}, 2.0f, 16, 16, LIME);

                DrawCylinder((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, SKYBLUE);
                DrawCylinderWires((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, DARKBLUE);
                DrawCylinderWires((Vector3){4.5f, -1.0f, 2.0f}, 1.0f, 1.0f, 2.0f, 6, BROWN);

                DrawCylinder((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, GOLD);
                DrawCylinderWires((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, PINK);

                DrawGrid(10, 1.0f);        // Draw a grid

            EndMode3D();

            DrawText("Press Spacebar to switch camera type", 10, GetScreenHeight() - 30, 20, DARKGRAY);

            if (camera.type == CAMERA_ORTHOGRAPHIC) DrawText("ORTHOGRAPHIC", 10, 40, 20, BLACK);
            else if (camera.type == CAMERA_PERSPECTIVE) DrawText("PERSPECTIVE", 10, 40, 20, BLACK);

            DrawFPS(10, 10);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
예제 #30
0
void FKSphereElem::DrawElemSolid(class FPrimitiveDrawInterface* PDI, const FTransform& ElemTM, float Scale, const FMaterialRenderProxy* MaterialRenderProxy)
{
	DrawSphere(PDI, ElemTM.GetLocation(), FVector( this->Radius * Scale ), DrawCollisionSides, DrawCollisionSides/2, MaterialRenderProxy, SDPG_World );
}