コード例 #1
0
ファイル: Test.cpp プロジェクト: hakuna-mathatha/Grafika
// Inicializacio, a program futasanak kezdeten, az OpenGL kontextus letrehozasa utan hivodik meg (ld. main() fv.)
void onInitialization() {
	glViewport(0, 0, screenWidth, screenHeight);

	Color ks = Color(0.4, 0.4, 0.4);
	Color kd = Color(255, 215, 0) / 255;
	Color k = Color(3.1, 2.7, 1.9);
	Color k_1 = Color(1.1, 1.7, 0.9);
	Color n = Color(0.17, 0.35, 1.5);
	Material *material = new Material(ks, Color(255, 200, 50) / 255, n, k,
			Color(), 50, false, false);
	Material *material_2 = new Material(ks, Color(205, 127, 50) / 255, n, k,
			Color(), 50, false, false);
	Material *material_3 = new Material(ks, Color(0, 178, 89) / 255, n, k,
			Color(), 50, true, false);

	Material *material_4 = new Material(ks, Color(0, 144, 244) / 255,
			Color(1.5, 1.5, 1.5), Color(), Color(), 50, false, true);
//	Sphere implementation----------------------------------------------
	Sphere *firstSphere = new Sphere(material_4);

//	Ellipsoid implementation-------------------------------------------
	Ellipsoid *firstEllipsoid = new Ellipsoid(material);
	myMatrix transfom1 = myMatrix(0.3, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.3, 0, 0,
			0, 0, 1);
	myMatrix transfom3 = myMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -0.2, 0,
			0.5, 1);
	myMatrix transfom2 = myMatrix(cos(M_PI / 6), sin(M_PI / 6), 0, 0,
			-sin(M_PI / 6), cos(M_PI / 6), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
	myMatrix transform4 = myMatrix(0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0.3, 0.2,
			1, 1);

	Vector normal = Vector(-0.529863, 0.253724, 0.80924, 1);
	Vector origo = Vector(-0.150579, 0.20029, 0.229974, 0);

	Hit hit = Hit();
	hit.normalVector = normal;
	hit.intersectPoint = origo;

	myMatrix tr1 = myMatrix(0.15, 0, 0, 0, 0, 0.25, 0, 0, 0, 0, 0.15, 0, 0, 0,
			0, 1);
	myMatrix tr3 = myMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0.25, 0, 1);
	myMatrix tr = getTheNewCoordSys(hit);

	Ellipsoid *secondEllipsoid = new Ellipsoid(material);
	myMatrix first_connection_matrix = tr1 * tr3 * tr;
	firstEllipsoid->setTrasformationMatrix(transfom1);
	secondEllipsoid->setTrasformationMatrix(first_connection_matrix);

	Vector normal_2 = normal * first_connection_matrix;
	Vector origo_2 = origo * first_connection_matrix;

	hit.normalVector = normal_2;
	hit.intersectPoint = origo_2;

	tr1 = myMatrix(0.15 , 0, 0, 0, 0, 0.25 , 0, 0, 0, 0,
			0.15 , 0, 0, 0, 0, 1);
	tr3 = myMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0.25 , 0,
			1);
	tr = getTheNewCoordSys(hit);
	Ellipsoid *thirdEllipsoid = new Ellipsoid(material);
	myMatrix second_connection_matrix = first_connection_matrix*tr;
	thirdEllipsoid->setTrasformationMatrix(second_connection_matrix);

//	Cylinder implementation---------------------------------------------
	Cylinder *firstCylinder = new Cylinder(material);
	transfom1 = myMatrix(0.2, 0, 0, 0, 0, 0.2, 0, 0, 0, 0, 0.2, 0, 0, 0, 0, 1);
	transfom3 = myMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.4, 0, -0.6, 1);
	transfom2 = myMatrix(cos(M_PI / 2), sin(M_PI / 2), 0, 0, -sin(M_PI / 2),
			cos(M_PI / 2), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
	firstCylinder->setTrasformationMatrix((transfom1 * transfom2) * transfom3);

//	Paraboloid implemenation--------------------------------------------
	Paraboloid *firstParaboloid = new Paraboloid(material_4);
	transfom1 = myMatrix(0.2, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.2, 0, 0, 0, 0, 1);
	transfom3 = myMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.4, 0, -0.6, 1);
	transfom2 = myMatrix(cos(M_PI / 2), sin(M_PI / 2), 0, 0, -sin(M_PI / 2),
			cos(M_PI / 2), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
	firstParaboloid->setTrasformationMatrix((transfom1) * transfom3);

//	Plane implementation------------------------------------------------
	Plane *firstPlane = new Plane(material_2);
	Plane2 *secondPlane = new Plane2(material_2);
	Scene scene = Scene();
	scene.AddObject((Intersectable*) firstPlane);
//	scene.AddObject((Intersectable*) firstCylinder);
//	scene.AddObject((Intersectable*) firstSphere);
	scene.AddObject((Intersectable*) firstEllipsoid);
	scene.AddObject((Intersectable*) secondEllipsoid);
//	scene.AddObject((Intersectable*) thirdEllipsoid);
//	scene.AddObject((Intersectable*) secondPlane);
//	scene.AddObject((Intersectable*) firstParaboloid);

	scene.SetAmbientColor(Color(77, 199, 253) / 255);

	PositionLightSource *light = new PositionLightSource(Vector(-1, 6, 7),
			Color(1, 1, 1));

	scene.AddLight((LightSource*) light);

	MyCamera camera = MyCamera(Vector(1, 2, 3), Vector(0, 0, 0),
			Vector(0, 1, 0));

	scene.SetCamera(camera);

	scene.render();

}