Beispiel #1
0
Camera::Camera()
: Position(F3dVector(0, 0, 0))
, ViewDir(F3dVector(0, 0, -1))
, RightVector(F3dVector(1, 0, 0))
, UpVector(F3dVector(0, 1, 0))
, RotatedX(0)
, RotatedY(0)
, RotatedZ(0)
{}
Beispiel #2
0
CCamera::CCamera()
{
	Position = F3dVector (0.0, 0.0,	0.0);
	ViewDir = F3dVector( 0.0, 0.0, -1.0);
	RightVector = F3dVector (1.0, 0.0, 0.0);
	UpVector = F3dVector (0.0, 1.0, 0.0);

	RotatedX = RotatedY = RotatedZ = 0.0;
}
Beispiel #3
0
GlCamera::GlCamera()
{
	//Init with standard OGL values:
	position = F3dVector (0.0, 0.0,	0.0);
	viewDir = F3dVector( 0.0, 0.0, -1.0);
	rightVector = F3dVector (1.0, 0.0, 0.0);
	upVector = F3dVector (0.0, 1.0, 0.0);

	//Only to be sure:
	rotatedX = rotatedY = rotatedZ = 0.0;
}
CCamera::CCamera()
{
	//Init with standard OGL values:
	Position = F3dVector (0.0, 0.0,	0.0);
	ViewDir = F3dVector( 0.0, 0.0, -1.0);
	RightVector = F3dVector (1.0, 0.0, 0.0);
	UpVector = F3dVector (0.0, 1.0, 0.0);

	//Only to be sure:
	RotatedX = RotatedY = RotatedZ = 0.0;
}
Beispiel #5
0
Game::Game() : lastGeneratedEnemy(0), enemyGenerationDiff(startTimeDiff), 
lastChangedMap(0), mapScrollSpeed(0.2), lastGeneratedEnemyType(STANDARD) {
	
	leftDownCorner = F3dVector(-0.24, -0.07, 0.0);
	rightDownCorner = F3dVector(0.24, -0.07, 0.0);
	leftUpCorner = F3dVector(-0.24, 0.07, 0.0);
	rightUpCorner = F3dVector(0.24, 0.07,  0.0);

	player = new Player(F3dVector(0.0, 0.0, 0.0), this, 100);

	for (int i = 0; i < 256; ++i)
		keys[i] = false;
}
Beispiel #6
0
CCamera::CCamera()
{
	//Init with standard OGL values:
	Position = F3dVector (	0.0, 
							0.0,
							0.0);
	ViewDir = F3dVector(	0.0,
							0.0,
							-1.0);
	ViewDirChanged = false;
	//Only to be sure:
	RotatedX = RotatedY = RotatedZ = 0.0;
}
Beispiel #7
0
CCamera::CCamera()
{
	//Inicializa com os valores padrao:
	Position = F3dVector (	0.0, 
							0.0,
							0.0);
	ViewDir = F3dVector(	0.0,
							0.0,
							-1.0);
	ViewDirChanged = false;
	
	RotatedX = RotatedY = RotatedZ = 0.0;
}
Beispiel #8
0
void KeyDown(unsigned char key, int x, int y)
{	
	switch(key)
	{
	case 27:	//ESC
		exit(0);
		break;
	case 'a':		
		Camera.RotateY(5.0);
		Display();
		break;
	case 'd':		
		Camera.RotateY(-5.0);
		Display();
		break;
	case 'w':		
		Camera.MoveForwards( -0.3 ) ;
		Display();
		break;
	case 's':		
		Camera.MoveForwards( 0.3 ) ;
		Display();
		break;
	case 'x':		
		Camera.RotateX(5.0);
		Display();
		break;
	case 'y':		
		Camera.RotateX(-5.0);
		Display();
		break;
	case 'c':		
		Camera.StrafeRight(-0.3);
		Display();
		break;
	case 'v':		
		Camera.StrafeRight(0.3);
		Display();
		break;
	case 'f':
		Camera.Move(F3dVector(0.0,-0.3,0.0));
		Display();
		break;
	case 'r':
		Camera.Move(F3dVector(0.0,0.3,0.0));
		Display();
		break;

	
	}
}
Beispiel #9
0
void Game::generateEnemy() {
	clock_t currentTime = clock();
	if (currentTime - lastGeneratedEnemy > enemyGenerationDiff) {
		lastGeneratedEnemy = currentTime;

		GLfloat x = fRand(leftDownCorner.x, rightDownCorner.x);
		auto position = F3dVector(x, 0, -depth);
		auto velocity = F3dVector(0.0, 0.0, fRand(0.02, 0.15));
		auto red = Color(0.05, 0.9, 0.05);

		Enemy* newEnemy = new Enemy(this, position, velocity, red, 100);
		enemies.push_back(shared_ptr<Enemy>(newEnemy));
	}
}
Beispiel #10
0
void KeyDown(unsigned char key, int x, int y)
{	
	switch(key)
	{
	case 27:	//ESC
		exit(0);
		break;
	case 'a':		
		Camera.RotateY(5.0f);
		break;
	case 'd':		
		Camera.RotateY(-5.0f);
		break;
	case 'w':		
		Camera.MoveForwards( -0.15f ) ;
		break;
	case 's':		
		Camera.MoveForwards( 0.15f ) ;
		break;
	case 'x':		
		Camera.RotateX(5.0f);
		break;
	case 'y':		
		Camera.RotateX(-5.0f);
		break;
	case 'c':		
		Camera.StrafeRight(-0.05f);
		break;
	case 'v':		
		Camera.StrafeRight(0.05f);
		break;
	case 'f':
		Camera.Move(F3dVector(0.0,-0.1,0.0));
		break;
	case 'r':
		Camera.Move(F3dVector(0.0,0.1,0.0));
		break;
	case 'p':
		g_bPaused = ! g_bPaused;
		break;
	case 'l': 
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		break;
	case 'L': 
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		break;

	}
}
Beispiel #11
0
int main(int argc, char **argv)
{	
	//Initialize GLUT
	glutInit(&argc, argv);
	//Lets use doublebuffering, RGB(A)-mode and a depth buffer
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(800,600);
	//Create a window with rendering context and everything else we need
	glutCreateWindow("Particle Engine and Billboarding");
	//Init some state variables:
	glDisable(GL_DEPTH_TEST);
	glClearColor(0.1,0.1,0.1,1.0);
	glEnable(GL_POINT_SMOOTH);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	//also try GL_LINE
	
	g_Camera.Move(F3dVector(0.0f,0.3f,3.0f));
	

	//INITIALIZE THE PARTICLE SYSTEM:
	InitParticles();
	
	//Assign the event-handling routines
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutKeyboardFunc(KeyDown);
	glutIdleFunc(Display);  //If there is no msg, we have to repaint

	g_iLastRenderTime = timeGetTime();
	//Let GLUT get the msgs and tell us the ones we need
	glutMainLoop();
	return 0;
}
Beispiel #12
0
SF3dVector Normalize3dVector(SF3dVector v)
{
	SF3dVector res;
	float l= GetF3dVectorLength(v);
	if (l== 0.0f) return F3dVector(0, 0, 0);
	res.x= v.x/ l;
	res.y= v.y/ l;
	res.z= v.z/ l;
	return res;
}
Beispiel #13
0
int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(300,300);
	glutCreateWindow("Camera");
	Camera.Move( F3dVector(0.0, 0.0, 3.0 ));
	Camera.MoveForwards( 1.0 );
	glutDisplayFunc(Display);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(KeyDown);
	glutMainLoop();
	return 0;             
}
Beispiel #14
0
int main(int argc, char **argv)
{	
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(300,300);
	glutCreateWindow("Castle");
	glEnable(GL_DEPTH_TEST);
	glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
	glClearColor(0.0,0.0,0.0,0.0);
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutKeyboardFunc(KeyDown);
	Camera.Move(F3dVector(0.0,5.0,20.0));
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, MatSpec);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, MatShininess);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ModelAmb);
	Init();
	glutMainLoop();
	return 0;
}
Beispiel #15
0
int main (int argc, char **argv)
{
	//Initialize GLUT
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
	glutInitWindowSize(600,600);
	//Create a window with rendering context and everything else we need
	glutCreateWindow("Flag in the wind");


	//load the textures:
	FlagTexture1.LoadFromFile("germany.bmp");
	FlagTexture2.LoadFromFile("europe.bmp");
	FlagTexture3.LoadFromFile("portugal.bmp");
	GroundTexture.LoadFromFile("ground.bmp");

	//init texture stuff:
	GroundTexture.SetActive();
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	FlagTexture1.SetActive();
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	FlagTexture2.SetActive();
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	FlagTexture3.SetActive();
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);


	//initialize the flag:
	Flag.Initialize(40,26,2.0f,50.0f,0.997f);
	//and the values affecting it:
	wind = F3dVector (0.2,0.04,0.00);
	gravity = F3dVector(0.0,-0.015,0.0005);

	//initialize camera: 
	Camera.Move(F3dVector(1.0f, 0.0f, 15.0f));


	//Enable the vertex array functionality:
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY );
	glClearColor(0.0,0.0,1.0,0.0);  //blue background = sky ;-)
	
	//Switch on solid rendering:
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE ,1);
	glEnable(GL_DEPTH_TEST);

	//Initialize lighting:
	glEnable(GL_LIGHT1);								
	glEnable(GL_LIGHT2);

	glEnable(GL_LIGHTING);

	glFrontFace(GL_CCW);   //Tell OGL which orientation shall be the front face
	glShadeModel(GL_SMOOTH);

	//initialize generation of random numbers:
	srand((unsigned)time(NULL));

	
	//Assign the two used Msg-routines
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutKeyboardFunc(KeyDown);
	glutIdleFunc(Idle);
	//Let GLUT get the msgs
	glutMainLoop();
	return 0;
}
Beispiel #16
0
void InitParticles()
{
//INIT SYSTEM 1 (FIRE1)
	g_ParticleSystem1.Initialize(300);
	g_ParticleSystem1.m_iParticlesCreatedPerSec = 300;
	g_ParticleSystem1.m_fCreationVariance = 0.0f;
	g_ParticleSystem1.m_bRecreateWhenDied = false;
	g_ParticleSystem1.m_fMinDieAge = 0.5f;
	g_ParticleSystem1.m_fMaxDieAge = 1.5f;
	g_ParticleSystem1.SetCreationColor(1.0f,0.0f,0.0f,
									1.0f,0.0f,0.0f);
	g_ParticleSystem1.SetDieColor(1.0f,1.0f,1.0f,
							      1.0f,0.0f,0.0f);

	g_ParticleSystem1.SetAlphaValues(1.0f,0.0f,0.0f,0.0f);
	g_ParticleSystem1.SetEmitter(0.0f,0.0f,0.5f,
								0.1f,0.0f,0.1f);
	g_ParticleSystem1.SetAcceleration(F3dVector(0.0f,1.0f,0.0f),0.3f,0.4f);
	g_ParticleSystem1.SetSizeValues(0.04f,0.08f,0.06f,0.12f);
	g_ParticleSystem1.m_fMaxEmitSpeed = 0.2f;
	g_ParticleSystem1.m_fMinEmitSpeed = 0.3f;
	g_ParticleSystem1.SetEmissionDirection(0.0f,1.0f,0.0f,
										0.08f,0.5f,0.08f);
	g_ParticleSystem1.m_bParticlesLeaveSystem = true;
	g_ParticleSystem1.SetSpinSpeed(-0.82*PI,0.82*PI);
	g_ParticleSystem1.m_iBillboarding = BILLBOARDING_PERPTOVIEWDIR_BUTVERTICAL/*BILLBOARDING_PERPTOVIEWDIR*/;
	g_ParticleSystem1.LoadTextureFromFile("particle1.tga");

//INIT SYSTEM 2 (POINTS, FIREWORK)
	g_ParticleSystem2.Initialize(800);  //particle system must not have more than 800 particles
	g_ParticleSystem2.m_iParticlesCreatedPerSec = 800;  //we create all particles in the first second of the system's life
	g_ParticleSystem2.m_fMinDieAge = 2.5f;			//but the particles live longer than one second
	g_ParticleSystem2.m_fMaxDieAge = 2.5f;			//-> this causes the system to "shoot" periodically
		
	g_ParticleSystem2.m_fCreationVariance = 1.0f;
	g_ParticleSystem2.m_bRecreateWhenDied = true;
	g_ParticleSystem2.SetCreationColor(1.0f,1.0f,1.0f,
								0.5f,0.5f,0.5f);
	g_ParticleSystem2.SetDieColor(0.0f,1.0f,0.0f,
							   0.0f,0.3f,0.0f);
	g_ParticleSystem2.SetAlphaValues(1.0f,1.0f,0.0f,0.0f);
	g_ParticleSystem2.SetEmitter(0.8f,0.0f,0.0f,
								0.02f,0.0f,0.02f);
	g_ParticleSystem2.SetAcceleration(F3dVector(0.0f,-1.0f,0.0f),0.83f,1.4f);
	g_ParticleSystem2.SetSizeValues(3.0f,3.0f,4.0f,4.0f);
	g_ParticleSystem2.m_fMaxEmitSpeed = 0.82f;
	g_ParticleSystem2.m_fMinEmitSpeed = 1.3f;
	g_ParticleSystem2.SetEmissionDirection(-1.0f,2.0f,0.0f,
										0.5f,0.5f,0.5f);

	g_ParticleSystem2.m_bParticlesLeaveSystem = true;
	
//INIT SYSTEM 3 (RAIN)
	g_ParticleSystem3.Initialize(10000);
	g_ParticleSystem3.m_iParticlesCreatedPerSec = 4950;
	g_ParticleSystem3.m_fCreationVariance = 0.0f;
	g_ParticleSystem3.m_bRecreateWhenDied = false;
	g_ParticleSystem3.m_fMinDieAge = 2.0f;
	g_ParticleSystem3.m_fMaxDieAge = 2.0f;
	g_ParticleSystem3.SetCreationColor(0.0f,0.0f,1.0f,
									0.3f,0.3f,1.0f);
	g_ParticleSystem3.SetDieColor(0.4f,0.4f,1.0f,
							   0.0f,0.0f,1.0f);

	g_ParticleSystem3.SetAlphaValues(1.0f,1.0f,1.0f,1.0f);  
	g_ParticleSystem3.SetEmitter(0.0f,2.0f,0.0f,
								 1.0f,0.0f,1.0f);
	g_ParticleSystem3.SetAcceleration(NULL_VECTOR,0.0f,0.0f);
	g_ParticleSystem3.SetSizeValues(0.01f,0.01f,0.01f,0.01f);
	g_ParticleSystem3.m_fMaxEmitSpeed = 1.0f;
	g_ParticleSystem3.m_fMinEmitSpeed = 1.0f;
	g_ParticleSystem3.SetEmissionDirection(0.0f,-1.0f,0.0f,
										0.00f,0.0f,0.00f);
	g_ParticleSystem3.m_bParticlesLeaveSystem = true;
	g_ParticleSystem3.m_iBillboarding = BILLBOARDING_PERPTOVIEWDIR_BUTVERTICAL;
	g_ParticleSystem3.LoadTextureFromFile("particle2.tga");

//INIT SYSTEM 4 (SMOKE)
	g_ParticleSystem4.Initialize(150);
	g_ParticleSystem4.m_iParticlesCreatedPerSec = 50;
	g_ParticleSystem4.m_fCreationVariance = 0.0f;
	g_ParticleSystem4.m_bRecreateWhenDied = false;
	g_ParticleSystem4.m_fMinDieAge = 2.5f;
	g_ParticleSystem4.m_fMaxDieAge = 3.5f;
	g_ParticleSystem4.SetCreationColor(0.1f,0.1f,0.1f,
									0.2f,0.2f,0.2f);
	g_ParticleSystem4.SetDieColor(0.0f,0.0f,0.0f,
							   0.0f,0.0f,0.0f);

	g_ParticleSystem4.SetAlphaValues(1.0f,1.0f,0.0f,0.0f);
	g_ParticleSystem4.SetEmitter(-0.8f,0.0f,0.0f,
								0.0f,0.0f,0.0f);
	g_ParticleSystem4.SetAcceleration(F3dVector(0.0f,1.0f,0.0f),0.3f,0.4f);
	g_ParticleSystem4.SetSizeValues(0.0f,0.0f,1.12f,1.22f);
	g_ParticleSystem4.m_fMaxEmitSpeed = 0.01f;
	g_ParticleSystem4.m_fMinEmitSpeed = 0.04f;
	g_ParticleSystem4.SetEmissionDirection(0.0f,1.0f,0.0f,
										   0.08f,0.5f,0.08f);
	g_ParticleSystem4.m_bParticlesLeaveSystem = true;
	g_ParticleSystem4.m_iBillboarding = BILLBOARDING_PERPTOVIEWDIR;
	g_ParticleSystem4.LoadTextureFromFile("particle3.tga");

//INIT SYSTEM 5 ("ENGINE")
	g_ParticleSystem5.Initialize(300);
	g_ParticleSystem5.m_iParticlesCreatedPerSec = 200;
	g_ParticleSystem5.m_fCreationVariance = 0.0f;
	g_ParticleSystem5.m_bRecreateWhenDied = false;
	g_ParticleSystem5.m_fMinDieAge = 1.0f;
	g_ParticleSystem5.m_fMaxDieAge = 1.3f;
	g_ParticleSystem5.SetCreationColor(0.5f,0.0f,0.0f,
									0.5f,0.1f,0.1f);
	g_ParticleSystem5.SetDieColor(0.2f,0.2f,0.0f,
							   0.8f,0.8f,0.0f);

	g_ParticleSystem5.SetAlphaValues(1.0f,1.0f,0.3f,0.3f);
	g_ParticleSystem5.SetEmitter(0.0f,0.0f,-1.0f,
								0.02f,0.02f,0.0f);
	g_ParticleSystem5.SetAcceleration(F3dVector(0.0f,1.0f,0.0f),0.0f,0.0f);
	g_ParticleSystem5.SetSizeValues(0.12f,0.12f,0.06f,0.06f);
	g_ParticleSystem5.m_fMaxEmitSpeed = 0.12f;
	g_ParticleSystem5.m_fMinEmitSpeed = 0.14f;
	g_ParticleSystem5.SetEmissionDirection(0.0f,0.0f,1.0f,
										   0.00f,0.0f,0.00f);
	g_ParticleSystem5.m_bParticlesLeaveSystem = true;
	g_ParticleSystem5.m_iBillboarding = BILLBOARDING_PERPTOVIEWDIR;
	g_ParticleSystem5.LoadTextureFromFile("particle3.tga");

//INIT SYSTEM 6 (FIRE2)
	g_ParticleSystem6.Initialize(300);
	g_ParticleSystem6.m_iParticlesCreatedPerSec = 300;

	g_ParticleSystem6.m_bRecreateWhenDied = false;
	g_ParticleSystem6.m_fMinDieAge = 0.5f;
	g_ParticleSystem6.m_fMaxDieAge = 1.0f;
	g_ParticleSystem6.SetCreationColor(1.0f,0.0f,0.0f,
									1.0f,0.5f,0.0f);
	g_ParticleSystem6.SetDieColor(1.0f,1.0f,1.0f,
							      1.0f,0.5f,0.0f);

	g_ParticleSystem6.SetAlphaValues(1.0f,1.0f,0.0f,0.0f);
	g_ParticleSystem6.SetEmitter(0.0f,0.0f,0.5f,
								0.18f,0.0f,0.18f);
	g_ParticleSystem6.SetAcceleration(F3dVector(0.0f,1.0f,0.0f),0.3f,0.4f);
	g_ParticleSystem6.SetSizeValues(0.04f,0.08f,0.06f,0.12f);
	g_ParticleSystem6.m_fMaxEmitSpeed = 0.12f;
	g_ParticleSystem6.m_fMinEmitSpeed = 0.23f;
	g_ParticleSystem6.SetEmissionDirection(0.0f,1.0f,0.0f,
										0.08f,0.5f,0.08f);
	g_ParticleSystem6.m_bParticlesLeaveSystem = true;
	g_ParticleSystem6.SetSpinSpeed(-0.82*PI,0.82*PI);
	g_ParticleSystem6.m_iBillboarding = BILLBOARDING_PERPTOVIEWDIR;
	g_ParticleSystem6.LoadTextureFromFile("particle1.tga");

}