Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <GL/glut.h>
- #define _USE_MATH_DEFINES
- #include <math.h>
- //#include <gltext.hpp>
- //#include <SOIL.h>
- using namespace std;
- struct TVector {
- float x, y, z;
- };
- struct TColors {
- short R, G, B;
- };
- struct TObject3D {
- TVector position;
- TVector velocity;
- TVector rotation_angle;
- TVector rotation;
- TVector rotation_dir;
- float radius;
- float vector = 0.0;
- TColors color1;
- TColors color2;
- GLuint texture;
- // std::string name;
- };
- struct TLight {
- TVector position;
- TVector direction;
- float cutoff;
- };
- struct TView {
- TVector eye, vector;
- float angle;
- };
- // TObject3D objects[];
- TObject3D sphereOBJ1, sphereOBJ2, sphereOBJ3;
- TLight light0;
- TColors bkg;
- TView view;
- // short objects_count = 0;
- //GLuint tex;
- //GLUquadric* sphere1;
- //GLUquadric* sphere2;
- GLUquadricObj *sphere1;
- GLUquadricObj *sphere2;
- GLUquadricObj *sphere3;
- std::string tekst;
- #define GRAVITY 4.0
- #define MAX_NUM_LIGHTS 8
- #define PI 3.14159265
- void RunPhysics(float dt, TObject3D *object) {
- if ((object->position.x >= 7.0) || (object->position.x <= -7.0)) {
- object->velocity.x = -object->velocity.x;
- object->rotation_dir.x = -1 * object->rotation_dir.x;
- }
- if ((object->position.z >= 7.0) || (object->position.z <= -7.0)) {
- object->velocity.z = -object->velocity.z;
- object->rotation_dir.z = -1 * object->rotation_dir.z;
- }
- object->velocity.y += GRAVITY;
- object->rotation_angle.x += object->rotation.x * object->rotation_dir.x;
- object->rotation_angle.y += object->rotation.y * object->rotation_dir.y;
- object->rotation_angle.z += object->rotation.z * object->rotation_dir.z;
- object->position.x = object->position.x + object->velocity.x;
- object->position.y = object->position.y - object->velocity.y / 65536.0;
- object->position.z = object->position.z + object->velocity.z;
- if (object->position.y - object->radius < -1) {
- object->position.y = -1 + object->radius;
- object->velocity.y = -object->velocity.y;
- }
- object->vector = sqrt(object->velocity.x * object->velocity.x + object->velocity.z * object->velocity.z);
- // cout << object->position.y << "\n";
- // cout << object->vector << " " << object->position.x << " " << object->position.y << " " << object->position.z << "\n";
- }
- void CollisionDetect3(TObject3D *object1, TObject3D *object2) {
- // obliczenie odleglosci miedzy kulami
- float dx = abs(object1->position.x - object2->position.x);
- float dy = abs(object1->position.y - object2->position.y);
- float dz = abs(object1->position.z - object2->position.z);
- float distance = sqrt(dx*dx + dy*dy + dz*dz);
- // jesli odleglosc <= sumie promieni obu kul, nastepuje kolizja
- if (distance <= object1->radius + object2->radius) {
- // nadanie wartosci zmiennym pomocniczym...
- // wspolrzedne srodkow kul w chwili T0
- float obj1xT0 = object1->position.x - object1->velocity.x * 2;
- float obj1yT0 = object1->position.y - object1->velocity.y * 2;
- float obj1zT0 = object1->position.z - object1->velocity.z * 2;
- float obj2xT0 = object2->position.x - object2->velocity.x * 2;
- float obj2yT0 = object2->position.y - object2->velocity.y * 2;
- float obj2zT0 = object2->position.z - object2->velocity.z * 2;
- // wspolrzedne srodkow kul w chwili T
- float obj1xT = object1->position.x - object1->velocity.x;
- float obj1yT = object1->position.y - object1->velocity.y;
- float obj1zT = object1->position.z - object1->velocity.z;
- float obj2xT = object2->position.x - object2->velocity.x;
- float obj2yT = object2->position.y - object2->velocity.y;
- float obj2zT = object2->position.z - object2->velocity.z;
- // wspolrzedne srodkow kul w chwili zderzenia
- float obj1xZD = object1->position.x;
- float obj1yZD = object1->position.y;
- float obj1zZD = object1->position.z;
- float obj2xZD = object2->position.x;
- float obj2yZD = object2->position.y;
- float obj2zZD = object2->position.z;
- // skladowe predkosci kul
- float dvx1 = object1->velocity.x;
- float dvy1 = object1->velocity.y;
- float dvz1 = object1->velocity.z;
- float dvx2 = object2->velocity.x;
- float dvy2 = object2->velocity.y;
- float dvz2 = object2->velocity.z;
- // dlugosci wektorow predkosci wypadkowych w plaszczyznie XZ
- float obj1_velocity_xz = sqrt(dvx1*dvx1 + dvz1*dvz1);
- float obj2_velocity_xz = sqrt(dvx2*dvx2 + dvz2*dvz2);
- cout << "dlugosci wektorow: " << obj1_velocity_xz << " " << obj2_velocity_xz << "\n";
- // obliczanie kata pomiedzy osia X ukladu wpsolrzednych OX a osia dzeta ulkadu dzeta-eta
- // float sin_fi = (obj2xZD - obj1xZD) / sqrt((obj2xZD - obj1xZD) * (obj2xZD - obj1xZD) + (obj1zZD - obj2zZD) * (obj1zZD - obj2zZD));
- float cos_fi = (obj1zZD - obj2zZD) / sqrt((obj2xZD - obj1xZD) * (obj2xZD - obj1xZD) + (obj1zZD - obj2zZD) * (obj1zZD - obj2zZD));
- float fi = acos(cos_fi);
- cout << "kat miedzy X a dzeta: " << fi << "\n";
- // obliczanie katow pomiedzy wektorami predkosci kul a osia X ukladu wspolrzednych OX
- float cos_theta1 = abs(dvx1) / obj1_velocity_xz;
- float cos_theta2 = abs(dvx2) / obj2_velocity_xz;
- float theta1 = acos(cos_theta1);
- float theta2 = acos(cos_theta2);
- cout << "cosinusy theta: " << cos_theta1 << " " << cos_theta2 << "\n";
- cout << "katy miedzy predkosciami a osia X: " << theta1 << " " << theta2 << "\n";
- // obliczanie wektora stycznej obu kul
- double styczna_vec_x = dx * cos(90 * M_PI / 180) - dz * sin(90 * M_PI / 180);
- double styczna_vec_z = dx * sin(90 * M_PI / 180) + dz * cos(90 * M_PI / 180);
- double styczna_vec_len = sqrt((styczna_vec_x * styczna_vec_x) + (styczna_vec_z * styczna_vec_z));
- // skladowe predkosci obu kul po zderzeniu w ukladzie dzeta-eta. Wspolczynnik restytucji = 1, masa = 1
- float dzeta_eta_W1x = obj1_velocity_xz * cos(theta1 - fi);
- float dzeta_eta_W2x = obj2_velocity_xz * cos(theta2 - fi);
- float dzeta_eta_W1z = obj1_velocity_xz * ((1 - 1) / (1 + 1)) * sin(theta1 - fi) + obj2_velocity_xz * ((1 + 1) / (1 + 1)) * sin(theta2 - fi);
- float dzeta_eta_W2z = obj1_velocity_xz * ((1 * (1 + 1)) / (1 + 1)) * sin(theta1 - fi) + obj2_velocity_xz * ((1 - 1 * 1) / (1 + 1)) * sin(theta2 - fi);
- cout << "skladowe predkosci W w dzeta-eta: " << dzeta_eta_W1x << "," << dzeta_eta_W1z << " " << dzeta_eta_W2x << "," << dzeta_eta_W2z << "\n";
- // skladowe predkosci obu kul w chwili zderzenia w ukladzie dzeta-eta
- float dzeta_eta_V1x = abs(dvx1) * cos(fi) + abs(dvz1) * sin(fi);
- float dzeta_eta_V1z = abs(dvz1) * cos(fi) - abs(dvx1) * sin(fi);
- float dzeta_eta_V2x = abs(dvx2) * cos(fi) + abs(dvz2) * sin(fi);
- float dzeta_eta_V2z = abs(dvz2) * cos(fi) - abs(dvx2) * sin(fi);
- // obliczanie skladowych X i Z predkosci koncowych W1 i W2
- float W1x = dzeta_eta_W1x * cos(fi) - dzeta_eta_W1z * sin(fi);
- float W1z = dzeta_eta_W1x * sin(fi) + dzeta_eta_W1z * cos(fi);
- float W2x = dzeta_eta_W2x * cos(fi) - dzeta_eta_W2z * sin(fi);
- float W2z = dzeta_eta_W2x * sin(fi) + dzeta_eta_W2z * cos(fi);
- cout << "skladowe predkosci W: " << W1x << "," << W1z << " " << W2x << "," << W2z << "\n";
- // obliczanie predkosci koncowych W1, W2
- float W1 = sqrt(W1x * W1x + W1z * W1z);
- float W2 = sqrt(W2x * W2x + W2z * W2z);
- // obliczanie katow miedzy wektorami W2, W1 a osia X
- float cos_psi1 = W1x / W1;
- float cos_psi2 = W2x / W2;
- float psi1 = acos(cos_psi1);
- float psi2 = acos(cos_psi2);
- // obliczanie kata miedzy wektorem W2 a osia dzeta
- float alpha = psi2 - fi;
- // cout << "predkosci koncowe: " << W1 << " " << W2 << "\n\n";
- // koniec
- float dvx1_new = W1x;
- float dvz1_new = W1z;
- float dvx2_new = W2x;
- float dvz2_new = W2z;
- object1->velocity.x = dvx1_new;
- object1->velocity.z = dvz1_new;
- object2->velocity.x = dvx2_new;
- object2->velocity.z = dvz2_new;
- if (object2->position.y < object1->position.y) object2->velocity.y = -object2->velocity.y;
- else if (object1->position.y <= object2->position.y) object1->velocity.y = -object1->velocity.y;
- /*object1->position.x += object1->velocity.x;
- object1->position.z += object1->velocity.z;
- object1->position.y += object1->velocity.y;
- object2->position.x += object2->velocity.x;
- object2->position.z += object2->velocity.z;
- object2->position.y += object2->velocity.y; */
- // cout << "kolizja " << "predkosc W1: " << W1 << " " << W1x << " " << W1z << " ... W2: " << W2 << " " << W2x << " " << W2z << "\n";
- // cout << "fi " << fi << " theta1: " << theta1 << " theta2: " << theta2 << "\n";
- }
- }
- void make_tex(TObject3D *object) {
- unsigned char data[128][128][3];
- for (int y = 0; y < 128; y++) {
- for (int x = 0; x < 128; x++) {
- unsigned char *p = data[y][x];
- if ((x ^ y) & 2) {
- p[0] = object->color1.R;
- p[1] = object->color1.G;
- p[2] = object->color1.B;
- }
- else {
- p[0] = object->color2.R;
- p[1] = object->color2.G;
- p[2] = object->color2.B;
- }
- }
- }
- glGenTextures(1, &(object->texture));
- glBindTexture(GL_TEXTURE_2D, object->texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, (const GLvoid *)data);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- }
- void draw() {
- glClearColor((float)bkg.R/256, (float)bkg.G/256, (float)bkg.B/256, 1);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(sphereOBJ1.position.x, sphereOBJ1.position.y, sphereOBJ1.position.z);
- glRotatef(150, 0.0, 1.0, 1.0);
- glRotatef(sphereOBJ1.rotation_angle.x, 0.0, 0.0, 2.0);
- glColor3f(1.0, 1.0, 1.0);
- gluQuadricDrawStyle(sphere1, GLU_FILL);
- glBindTexture(GL_TEXTURE_2D, sphereOBJ1.texture);
- gluQuadricTexture(sphere1, GL_TRUE);
- gluQuadricNormals(sphere1, GLU_SMOOTH);
- gluSphere(sphere1, sphereOBJ1.radius, 32, 16);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(sphereOBJ2.position.x, sphereOBJ2.position.y, sphereOBJ2.position.z);
- glRotatef(150, 0.0, 1.0, 1.0);
- glRotatef(sphereOBJ2.rotation_angle.x, 0.0, 0.0, 2.0);
- glColor3f(1.0, 1.0, 1.0);
- gluQuadricDrawStyle(sphere2, GLU_FILL);
- glBindTexture(GL_TEXTURE_2D, sphereOBJ2.texture);
- gluQuadricTexture(sphere2, GL_TRUE);
- gluQuadricNormals(sphere2, GLU_SMOOTH);
- gluSphere(sphere2, sphereOBJ2.radius, 32, 16);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(sphereOBJ3.position.x, sphereOBJ3.position.y, sphereOBJ3.position.z);
- glRotatef(150, 0.0, 1.0, 1.0);
- glRotatef(sphereOBJ3.rotation_angle.x, 0.0, 0.0, 2.0);
- glColor3f(1.0, 1.0, 1.0);
- gluQuadricDrawStyle(sphere3, GLU_FILL);
- glBindTexture(GL_TEXTURE_2D, sphereOBJ3.texture);
- gluQuadricTexture(sphere3, GL_TRUE);
- gluQuadricNormals(sphere3, GLU_SMOOTH);
- gluSphere(sphere3, sphereOBJ3.radius, 32, 16);
- glutSwapBuffers();
- }
- void resize(int w, int h) {
- if (!h) h = 1;
- glViewport(0, 0, w, h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(60.0, 1.00*w / h , 1.0, 100);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(view.eye.x, view.eye.y, view.eye.z, view.eye.x + view.vector.x, view.vector.y, view.eye.z - view.vector.z, 0.0, 1.0, 0.0);
- }
- void changeView(bool symbol1, bool symbol2) {
- view.eye.x = (symbol1 == 1) ? view.eye.x + view.vector.z : view.eye.x - view.vector.z;
- view.eye.z = (symbol2 == 1) ? view.eye.z + view.vector.x : view.eye.z - view.vector.x;
- }
- void inputSpecial(int key, int x, int y) {
- cout << key << "\n";
- if (key == GLUT_KEY_UP) {
- // cout << "up" << "\n";
- // if ((view.angle >= 0) && (view.angle < 90)) ((int)view.angle % 90) == 0 ? view.eye.z -= 1.0 : changeView(1, 0);
- // else if ((view.angle >= 90) && (view.angle < 180)) ((int)view.angle % 90) == 0 ? view.eye.x += 1.0 : changeView(1, 0);
- // else if ((view.angle >= 180) && (view.angle < 270)) ((int)view.angle % 90) == 0 ? view.eye.z += 1.0 : changeView(1, 0);
- // else if ((view.angle >= 270) && (view.angle < 360)) ((int)view.angle % 90) == 0 ? view.eye.x -= 1.0 : changeView(1, 0);
- if ((view.angle >= 0) && (view.angle < 90)) {
- if (((int)view.angle % 90) == 0) {
- view.eye.z = view.eye.z -= 1.0;
- }
- else {
- view.eye.z = view.eye.z - view.vector.z;
- view.eye.x = view.eye.x + view.vector.x;
- }
- }
- else if ((view.angle >= 90) && (view.angle < 180)) {
- if (((int)view.angle % 90) == 0) {
- view.eye.x = view.eye.x += 1.0;
- }
- else {
- view.eye.z = view.eye.z - view.vector.z;
- view.eye.x = view.eye.x + view.vector.x;
- }
- }
- else if ((view.angle >= 180) && (view.angle < 270)) {
- if (((int)view.angle % 90) == 0) {
- view.eye.z = view.eye.z += 1.0;
- }
- else {
- view.eye.z = view.eye.z - view.vector.z;
- view.eye.x = view.eye.x + view.vector.x;
- }
- }
- else if ((view.angle >= 270) && (view.angle < 360)) {
- if (((int)view.angle % 90) == 0) {
- view.eye.x = view.eye.x -= 1.0;
- }
- else {
- view.eye.z = view.eye.z - view.vector.z;
- view.eye.x = view.eye.x + view.vector.x;
- }
- }
- }
- else if (key == GLUT_KEY_DOWN) {
- // cout << "down" << "\n";
- // if ((view.angle >= 0) && (view.angle < 90)) ((int)view.angle % 90) == 0 ? view.eye.z += 1.0 : changeView(0, 1);
- // else if ((view.angle >= 90) && (view.angle < 180)) ((int)view.angle % 90) == 0 ? view.eye.x -= 1.0 : changeView(0, 0);
- // else if ((view.angle >= 180) && (view.angle < 270)) ((int)view.angle % 90) == 0 ? view.eye.z -= 1.0 : changeView(0, 1);
- // else if ((view.angle >= 270) && (view.angle < 360)) ((int)view.angle % 90) == 0 ? view.eye.x += 1.0 : changeView(0, 1);
- if ((view.angle >= 0) && (view.angle < 90)) {
- if (((int)view.angle % 90) == 0) {
- view.eye.z = view.eye.z += 1.0;
- }
- else {
- view.eye.z = view.eye.z + view.vector.z;
- view.eye.x = view.eye.x - view.vector.x;
- }
- }
- else if ((view.angle >= 90) && (view.angle < 180)) {
- if (((int)view.angle % 90) == 0) {
- view.eye.x = view.eye.x -= 1.0;
- }
- else {
- view.eye.z = view.eye.z + view.vector.z;
- view.eye.x = view.eye.x - view.vector.x;
- }
- }
- else if ((view.angle >= 180) && (view.angle < 270)) {
- if (((int)view.angle % 90) == 0) {
- view.eye.z = view.eye.z -= 1.0;
- }
- else {
- view.eye.z = view.eye.z + view.vector.z;
- view.eye.x = view.eye.x - view.vector.x;
- }
- }
- else if ((view.angle >= 270) && (view.angle < 360)) {
- if (((int)view.angle % 90) == 0) {
- view.eye.x = view.eye.x += 1.0;
- }
- else {
- view.eye.z = view.eye.z + view.vector.z;
- view.eye.x = view.eye.x - view.vector.x;
- }
- }
- }
- else if (key == GLUT_KEY_LEFT) {
- if (glutGetModifiers() & GLUT_ACTIVE_ALT) {
- cout << "left" << "\n";
- if ((view.angle >= 0) && (view.angle < 90)) ((int)view.angle % 90) == 0 ? view.eye.x -= 1.0 : changeView(0, 0);
- else if ((view.angle >= 90) && (view.angle < 180)) ((int)view.angle % 90) == 0 ? view.eye.z -= 1.0 : changeView(0, 0);
- else if ((view.angle >= 180) && (view.angle < 270)) ((int)view.angle % 90) == 0 ? view.eye.x += 1.0 : changeView(0, 0);
- else if ((view.angle >= 270) && (view.angle < 360)) ((int)view.angle % 90) == 0 ? view.eye.z += 1.0 : changeView(0, 0);
- }
- else {
- cout << "left2" << "\n";
- view.angle -= 3;
- if (view.angle == -3) view.angle = 357;
- view.vector.x = sin(view.angle * PI / 180);
- view.vector.z = cos(view.angle * PI / 180);
- }
- }
- else if (key == GLUT_KEY_RIGHT) {
- if (glutGetModifiers() & GLUT_ACTIVE_ALT) {
- cout << "right" << "\n";
- if ((view.angle >= 0) && (view.angle < 90)) ((int)view.angle % 90) == 0 ? view.eye.x += 1.0 : changeView(1, 1);
- else if ((view.angle >= 90) && (view.angle < 180)) ((int)view.angle % 90) == 0 ? view.eye.z += 1.0 : changeView(1, 1);
- else if ((view.angle >= 180) && (view.angle < 270)) ((int)view.angle % 90) == 0 ? view.eye.x -= 1.0 : changeView(1, 1);
- else if ((view.angle >= 270) && (view.angle < 360)) ((int)view.angle % 90) == 0 ? view.eye.z -= 1.0 : changeView(1, 1);
- }
- else {
- cout << "right2" << "\n";
- view.angle += 3;
- if (view.angle == 360) view.angle = 0;
- view.vector.x = sin(view.angle * PI / 180);
- view.vector.z = cos(view.angle * PI / 180);
- }
- }
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(60.0, (GLdouble)1024 / 768, 1.0, 100);
- gluLookAt(view.eye.x, view.eye.y, view.eye.z, view.eye.x + view.vector.x, view.eye.y, view.eye.z - view.vector.z, 0.0, 1.0, 0.0);
- glutPostRedisplay();
- }
- void inputStd(unsigned char key, int x, int y) {
- switch (key) {
- case 27:
- exit(0);
- break;
- default:
- break;
- }
- }
- void addObject(
- float posx,float posy,float posz,
- float velx,float vely,float velz,
- float rotangx, float rotangy, float rotangz,
- float rotx, float roty, float rotz,
- float rotdirx, float rotdiry, float rotdirz,
- float rad, float vec,
- short col1r, short col1g, short col1b,
- short col2r, short col2g, short col2b,
- GLuint tex) {
- //objects_count++;
- // objects[objects_count].position.y = "abc";
- // objects[objects_count] = { { posx, posy, posz }, { velx, vely, velz }, { rotangx, rotangy, rotangz }, { rotx, roty, rotz }, { rotdirx, rotdiry, rotdirz }, rad, vec, { col1r, col1g, col1b }, { col2r, col2g, col2b }, tex };
- // { 26, "Jim Smith" } };
- /*object->position.y = posy;
- object->position.z = posz;
- object->velocity.x = velx;
- object->velocity.y = vely;
- object->velocity.z = velz;
- object->rotation_angle.x = rotangx;
- object->rotation_angle.y = rotangy;
- object->rotation_angle.z = rotangz;
- object->rotation.x = rotx;
- object->rotation.y = roty;
- object->rotation.z = rotz;
- object->rotation_dir.x = rotdirx;
- object->rotation_dir.y = rotdiry;
- object->rotation_dir.z = rotdirz;
- object->radius = rad;
- object->color1.R = col1r;
- object->color1.G = col1g;
- object->color1.B = col1b;
- object->color2.R = col2r;
- object->color2.G = col2g;
- object->color2.B = col2b;*/
- }
- void init(void) {
- bkg.R = 169;
- bkg.G = 167;
- bkg.B = 169;
- // addObject(0.0, 0.5, 0.0, 0.005, 0, 0.005, 0.0, 0.0, 0.0, 0.2, 0.0, 0, -1, 0, 0, 1.0, 0, 255, 255, 255, 255, 0, 0, 1);
- // addObject(2.0, 0.1, 1.0, 0.003, 0, 0.009, 0.0, 0.0, 0.0, 0.2, 0.1, 0, 1, 0, 0, 0.25, 0, 255, 255, 255, 0, 255, 255, 2);
- // addObject(2.0, 0.1, 1.0, 0.003, 0, 0.009, 0.0, 0.0, 0.0, 0.2, 0.1, 0, 1, 0, 0, 0.25, 0, 255, 255, 255, 0, 255, 255, 3);
- sphereOBJ1.position.x = 0.0;
- sphereOBJ1.position.y = 0.5;
- sphereOBJ1.position.z = 0.0;
- sphereOBJ1.velocity.x = 0.003;
- sphereOBJ1.velocity.y = 0.0;
- sphereOBJ1.velocity.z = 0.02;
- sphereOBJ1.rotation_angle.x = 0.0;
- sphereOBJ1.rotation_angle.y = 0.0;
- sphereOBJ1.rotation_angle.z = 0.0;
- sphereOBJ1.rotation.x = 0.2;
- sphereOBJ1.rotation.y = 0;
- sphereOBJ1.rotation.z = 0;
- sphereOBJ1.rotation_dir.x = -1;
- sphereOBJ1.rotation_dir.y = 0;
- sphereOBJ1.rotation_dir.z = 0;
- sphereOBJ1.radius = 1.0;
- sphereOBJ1.color1.R = 255;
- sphereOBJ1.color1.G = 255;
- sphereOBJ1.color1.B = 255;
- sphereOBJ1.color2.R = 255;
- sphereOBJ1.color2.G = 0;
- sphereOBJ1.color2.B = 0;
- //addObject(&sphereOBJ2, 2.0, 0.1, 1.0, 0.003, 0, 0.009, 0.0, 0.0, 0.0, 0.2, 0.1, 0, 1, 0, 0, 0.25, 255, 255, 255, 0, 255, 255);
- sphereOBJ2.position.x = 2.0;
- sphereOBJ2.position.y = 0.1;
- sphereOBJ2.position.z = 2.0;
- sphereOBJ2.velocity.x = 0.005;
- sphereOBJ2.velocity.y = 0.0;
- sphereOBJ2.velocity.z = -0.010;
- sphereOBJ2.rotation_angle.x = 0.0;
- sphereOBJ2.rotation_angle.y = 0.0;
- sphereOBJ2.rotation_angle.z = 0.0;
- sphereOBJ2.rotation.x = 0.2;
- sphereOBJ2.rotation.y = 0.1;
- sphereOBJ2.rotation.z = 0;
- sphereOBJ2.rotation_dir.x = 1;
- sphereOBJ2.rotation_dir.y = 0;
- sphereOBJ2.rotation_dir.z = 0;
- sphereOBJ2.radius = 0.5;
- sphereOBJ2.color1.R = 255;
- sphereOBJ2.color1.G = 255;
- sphereOBJ2.color1.B = 255;
- sphereOBJ2.color2.R = 0;
- sphereOBJ2.color2.G = 0;
- sphereOBJ2.color2.B = 255;
- sphereOBJ3.position.x = 4.0;
- sphereOBJ3.position.y = 0.3;
- sphereOBJ3.position.z = 5.0;
- sphereOBJ3.velocity.x = 0.004;
- sphereOBJ3.velocity.y = 0.0;
- sphereOBJ3.velocity.z = 0.004;
- sphereOBJ3.rotation_angle.x = 0.0;
- sphereOBJ3.rotation_angle.y = 0.0;
- sphereOBJ3.rotation_angle.z = 0.0;
- sphereOBJ3.rotation.x = 0.1;
- sphereOBJ3.rotation.y = 0;
- sphereOBJ3.rotation.z = 0;
- sphereOBJ3.rotation_dir.x = 1;
- sphereOBJ3.rotation_dir.y = 0;
- sphereOBJ3.rotation_dir.z = 0;
- sphereOBJ3.radius = 0.75;
- sphereOBJ3.color1.R = 255;
- sphereOBJ3.color1.G = 255;
- sphereOBJ3.color1.B = 255;
- sphereOBJ3.color2.R = 255;
- sphereOBJ3.color2.G = 0;
- sphereOBJ3.color2.B = 255;
- view.eye.x = 0.0;
- // view.eye.y = 5.0;
- view.eye.y = 0.0;
- view.eye.z = 10.0;
- view.vector.x = 0.0;
- // view.vector.y = -10.0;
- view.vector.y = 0.0;
- view.vector.z = 1.0;
- view.angle = 0.0;
- light0.position.x = 0.0;
- light0.position.y = 2.0;
- light0.position.z = 3.0;
- light0.direction.x = 1.0;
- light0.direction.y = 1.0;
- light0.direction.z = -1.0;
- tekst = "ala";
- // light1.position.x = 0.0;
- // light1.position.y = -2.0;
- // light1.position.z = 3.0;
- // light1.direction.x = 1.0;
- // light1.direction.y = 1.0;
- // light1.direction.z = -1.0;
- GLfloat light0_position[] = { light0.position.x, light0.position.y, light0.position.z, 0.0 };
- GLfloat spot0_direction[] = { light0.direction.x, light0.direction.y, light0.direction.z };
- GLfloat spot0_cutoff = 180;
- // GLfloat light1_position[] = { light1.position.x, light1.position.y, light1.position.z, 0.0 };
- // GLfloat spot1_direction[] = { light1.direction.x, light1.direction.y, light1.direction.z };
- // GLfloat spot1_cutoff = 180;
- GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
- GLfloat mat_shininess[] = { 50.0 };
- GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
- GLfloat diffuseLight[] = { 0.8f, 0.8f, 0.8, 1.0f };
- GLfloat specularLight[] = { 0.5f, 0.5f, 0.5f, 1.0f };
- glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
- glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot0_direction);
- glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, spot0_cutoff);
- // glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
- // glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot1_direction);
- // glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, spot1_cutoff);
- glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
- glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
- // Assign created components to GL_LIGHT0
- glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
- glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- // glEnable(GL_LIGHT1);
- glEnable(GL_DEPTH_TEST);
- // for (short i = 0; ++i; i < objects_count) {
- make_tex(&sphereOBJ1);
- make_tex(&sphereOBJ2);
- make_tex(&sphereOBJ3);
- // }
- sphere1 = gluNewQuadric();
- sphere2 = gluNewQuadric();
- sphere3 = gluNewQuadric();
- glEnable(GL_TEXTURE_2D);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(view.eye.x, view.eye.y, view.eye.z, view.eye.x + view.vector.x, view.vector.y, view.eye.z - view.vector.z, 0.0, 1.0, 0.0);
- glColor3d(0, 0, 0);
- }
- void myIdle() {
- CollisionDetect3(&sphereOBJ1, &sphereOBJ2);
- CollisionDetect3(&sphereOBJ1, &sphereOBJ3);
- CollisionDetect3(&sphereOBJ2, &sphereOBJ3);
- RunPhysics(0.003, &sphereOBJ1);
- RunPhysics(0.003, &sphereOBJ2);
- RunPhysics(0.003, &sphereOBJ3);
- draw();
- }
- int main(int argc, char **argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- glutInitWindowSize(1024,768);
- glutCreateWindow("Test");
- glutDisplayFunc(draw);
- glutKeyboardFunc(inputStd);
- glutSpecialFunc(inputSpecial);
- glutIdleFunc(myIdle);
- glutReshapeFunc(resize);
- init();
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement