コード例 #1
0
ファイル: World.cpp プロジェクト: whitelight2134/spacewar
void World::initShips()
{
	// space ship
	PhysicsObjectId id(PhysicsObjectId::TYPE_SHIP, PhysicsObjectId::FLEET_PLAYER, 0);
	m_playerShip.init("Grapple", Const::SHIP_SIZE);
	m_playerShip.setId(id);
	m_playerShip.setPosition(Const::SHIP_POSITION);
	m_playerShip.setAmmo(8);
	m_playerShip.setHealth(Const::PLAYER_HEALTH);
	m_playerShip.setSpeed(Const::MOVE_PER_FRAME);


	// space ships
	id.m_type = PhysicsObjectId::TYPE_SHIP;
	id.m_fleet = PhysicsObjectId::FLEET_ENEMY;
	ObjModel model;
	model.load(Const::MODEL_DIR + Const::ENEMY_SHIP_MODEL_NAME + Const::EXTENSION);
	DisplayList displayList = model.getDisplayList();
	for (int i = 1; i <= Const::MOON_COUNT; i++)
	{
		for (int j = 0; j < Const::SHIPS_PER_MOON; j++){
			int index = (i - 1) * Const::SHIPS_PER_MOON + j;
			id.m_index = index;
			Vector3 position = m_planetoids[i].getPosition() + Vector3::getRandomUnitVector()*(m_planetoids[i].getScaledSize() + 500.0);
			m_ships[index].initPhysics(id, position, 1.0, 0, displayList, Const::ENEMY_SHIP_SIZE);
			m_ships[index].setHealth(1);
			m_ships[index].setUnitAi(new StemCell::UnitAiMoonGuard(m_ships[index], *this, m_planetoids[i].getId()));
			m_ships[index].setManeuverability(Const::SHIP_MAX_SPEED,Const::SHIP_ACCELERATION,Const::ROTATION_RATE);
		}
	}
}
コード例 #2
0
int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glEnable(GL_DEPTH_TEST);
	glutInitWindowPosition(100, 100);
	winWidth = 1300, winHeight = 800;
	glutInitWindowSize(winWidth, winHeight);
	glutCreateWindow("Traffic Simulation");
	glewInit();

	// Load the 3D models.
	trafficLight.ReadFile("Models/TrafficLight.obj");
	trafficLight2.ReadFile("Models/TrafficLight.obj");
	trafficLight3.ReadFile("Models/TrafficLight.obj");
	trafficLight4.ReadFile("Models/TrafficLight.obj");
	//cout << "\n|||||||||||\n";
	car.ReadFile("Models/taxi.obj");
	//cout << "\n|||||||||||\n";
	surveillanceCamera.ReadFile("Models/camera.obj");
	//cout << "\n|||||||||||\n";
	init();
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutSpecialFunc(specialKey);
	glutTimerFunc(0, timer, updateInterval);
	glutMainLoop();
	

	system("pause");
}
コード例 #3
0
    ObjModel* ObjModel::create(
        izanagi::IMemoryAllocator* allocator,
        izanagi::graph::CGraphicsDevice* device,
        const char* path)
    {
        void* buf = ALLOC(allocator, sizeof(ObjModel));
        VRETURN_NULL(buf);

        IZ_BOOL result = IZ_FALSE;

        ObjModel* instance = new(buf)ObjModel;
        {
            instance->m_Allocator = allocator;
            instance->AddRef();

            result = instance->load(
                allocator,
                device,
                path);
        }

        if (!result) {
            SAFE_RELEASE(instance);
        }

        return instance;
    }
コード例 #4
0
ファイル: crossy.cpp プロジェクト: AbdulazizAlaa/OpenRoad
void init()
{
	initDisplay();
	
	player1.load("chr_old.obj");
	car1.load("car1.obj");
	road.load("Road_Wide.obj");
	grass.load("Grass.obj");


}
コード例 #5
0
ファイル: main.cpp プロジェクト: aashish24/myexp
void DrawModel(ObjModel &model)
{
  glEnableClientState(GL_VERTEX_ARRAY);
  glVertexPointer(3, GL_FLOAT, 0, model.GetVertices());

  glEnableClientState(GL_NORMAL_ARRAY);
  glNormalPointer(GL_FLOAT, 0, model.GetNormals());

  glDrawArrays(GL_TRIANGLES, 0, model.GetTotalVerts());

  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_NORMAL_ARRAY);
}
コード例 #6
0
ファイル: crossy.cpp プロジェクト: AbdulazizAlaa/OpenRoad
void drawRoad(int i)
{
	glPushMatrix();
		glTranslatef(0, -1.0f, stepObj[i].z);
		glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
		if(stepObj[i].type == 0){
			road.draw();
			drawCar(10.0f, 0, 0.09f, i);
		}else if(stepObj[i].type == 1){
			grass.draw();
		}
	glPopMatrix();
		

}
コード例 #7
0
ファイル: main.cpp プロジェクト: streibeb/cs409
void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	// clear the screen - any drawing before here will not display

	glLoadIdentity();
	// set up the camera here
    camera.setCamera();

	// camera is set up - any drawing before here will display incorrectly
    
    // Draw Skybox
    glPushMatrix();
        glTranslatef(camera.getPosition().x,
                     camera.getPosition().y,
                     camera.getPosition().z);
        glDepthMask(GL_FALSE);
        skybox.draw();
        glDepthMask(GL_TRUE);
    glPopMatrix();

    // Draw Saturn
    glPushMatrix();
        glTranslatef(saturnInfo.x, 0.f, saturnInfo.z);
        glScalef(saturnInfo.radius, saturnInfo.radius, saturnInfo.radius);
        saturn.draw();
    glPopMatrix();
    
    // Draw Moons
    for (int i = 0; i < 10; i++)
    {
        glPushMatrix();
            glTranslatef(moonInfo[i].x, 0.f, moonInfo[i].z);
            glScalef(moonInfo[i].radius, moonInfo[i].radius, moonInfo[i].radius);
            moons[i].draw();
        glPopMatrix();
    }
    
    // Draw rings
    glPushMatrix();
        glTranslatef(ringInfo.x, 0.f, ringInfo.z);
        glScalef(ringInfo.radius, ringInfo.radius, ringInfo.radius);
        ring.draw();
    glPopMatrix();
    
	// send the current image to the screen - any drawing after here will not display
	glutSwapBuffers();
}
コード例 #8
0
ファイル: pac_1_cpp.cpp プロジェクト: aravindsagar/pac-minion
void init(int argc, char** argv)
{
	/**
	* This function initializes the graphics properties of the whole game
	*/
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE);		//Double Buffering - RGBAlpha - 3D - Ani-Aliasing
	glutInitWindowSize(winsizex, winsizey); 											//Window size
	glutCreateWindow("PAC-MINION"); 														//Create a window
	glutFullScreen();																	//Start with full screen mode
	glutIgnoreKeyRepeat(1);																//Ignoring key repaeat, Since we have key states
	glClearDepth(1);			
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);												//Initial color flush
	glEnable(GL_DEPTH_TEST); 															//Make sure 3D drawing works when one object is in front of another
	glEnable(GL_LIGHTING);																//Enable Lighting
	glEnable(GL_LIGHT0);																//Light 0 is enabled
	glShadeModel (GL_SMOOTH);	
	glEnable(GL_COLOR_MATERIAL);														//Enabling coloring in 3d materials
	glEnable(GL_BLEND); 																//Enable the OpenGL Blending functionality  
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);									//Function to be used for blending the graphical objects 
	GLfloat light_position[] = { 0.0, 0.0, 1.0, 0.0 };
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);									//Setting the light position
	GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
	glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);									//Setting the ambient light intensity
	minion.genList();																	//Generating the drawing list of thw minion
	
}
コード例 #9
0
void init()
{
	FILE* f = fopen("media/lighting/camera.txt", "r");

	xyz pos;
	while (!feof(f))
	{
		fscanf(f, "%f %f %f", &pos.x, &pos.y, &pos.z);
		camera_pos.push_back(pos);
	}

	fclose(f);
	
	FOVY = 54.495f;
	mgr=new TheoraVideoManager();
	clip=mgr->createVideoClip(new TheoraMemoryFileDataSource("media/lighting/lighting" + resourceExtension), TH_RGB);
	clip->setAutoRestart(1);
	//clip->setPlaybackSpeed(0.5f);
	
	tex_id = createTexture(nextPow2(clip->getWidth()),nextPow2(clip->getHeight()));
	diffuse_map = loadTexture("media/lighting/diffuse_map.tga");
	
	room.load("media/lighting/room.obj", diffuse_map);

	glDisable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glDepthFunc(GL_LESS);
	glEnable(GL_COLOR_MATERIAL);
}
コード例 #10
0
ファイル: crossy.cpp プロジェクト: AbdulazizAlaa/OpenRoad
void drawCar(float  y, float z, float scale, int i)
{
	glPushMatrix();
		glTranslatef(0, 1, count_steps[i]);
		glScalef(scale,scale,scale);
		//glRotatef(90.0f, 0.0f, 1.0f, 0.0f);        
		car1.draw();
	glPopMatrix();
}
コード例 #11
0
ファイル: crossy.cpp プロジェクト: AbdulazizAlaa/OpenRoad
void player()
{
	glPushMatrix();
        glTranslatef(playerX, playerY, playerZ);
		glRotatef(playerAngle, 0.0f, 1.0f, 0.0f);
        glScalef(playerSX, playerSY, playerSZ);
        player1.draw();
    glPopMatrix();
}
コード例 #12
0
void init(void)
{
	
	glClearColor(0.0, 0.0, 1.0, 1.0);	// background color = white
	glColor3f(0.0, 0.0, 0.0);		// drawing color = black
	glLineWidth(2.0f);
	glEnable(GL_DEPTH_TEST);
	fog_status=true;
	//fog_enable();
	physics_delta_time=(1/PHYSICS_UPDATE_RATE);
	AI_delta_time=(1/_FAST_AI_UPDATE_RATE);
	ai_slow_value=SLOW_AI_UPDATE_FRACTION;
	delta_time=0;
	frame=0;
	spiky_obj.load("fish.obj");
	submarine_obj.load("submarine_body.obj");
	whale_body.load("whale4s.obj");
	p_whale_x=525;
    p_whale_y=500;
    p_whale_z=-500;
	pwx=525;
    pwy=500;
    pwz=-500;
    v_whale_x=8;
    v_whale_y=8;
    v_whale_z=-12; 
	dv_whale_x=0;
    dv_whale_y=0;
    dv_whale_z=0;
	fast_AI_ESCORT=true;
	target_fish_no=-99;
	sphere=false;
	shark_target_fish=false;
	for(int i=0;i<256;i++)
	{
		key_pressed[i]=false;
	}
	alutInit(0, NULL);
//	alutLoadWAVFile("FreedomDance.wav", &format, &data, &size, &freq, &loop);

// Generate the sources


}
コード例 #13
0
ファイル: ObjLoader.cpp プロジェクト: nnarain/sgl-wrapper
void ObjLoader::load(ObjModel &model, const char *modelpath, const char * texturepath, bool invertUV)
{
	if (texturepath != NULL)
	{
		loadTexture(model.getTexture(), texturepath);
	}

	parse(modelpath);
	bindToMesh(model, invertUV);
}
コード例 #14
0
//--------------------------------------------------
void Scene::loadObjects(string filename, Object* obj)
{
	string name;
	name = "./Daten/Groups/";
	name.append(filename);
	name.append(".txt");

	ErrorLog *log = ErrorLog::getInstance();
	stringstream logStream;
	logStream << endl;
	logStream << "loading objects..." << endl << endl;
	log->reportError(logStream.str());

	FILE *fp = fopen(name.c_str(), "r");

	if (!fp)
	{
		logStream.str("");
		logStream << "Error, no input file!" << endl;
		log->reportError(logStream.str());
		return;
	}

	int res = 0;
	while (res != EOF)
	{
		char name[256] = "";
		float plz[6];
		res = fscanf(fp, "%s %f %f %f %f %f %f\n", &name, &plz[0], &plz[1], &plz[2], &plz[3], &plz[4], &plz[5]);

		ObjModel *model = new ObjModel();
		model->load(name, texturLoader, shLoader);

		Object *newObj = new Object();
		newObj->addModel(model);
		newObj->setPosition(plz[0], plz[1], plz[2]);
		newObj->setRotation(plz[3], plz[4], plz[5]);

		obj->addObject(newObj);
	}
}
コード例 #15
0
ファイル: Rendar.cpp プロジェクト: nonsensicalthinking/rendar
void Rendar::bspFromObjModel(string modelName)	{
	string* path = getCvarAddress_S("r_modelPath");
	string canonicalPath = *path + "obj/" + modelName;

	ObjModel* obj = new ObjModel();
	obj->loadObjFile(canonicalPath);

	vec3_t mapDimensions;
	obj->getDimensions(mapDimensions);

	float width = 0;

	if( mapDimensions[0] > mapDimensions[2] )	{
		width = mapDimensions[0];
	}
	else	{
		width = mapDimensions[2];
	}

	cout << " Widest dimension: " << width << endl;

	bspRoot = new bsp_node_t;
	bspRoot->root = true;

	/*	// debugging stuffs
	polygon_t* p = obj->polygonList;
	int myPolyCount = 0;
	while( p )	{
		myPolyCount++;
		p = p->next;
	}

	Con_print("myPolyCount: %d", myPolyCount);
	*/

	generateBSPTree(bspRoot, obj->polygonList, width);
	nameAndCachePolygons(bspRoot);

	delete obj;
}
コード例 #16
0
ファイル: main.cpp プロジェクト: streibeb/cs409
void init()
{
    for (int i = 0; i < 256; i++)
    {
        key_pressed[i] = false;
    }
    
    for (int i = 0; i < 20; i++)
    {
        special_key_pressed[i] = false;
    }
    
    initDisplay();
    camera.setPosition(Vector3(70000.0, 0.0, 70000.0));
    skybox.load("Models/Skybox.obj");
    saturn.load(saturnInfo.filename);
    for (int i = 0; i < 10; i++)
    {
        moons[i].load(moonInfo[i].filename);
    }
    ring.load(ringInfo.filename);
}
コード例 #17
0
ファイル: main.cpp プロジェクト: aashish24/myexp
void ShutdownApp()
{
   glDeleteObjectARB(_gSetRenderTargetShader);
   glDeleteObjectARB(_gClearRenderTargetShader);
   glDeleteObjectARB(_gRenderShader);
   glDeleteObjectARB(_gSsaoShader);
   glDeleteObjectARB(_gHorizontalBlurShader);
   glDeleteObjectARB(_gVerticalBlurShader);

   _gSceneFbo.Release();
   _gSsaoFbo.Release();
   _gHorizontalBlurFbo.Release();
   _gVerticalBlurFbo.Release();

   _gModel.Release();
}
コード例 #18
0
ファイル: main.cpp プロジェクト: AbdulazizAlaa/OpenRoad
void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();
	gluLookAt(2.0, 3.0, 4.0,
	          0.0, 0.0, 0.0,
	          0.0, 1.0, 0.0);

	// display positive X, Y, and Z axes near origin
	glBegin(GL_LINES);
		glColor3d(1.0, 0.0, 0.0);
		glVertex3d(0.0, 0.0, 0.0);
		glVertex3d(2.0, 0.0, 0.0);
		glColor3d(0.0, 1.0, 0.0);
		glVertex3d(0.0, 0.0, 0.0);
		glVertex3d(0.0, 2.0, 0.0);
		glColor3d(0.0, 0.0, 1.0);
		glVertex3d(0.0, 0.0, 0.0);
		glVertex3d(0.0, 0.0, 2.0);
	glEnd();

	// draw a purple wireframe cube
	glColor3d(1.0, 0.0, 1.0);
	glPushMatrix();
		glTranslated(0.0, 0.0, 0.0);
		glRotated(45, 0.0, 1.0, 0.0);
		glScaled(1.0, 1.0, 1.0);
		glutWireCube(1.0);
	glPopMatrix();

	glPushMatrix();
		glTranslated(0.0, 0.0, 0.0);
//		glRotated(45, 0.0, 1.0, 0.0);
		glScaled(0.005, 0.005, 0.005);		
		bucket.draw();
	glPopMatrix();

	glutSwapBuffers();
}
コード例 #19
0
ファイル: pac_1_cpp.cpp プロジェクト: aravindsagar/pac-minion
void draw()
{
	/**
	* Draws the 3D scene within the view volume
	*/
	int i,j;
	nfood=0;
	
	prevFrameTime = curFrameTime;
	curFrameTime = glutGet(GLUT_ELAPSED_TIME);								//Determines the time gap between two continuous frame to enable frame independent animation
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW); 											//Switch to the drawing perspective
	
	glLoadIdentity(); 														//Reset the drawing perspective
	glPushMatrix();
	camera();
	//glTranslatef(0.0f,0.0f,-100.0f);
	GLfloat light_position[] = { 0.0, 0.0, 1.0, 0.0 };
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	
	//Set material for pac and draw the pac
	GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat mat_shininess[] = {50.0};
	
	glTranslatef(-gridWidthby2, -gridHeightby2,-100.0f);
	
	glPushMatrix();
	glTranslatef(-gridCellSide/2,-gridCellSide/2,-gridCellSide/2);
	glColor4f(0.3,0.34,0.32,1.0);
	glBegin(GL_QUADS);
		glVertex3f(-gridCellSide,-gridCellSide,0);
		glVertex3f(-gridCellSide,gridHeightby2*2+gridCellSide,0);
		glVertex3f(gridWidthby2*2+gridCellSide,gridHeightby2*2+gridCellSide,0);
		glVertex3f(gridWidthby2*2+gridCellSide,0-gridCellSide,0);
	glEnd();
	glPopMatrix();
	glPushMatrix();
	
	/*
	In the following lines of code, we translate the PAC, and rotate it according to the direction of the PAC
	*/
	glTranslatef(pacx,pacy,0);

	if(!minionEnabled){
		glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
		glColor4f(0.75f,0.75f,0.0f,1.0f);
		glutSolidSphere(PACSIZE,50,50);
	}
	else{
		glDisable(GL_COLOR_MATERIAL);
		glRotatef(90.0f,1.0,0.0,0.0);
		if(pacCurDir == GLUT_KEY_LEFT) {
			if(pacAngle <= 270 - angleChange || pacAngle >= 270 + angleChange){
				if(pacAngle<=90 || pacAngle>270){
					pacAngle-=angleChange;
					if(pacAngle<0)
						pacAngle+=360;
				}
				else
					pacAngle = (pacAngle+angleChange)%360;
			}
			glRotatef((float)pacAngle,0.0,1.0,0.0);
		}
		else if(pacCurDir == GLUT_KEY_RIGHT){
			if(pacAngle <= 90 - angleChange || pacAngle >= 90 + angleChange){
				if(pacAngle<90 || pacAngle>=270){
					pacAngle = (pacAngle+angleChange)%360;
				}
				else
					pacAngle = (pacAngle-angleChange);
					if(pacAngle<0)
							pacAngle+=360;
			}
			glRotatef((float)pacAngle,0.0,1.0,0.0);
		}
		else if(pacCurDir == GLUT_KEY_UP){
			if(pacAngle <= 180 - angleChange || pacAngle >= 180 + angleChange){
				if(pacAngle<=359 && pacAngle>180){
					pacAngle = (pacAngle-angleChange);
					if(pacAngle<0)
							pacAngle+=360;
				}
				else
					pacAngle = (pacAngle+angleChange)%360;
			}
			glRotatef((float)pacAngle,0.0,1.0,0.0);
		}
		else if(pacCurDir == GLUT_KEY_DOWN){
			if(pacAngle <= 0 - angleChange || pacAngle >= 0 + angleChange){
				if(pacAngle<=180 && pacAngle>0){
					pacAngle = (pacAngle-angleChange);
					if(pacAngle<0)
							pacAngle+=360;
				}
				else
					pacAngle = (pacAngle+angleChange)%360;
			}
			glRotatef((float)pacAngle,0.0,1.0,0.0);
		}
		minion.draw();	//Draws the minion
		glEnable(GL_COLOR_MATERIAL);
	}								
	glPopMatrix();
	
	//Drawing ghosts
	if(!paused)
		blinky.move();
	if(Ghost::getGhostMode() == 2)
		glColor4f(0.0,0.0,1.0,0.8);
	else
		glColor4fv(blinky.color);
	glTranslatef(blinky.getX(),blinky.getY(),0.0f);
	glutSolidSphere(PACSIZE,5,5);
	glTranslatef(-blinky.getX(),-blinky.getY(),0.0f);
	
	if(!paused)
		inky.move();
	if(Ghost::getGhostMode() == 2)
		glColor4f(0.0,0.0,1.0,0.8);
	else
		glColor4fv(inky.color);
	glTranslatef(inky.getX(),inky.getY(),0.0f);
	glutSolidSphere(PACSIZE,5,5);
	glTranslatef(-inky.getX(),-inky.getY(),0.0f);

	if(!paused)
		pinky.move();
	if(Ghost::getGhostMode() == 2)
		glColor4f(0.0,0.0,1.0,0.8);
	else
		glColor4fv(pinky.color);
	glTranslatef(pinky.getX(),pinky.getY(),0.0f);
	glutSolidSphere(PACSIZE,5,5);
	glTranslatef(-pinky.getX(),-pinky.getY(),0.0f);

	if(!paused)
		clyde.move();
	if(Ghost::getGhostMode() == 2)
		glColor4f(0.0,0.0,1.0,0.8);
	else
		glColor4fv(clyde.color);
	glTranslatef(clyde.getX(),clyde.getY(),0.0f);
	glutSolidSphere(PACSIZE,5,5);
	glTranslatef(-clyde.getX(),-clyde.getY(),0.0f);

	GLfloat mat_specular2[] = {0.2,0.2,0.2,0.7};
	mat_shininess[0] = 100.0;
	GLfloat mat_diffuse[] = {0.2,0.17,0.73,1.0};
	GLfloat mat_ambient[] = {0.1,0.07,0.63,1.0};
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular2);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

	//Drawing the maze
	GLfloat mazeColor[] = {0.05f,0.07f,0.53f,1.0f};
	for(i=0;i<31;i++){
        
        for(j=0;j<28;j++){
            if(maze[i][j]==1){
                glColor4fv(mazeColor);
                glutSolidCube(gridCellSide);
            }
            else if(maze[i][j]==2){
                glColor4f(1.0f,0.8f,0.85f,0.9f);
                glutSolidSphere(0.5,10,10);
                nfood++;
            }
            else if(maze[i][j]==3){
                glColor4f(0.6f,1.0f,0.7f,0.75f);
                glutSolidSphere(1.2,20,20);
                nfood++;
            }
            glTranslatef(gridCellSide,0.0f,0.0f);
        }
        glTranslatef(-28*gridCellSide,gridCellSide,0.0f);
    }
    glPopMatrix();
    //staticElementsDraw();
    text();
	glutSwapBuffers(); //Send scene to the screen to be shown
}
コード例 #20
0
ファイル: main5.cpp プロジェクト: streibeb/cs409
void init()
{
	initDisplay();
	bucket.load("firebucket.obj");
    bucket_list = bucket.getDisplayList();
}
コード例 #21
0
void whale_model()
{
	
	//glMatrixMode(GL_MODELVIEW);
	GLUquadricObj* Sphere;
	Sphere=gluNewQuadric();
	float theta=0;
	


if(v_whale_z<0)
		{
			theta = 3.14 + atan(v_whale_x/v_whale_z);
		}


		else if (v_whale_z>0 )
		{
			theta = atan(v_whale_x/v_whale_z);
		}


		else
		{
			if(v_whale_x>0)
			{
				theta= 3.14/2;
			}
			else if(v_whale_x<0)
			{
				theta = (3 * 3.14) / 2;
			}

	   }
		theta = (theta * 180) / 3.14;
		float r;
		r = sqrt(powf(v_whale_x,2)+powf(v_whale_z,2));

		float pi;
		if(v_whale_y!=0 && r>0)
		{
			pi=atan(v_whale_y/r);
		}


		else if(r==0)
		{
			if(p_whale_y>0)
			{
				pi=3.14/2;
			}

			else if(p_whale_y<0)
			{
				pi = (3.14 * 3)/2;
			}
		}

		pi = (pi * 180) / 3.14;
		
		
		submarine1 sub2;
        GLUquadricObj *Spher;
		Spher = gluNewQuadric();
		glPushMatrix();
		
		glTranslatef(p_whale_x, p_whale_y, p_whale_z);	// unneeded since default position is (0, 0, 0)
		/*glBegin(GL_LINES);
              glVertex3d(0, 0, 0);
              glVertex3d(vx[i], vy[i], vz[i]);
         glEnd();*/
		glRotatef(theta, 0.0, 1.0, 0.0);	// unneeded since default rotation is 0 degrees
		glRotatef(pi, -1.0, 0.0, 0.0);
		 glScalef(7.0, 7.0, 7.0);		// unneeded since default scaling is 1 in X, Y, and Z
		glRotatef(90, 0.0, 1.0, 0.0);
	    whale_body.draw();
		if(sphere==true)
		{
		glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		
		glColor4f(sub2.red, sub2.green, sub2.blue, 0.2f);
		gluSphere(Spher,1, 10, 10);
 
		glDisable(GL_BLEND);
		}
		
		
	   glPopMatrix();
		
		}
コード例 #22
0
ファイル: main.cpp プロジェクト: aashish24/myexp
bool InitializeApp()
{
  glClearColor(0, 0, 0, 1);
  glShadeModel(GL_SMOOTH);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_TEXTURE_2D);

  // Load texture.
  int width = 0, height = 0, comp = 0;
  unsigned char *image;
  image = LoadTGA("/home/aashish/tools/mywork/src.git/data/noise.tga", width, height, comp);

  glGenTextures(1, &_gRandomSampler);
  glBindTexture(GL_TEXTURE_2D, _gRandomSampler);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height,
               0, GL_RGB, GL_UNSIGNED_BYTE, image);

   delete[] image;

  // Load shaders.
  if(!CreateGLSLShader("/home/aashish/tools/mywork/src.git/opengl/ssao_crytek/setRenderTargetsVs.glsl",
                      "/home/aashish/tools/mywork/src.git/opengl/ssao_crytek/setRenderTargetsPs.glsl",
                      _gSetRenderTargetShader))
    return false;

  if(!CreateGLSLShader("/home/aashish/tools/mywork/src.git/opengl/ssao_crytek/clearRenderTargetsVs.glsl",
                      "/home/aashish/tools/mywork/src.git/opengl/ssao_crytek/clearRenderTargetsPs.glsl",
                      _gClearRenderTargetShader))
    return false;

  if(!CreateGLSLShader("/home/aashish/tools/mywork/src.git/opengl/ssao_crytek/ssaoVs.glsl",
                      "/home/aashish/tools/mywork/src.git/opengl/ssao_crytek/ssaoPs.glsl",
                      _gSsaoShader))
   return false;


  if(!CreateGLSLShader("/home/aashish/tools/mywork/src.git/opengl/ssao_crytek/hBlurVs.glsl",
                      "/home/aashish/tools/mywork/src.git/opengl/ssao_crytek/hBlurPs.glsl",
                      _gHorizontalBlurShader))
  return false;

  if(!CreateGLSLShader("/home/aashish/tools/mywork/src.git/opengl/ssao_crytek/vBlurVs.glsl",
                       "/home/aashish/tools/mywork/src.git/opengl/ssao_crytek/vBlurPs.glsl",
                       _gVerticalBlurShader))
    return false;

  if(!CreateGLSLShader("/home/aashish/tools/mywork/src.git/opengl/ssao_crytek/renderingVs.glsl",
                       "/home/aashish/tools/mywork/src.git/opengl/ssao_crytek/renderingPs.glsl",
                        _gRenderShader))
    return false;

  // Bind our shader variables.
  _gOffset            = glGetUniformLocationARB(_gRenderShader, "offset");

  _gLight1Pos             = glGetUniformLocationARB(_gRenderShader, "light1Pos");
  _gLight1AmbientColor    = glGetUniformLocationARB(_gRenderShader, "light1AmbientColor");
  _gLight1DiffuseColor    = glGetUniformLocationARB(_gRenderShader, "light1DiffuseColor");
  _gLight1SpecularColor   = glGetUniformLocationARB(_gRenderShader, "light1SpecularColor");

  _gLight2Pos             = glGetUniformLocationARB(_gRenderShader, "light2Pos");
  _gLight2AmbientColor    = glGetUniformLocationARB(_gRenderShader, "light2AmbientColor");
  _gLight2DiffuseColor    = glGetUniformLocationARB(_gRenderShader, "light2DiffuseColor");
  _gLight2SpecularColor   = glGetUniformLocationARB(_gRenderShader, "light2SpecularColor");

  _gAmbientOcclusion  = glGetUniformLocationARB(_gRenderShader, "aos");
  _gSceneColors       = glGetUniformLocationARB(_gRenderShader, "colors");
  _gSceneDepths       = glGetUniformLocationARB(_gRenderShader, "depths");
  _gSceneNormals      = glGetUniformLocationARB(_gRenderShader, "normals");

  _gSsaoOffset        = glGetUniformLocationARB(_gSsaoShader, "offset");
  _gSsaoNormals       = glGetUniformLocationARB(_gSsaoShader, "normals");
  _gSsaoDepths        = glGetUniformLocationARB(_gSsaoShader, "depths");
  _gSsaoRandoms       = glGetUniformLocationARB(_gSsaoShader, "randoms");

  _gHorizontalBlurSceneSampler       = glGetUniformLocationARB(_gHorizontalBlurShader, "scene");
  _gHorizontalBlurSceneSamplerDepth  = glGetUniformLocationARB(_gHorizontalBlurShader, "depths");
  _gHorizontalBlurSceneSamplerNormal = glGetUniformLocationARB(_gHorizontalBlurShader, "normals");

  _gVerticalBlurSceneSampler       = glGetUniformLocationARB(_gVerticalBlurShader, "scene");
  _gVerticalBlurSceneDepthSampler  = glGetUniformLocationARB(_gVerticalBlurShader, "depths");
  _gVerticalBlurSceneNormalSampler = glGetUniformLocationARB(_gVerticalBlurShader, "normals");

  // Create frame buffer objects.
  if(_gSceneFbo.Create(WIDTH, HEIGHT) == false)
    return false;

  // Create frame buffer objects.
  if(_gSsaoFbo.Create(WIDTH, HEIGHT) == false)
    return false;

  // Create frame buffer objects.
  if(_gHorizontalBlurFbo.Create(WIDTH, HEIGHT) == false)
    return false;

  if(_gVerticalBlurFbo.Create(WIDTH, HEIGHT) == false)
    return false;

  if(_gModel.LoadOBJ("/home/aashish/tools/mywork/src.git/data/sponza.obj") == false)
    return false;

  return true;
}
コード例 #23
0
void draw()
{
	glClearColor(1, 1, 1, 1);

	glLoadIdentity();
	float x1, y1, z1, x2=-65.147f, y2=80.219f, z2=12.301f;
	static int index = 0;

	TheoraVideoFrame* f=clip->getNextFrame();
	if (f)
	{
		index = (int)f->getFrameNumber();
		glBindTexture(GL_TEXTURE_2D,tex_id);
		unsigned char* buffer = f->getBuffer();
		int x, len = f->getWidth() * f->getHeight() * 3;
		for (int i = 0; i < len; i++)
		{
			x = (*buffer) * 0.8f + 255 * 0.2f;
			if (x > 255) *buffer = 255;
			else *buffer = x;
			buffer++;
		}
		
		glTexSubImage2D(GL_TEXTURE_2D,0,0,0,f->getWidth(),f->getHeight(),GL_RGB,GL_UNSIGNED_BYTE,f->getBuffer());
		clip->popFrame();
	}
	x1 = camera_pos[index].x; y1 = camera_pos[index].y; z1 = camera_pos[index].z;
	gluLookAt(x1, z1, -y1, x2, z2, -y2,  0,1,0);
	//gluLookAt(x1, y1, z1, x2, z2, -y2,  0,1,0);

	glBlendFunc(GL_ONE,GL_ZERO);
	glEnable(GL_CULL_FACE);
	if (diffuse_enabled) glEnable(GL_TEXTURE_2D);
	else glDisable(GL_TEXTURE_2D);
	room.draw();
	glDisable(GL_CULL_FACE);

	if (lighting_enabled)
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D,tex_id);

		glPushMatrix();
		glLoadIdentity();
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		
		glDisable(GL_DEPTH_TEST);

		glBlendFunc(GL_DST_COLOR, GL_ZERO);
		
		glBegin(GL_QUADS);

		glTexCoord2f(            0,   4 / 1024.0f); glVertex3f(-1, 1, 0);
		glTexCoord2f(800 / 1024.0f,   4 / 1024.0f); glVertex3f( 1, 1, 0);
		glTexCoord2f(800 / 1024.0f, 604 / 1024.0f); glVertex3f( 1,-1, 0);
		glTexCoord2f(            0, 604 / 1024.0f); glVertex3f(-1,-1, 0);

		glEnd();

		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
		glPopMatrix();
		glEnable(GL_DEPTH_TEST);
	}
}
コード例 #24
0
ファイル: scene.cpp プロジェクト: TTU-Graphics/FinalProject
Model* Scene::buildModel(Json::Value model) {
    string type = model["class"].asString();
    Model *retModel;
    // menger
    if(type.compare("Menger") == 0) {
        vec3 center = getVec3(model.get("center", "[0,0,0]"));
        printVec("center",center);
        float radius = model.get("radius", "1.0").asFloat();
        int subdivs = model.get("subdivisions", "2").asInt();
        retModel = new Menger(center, radius, subdivs);
    }
    // sphere
    else if(type.compare("Sphere") == 0) {
        Sphere *sphere;
        if(!model.isMember("ambient")) {
            sphere = new Sphere(
                model["radius"].asFloat(),
                model["subdivs"].asInt(),
                lights.size());
        } else {
            sphere = new Sphere(
                model["radius"].asFloat(),
                model["subdivs"].asInt(),
                lights.size(),
                getVec4(model.get("ambient","[1,0,1,1]")),
                getVec4(model.get("diffuse","[1,0.8,0,1]")),
                getVec4(model.get("specular","[1,0,1,1]")));
        }
        vector<Light*>::iterator it;
        int light = 0;
        for(it = lights.begin(); it != lights.end(); it++) {
            sphere->setLight((*it), light++);
        }
        retModel = sphere;
    } else if(type.compare("TexTri") == 0) {
        retModel = new TexTri(model["texture"].asString().c_str());
        printf("created textri\n");
    } else if(type.compare("ObjModel") == 0) {
        ObjModel *obj = new ObjModel(model["objfile"].asString().c_str(),
                                     lights.size(),
                                     getVec4(model.get("ambient","[1,1,1,1]")),
                                     getVec4(model.get("diffuse","[1,1,1,1]")),
                                     getVec4(model.get("specular","[1,1,1,1]")));
        vector<Light*>::iterator it;
        int light = 0;
        for(it = lights.begin(); it != lights.end(); it++) {
            obj->setLight((*it), light++);
        }
        retModel = obj;
    } else if(type.compare("Tesseract") == 0) {
        Tesseract *tess = new Tesseract( lights.size() );
        vector<Light*>::iterator it;
        int light = 0;
        for(it = lights.begin(); it != lights.end(); it++) {
            tess->setLight((*it), light++);
        }
        retModel = tess;
    } else if(type.compare("Particles") == 0) {
        Particles *part = new Particles( model.get("number",50).asInt() );
        retModel = part;
    }

    // map model if it has an id
    if(model.isMember("id")) {
        string id = model["id"].asString();
        nodes[id] = retModel;
        idModels[id] = retModel;
    }
    return retModel;
}
コード例 #25
0
ファイル: main.cpp プロジェクト: AbdulazizAlaa/OpenRoad
void init()
{
	initDisplay();
	bucket.load("models/bucket/firebucket.obj");
}
コード例 #26
0
ファイル: ObjLoader.cpp プロジェクト: nnarain/sgl-wrapper
void ObjLoader::bindToMesh(ObjModel &model, bool invertUV)
{
	const int vertSize = _positions->size();
	const int normSize = _normals->size();
	const int uvSize   = _texCoords->size();

	Mesh &mesh = model.getMesh();

	// calculate the vertex data stride
	int stride = 0;
	if (vertSize > 0)
	{ 
		mesh.addAttribute(VertexAttribute(0, 3));
		stride += 3;
	}
	if (normSize > 0)
	{
		mesh.addAttribute(VertexAttribute(1, 3));
		stride += 3;
	}
	if (uvSize > 0)
	{
		mesh.addAttribute(VertexAttribute(2, 2));
		stride += 2;
	}

	std::vector<float> buffer;
	int offset = 0;

	std::map<std::string, MeshData>::iterator meshIter;

	for (meshIter = _meshes->begin(); meshIter != _meshes->end(); ++meshIter)
	{
		const std::string &meshName = (*meshIter).first;
		MeshData &mesh = (*meshIter).second;
		std::vector<Face> &faces = mesh.faces;

		// set mesh data
		int drawCount = faces.size() * 3; // each face is a triangle (3 vertices)

		model.addMeshData(meshName, offset, drawCount);
		
		offset += drawCount;

		std::vector<Face>::iterator iter;
		for (iter = faces.begin(); iter != faces.end(); ++iter)
		{
			Face& face = (*iter);

			int i;
			for (i = 0; i < 3; ++i)
			{
				int vIdx = face.vertices[i] - 1;
				int nIdx = face.normal[i] - 1;
				int tIdx = face.texCoord[i] - 1;

				if (vertSize > 0)
				{
					Vector3& v = _positions->at(vIdx);
					buffer.push_back(v.x);
					buffer.push_back(v.y);
					buffer.push_back(v.z);
				}

				if (normSize > 0)
				{
					Vector3& n = _normals->at(nIdx);
					buffer.push_back(n.x);
					buffer.push_back(n.y);
					buffer.push_back(n.z);
				}

				if (uvSize > 0)
				{
					Vector2 &uv = _texCoords->at(tIdx);
					buffer.push_back(uv.x);
					buffer.push_back(invertUV ? 1.0f - uv.y : uv.y);
				}
			}
		}
	}
	
	// faces times 3 vertices per triangle
	int drawCount = offset;

	// bind vertex data to mesh
	Buffer& vbo = mesh.getVBO();
	vbo.bind();
	vbo.setData(&buffer[0], buffer.size() * sizeof(float));
	vbo.unbind();

	mesh.setDrawCount(drawCount);
	
	mesh.create(stride * sizeof(float));
}
コード例 #27
0
void init()
{
	glClearColor(0.5, 0.5, 1.0, 1);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	// Note that the light is defined in the eye or camera frame.
	GLfloat light_position[] = {0.0, 0.0, 0.0, 1.0};

	GLfloat ambient[] = {0.3, 0.3, 0.3, 1};
	GLfloat diffuse[] = {1.0, 1.0, 1.0, 1};
	GLfloat specular[] = {1.0, 1.0, 1.0, 1};

	glLightfv(GL_LIGHT0, GL_POSITION, light_position);

	glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
	glLightfv(GL_LIGHT0, GL_SPECULAR, specular);

	glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
	glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);

	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_NORMALIZE);

	glEnable(GL_LIGHTING);	
	glEnable(GL_LIGHT0);

	// Generate display list for the surveillance camera.
	surveillanceCameraID = glGenLists(1);
	
	glNewList(surveillanceCameraID, GL_COMPILE);
	surveillanceCamera.Draw();
	glEndList();

	// Generate display list for the car.
	carID = glGenLists(1);
	glNewList(carID, GL_COMPILE);
	car.Draw();
	glEndList();



	board.SetLocation(boardPos);
	board.SetOrientation(boarddirection);
	board.SetSize(3, 2.5);
	board.ReadFile("Square.ppm");

	board2.SetLocation(boardPos2);
	board2.SetOrientation(boarddirection2);
	board2.SetSize(5, 3.5);
	board2.ReadFile("wendys.ppm");

	// Generate the display list for terrain, including road and grass.
	terrainID = glGenLists(1);
	glNewList(terrainID, GL_COMPILE);
	glDisable(GL_LIGHTING);

	// Grass
	glColor3f(0, 0.7, 0);
	glBegin(GL_QUADS);
		glVertex3f(-1000, 0, 1000);
		glVertex3f(-10, 0, 1000);
		glVertex3f(-10, 0, 10);
		glVertex3f(-1000, 0, 10);

		glVertex3f(10, 0, 1000);
		glVertex3f(1000, 0, 1000);
		glVertex3f(1000, 0, 10);
		glVertex3f(10, 0, 10);

		glVertex3f(10, 0, -10);
		glVertex3f(1000, 0, -10);
		glVertex3f(1000, 0, -1000);
		glVertex3f(10, 0, -1000);

		glVertex3f(-1000, 0, -10);
		glVertex3f(-10, 0, -10);
		glVertex3f(-10, 0, -1000);
		glVertex3f(-1000, 0, -1000);
	glEnd();

	// Roads
	glBegin(GL_QUADS);
		glColor3f(0.2, 0.2, 0.2);

		glVertex3f(-10, 0, 1000);
		glVertex3f(10, 0, 1000);
		glVertex3f(10, 0, -1000);
		glVertex3f(-10, 0, -1000);

		glVertex3f(-1000, 0, 10);
		glVertex3f(1000, 0, 10);
		glVertex3f(1000, 0, -10);
		glVertex3f(-1000, 0, -10);
	glEnd();

	// Yellow line South
	glBegin(GL_POLYGON);
		glColor3f(1, 1, 0);
		glVertex3f(-0.1, 0.05, 1000);
		glVertex3f(0.1, 0.05, 1000);
		glVertex3f(0.1, 0.05, 10);
		glVertex3f(-0.1, 0.05, 10);
	glEnd();
	// Yellow line North
	glBegin(GL_POLYGON);
	glColor3f(1, 1, 0);
	glVertex3f(-0.1, 0.05, -1000);
	glVertex3f(0.1, 0.05, -1000);
	glVertex3f(0.1, 0.05, -10);
	glVertex3f(-0.1, 0.05, -10);
	glEnd();
	// Yellow line west
	glBegin(GL_POLYGON);
	glColor3f(1, 1, 0);
	glVertex3f(-1000, 0.05, -0.1);
	glVertex3f(-1000, 0.05, 0.1);
	glVertex3f(-10, 0.05, 0.1);
	glVertex3f(-10, 0.05, -0.1);
	glEnd();
	// Yellow line east
	glBegin(GL_POLYGON);
	glColor3f(1, 1, 0);
	glVertex3f(1000, 0.05, -0.1);
	glVertex3f(1000, 0.05, 0.1);
	glVertex3f(10, 0.05, 0.1);
	glVertex3f(10, 0.05, -0.1);
	glEnd();
	// white dashed line South
	for (int i = 10; i <= 1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(4.9, 0.05, i);
		glVertex3f(5.1, 0.05, i);
		glVertex3f(5.1, 0.05, i + 3);
		glVertex3f(4.9, 0.05, i + 3);
		glEnd();
		i += 13;
	}
	
	for (int i = 10; i <= 1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(-4.9, 0.05, i);
		glVertex3f(-5.1, 0.05, i);
		glVertex3f(-5.1, 0.05, i + 3);
		glVertex3f(-4.9, 0.05, i + 3);
		glEnd();
		i += 13;
	}
	// white dashed line north
	for (int i = -10; i >= -1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(-4.9, 0.05, i);
		glVertex3f(-5.1, 0.05, i);
		glVertex3f(-5.1, 0.05, i - 3);
		glVertex3f(-4.9, 0.05, i - 3);
		glEnd();
		i -= 13;
	}

	for (int i = -10; i >= -1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(4.9, 0.05, i);
		glVertex3f(5.1, 0.05, i);
		glVertex3f(5.1, 0.05, i - 3);
		glVertex3f(4.9, 0.05, i - 3);
		glEnd();
		i -= 13;
	}
	// white dashed line west
	for (int i = -10; i >= -1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(i, 0.05, 4.9);
		glVertex3f(i, 0.05, 5.1);
		glVertex3f(i - 3, 0.05, 5.1);
		glVertex3f(i - 3, 0.05, 4.9);
		glEnd();
		i -= 13;
	}

	for (int i = -10; i >= -1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(i, 0.05, -4.9);
		glVertex3f(i, 0.05, -5.1);
		glVertex3f(i - 3, 0.05,-5.1);
		glVertex3f(i - 3, 0.05, -4.9);
		glEnd();
		i -= 13;
	}
	// white dashed line east
	for (int i = 10; i <= 1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(i, 0.05, -4.9);
		glVertex3f(i, 0.05, -5.1);
		glVertex3f(i + 3, 0.05, -5.1);
		glVertex3f(i + 3, 0.05, -4.9);
		glEnd();
		i += 13;
	}
	
	for (int i = 10; i <= 1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(i, 0.05, 4.9);
		glVertex3f(i, 0.05, 5.1);
		glVertex3f(i + 3, 0.05, 5.1);
		glVertex3f(i + 3, 0.05, 4.9);
		glEnd();
		i += 13;
	}




	glEndList();
}
コード例 #28
0
ファイル: World.cpp プロジェクト: streibeb/cs409
void World :: init ()
{
	if(!isInitialized())
	{
        // Skybox Init
        ObjModel sb;
        sb.load("Models/Skybox.obj");
        skybox = sb.getDisplayList();
        
        // Planet Init
        ObjModel p;
        p.load(planetInfo.filename);
        DisplayList p_dl = p.getDisplayList();
        PhysicsObjectId p_id = PhysicsObjectId(PhysicsObjectId::TYPE_PLANETOID,
                                             PhysicsObjectId::FLEET_NATURE,
                                             0);
        planet.initPlanetoid(p_id, planetInfo.position, planetInfo.radius, p_dl, 1.f);
        
        // Moon Init
        for (int i = 0; i < MOON_COUNT; i++)
        {
            ObjModel m;
            m.load(moonInfo[i].filename);
            DisplayList m_dl = m.getDisplayList();
            PhysicsObjectId m_id = PhysicsObjectId(PhysicsObjectId::TYPE_PLANETOID,
                                                   PhysicsObjectId::FLEET_NATURE,
                                                   i + 1);
            moons[i].initPlanetoid(m_id, moonInfo[i].position, moonInfo[i].radius, m_dl, 1.f);
        }
        
        // Ship Init
        ObjModel s;
        s.load("Models/Grapple.obj");
        DisplayList s_dl = s.getDisplayList();
        for (int i = 0; i < SHIP_COUNT; i++)
        {
            PhysicsObjectId s_id = PhysicsObjectId(PhysicsObjectId::TYPE_SHIP,
                                                   PhysicsObjectId::FLEET_ENEMY,
                                                   i);
            
            int moonIndex = rand() % MOON_COUNT;
            Vector3 pos = moonInfo[moonIndex].position
                            + Vector3::getRandomUnitVector()
                            * (moonInfo[moonIndex].radius + 500.0);
            
            ships[i].initPhysics(s_id, pos, 100.f, Vector3::getRandomUnitVector(), s_dl, 1.f);
            ships[i].setHealth(1);
            ships[i].setAmmo(0);
            ships[i].setSpeed(0.f);
        }
        
        // Add Bullets
        ObjModel b;
        b.load("Models/Bolt.obj");
        DisplayList b_dl = b.getDisplayList();
        for (int i = 0; i < BULLET_COUNT; i++)
        {
            PhysicsObjectId b_id = PhysicsObjectId(PhysicsObjectId::TYPE_BULLET,
                                                   PhysicsObjectId::FLEET_MAX,
                                                   i);
            bullets[i].initPhysics(b_id, {0, 0, 0}, 1.f, {0, 0, 0}, b_dl, 2.5f);
        }

		assert(mp_explosion_manager != NULL);
		mp_explosion_manager->init("Explode1.png", 15);
	}

	assert(invariant());
}
コード例 #29
0
//--------------------------------------------------
Scene::Scene(Input *input)
{
	camera = new Camera();
	cameraSpeed = 0.3f;
	this->input = input;

	sun = new Light(GL_LIGHT0);

	//SetupOpenGL

	//Blending
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0.01f);

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glEnable(GL_NORMALIZE);

	glDisable(GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

	texturLoader = new Texture();
	shLoader = new Shaderloader();

	mainObj = new Object();
	loadObjects("default", mainObj);

	terrain = new Terrain(texturLoader);
	skybox = new Skybox(texturLoader);
	water = new Object();
	ObjModel* watermod = new ObjModel();
	watermod->load("water", texturLoader, shLoader);
	water->addModel(watermod);

	armor = new ObjModel();
	armor->load("ruestung_old", texturLoader, shLoader);
	armorRotation = 0.0;

	torch1 = new ParticleSystem(texturLoader, Vector3f(15.0 - 300, 202.0, 26.0 + 700));
	torch2 = new ParticleSystem(texturLoader, Vector3f(287.0 - 300, 202.0, 26.0 + 700));

	helpText = new Text(texturLoader);

	//Save ModelMatrix
	glLoadIdentity();
	mainObj->saveModelMatrix();


	camera->move(200, -170, -500);

	// for students: uncomment this if you implemented environment mapping
	envShader = new Shader();
	envShader->load("./Daten/Shaders/Env_Mapping.vert", "./Daten/Shaders/Env_Mapping.frag");
	// end for students

	// set up our dynamic cubemap
	// uncomment this if you implemented environment mapping
	glEnable(GL_TEXTURE_CUBE_MAP_ARB);
	glGenTextures(1, &envText);
	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, envText);
	// end

	// set up some parameters
	// uncomment this if you implemented environment mapping
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
	//end

	// set up min and max filters
	// uncomment this if you implemented environment mapping
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	for (int i = 0; i < 6; i++)
	{
		glTexImage2D(cubeMapDefines[i], 0, GL_RGBA, CUBE_MAP_SIZE, CUBE_MAP_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
	}

	glDisable(GL_TEXTURE_CUBE_MAP_ARB);

	shadowMode = 0;

	//create shadowmap-texture

	shMapW = width;
	shMapH = height;

	shadowMap = 0;
	glGenTextures(1, &shadowMap);
	glBindTexture(GL_TEXTURE_2D, shadowMap);
	glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32_ARB, shMapW, shMapH, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

	shadowMapping = new Shader();
	shadowMapping->load("./Daten/Shaders/Shadow_Mapping.vert", "./Daten/Shaders/Shadow_Mapping.frag");
	shadowMappingAliased = new Shader();
	shadowMappingAliased->load("./Daten/Shaders/Shadow_Mapping.vert",
														 "./Daten/Shaders/Shadow_Mapping_Aliased.frag");

	// load toon shader
	toonShader = new Shader();
	toonShader->load("./Daten/Shaders/toon.vert", "./Daten/Shaders/toon.frag");
}