1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
//WORLD.H
#pragma once
#ifndef WORLD_H
#define WORLD_H
#include <iostream>
#include <windows.h>
#include "GLee.h"
#include <gl/gl.h>
#include <gl/glu.h>
#include <string>
#include <fstream>
#include <SDL.h>
#include "SDL_opengl.h"
#include "SDL_image.h"
#include "SDL_mixer.h"
#include <stdio.h>
#include <math.h>
#include <sstream>
#include "shaders.h"
#include "framebuffer.h"
#include "MoveAndRender.h"
#include "pipeline.h"
#include "sound.h"
#include "camera.h"
#include "Particles.h"
#include <vector>
using namespace std;
SDL_Event event;
RenderPipeline pipeline;
shader* mainshader;
Framebuffer screenfbo;
Camera camera;
MoveRender entity[2];
unsigned int texture;
bool running = true;
int r = 1;
#endif
//MAIN.CPP
#include "world.h"
int main(int argc, char* args[])
{
pipeline.setup("SATCollision", 640, 480, false, MODEL_MATRIX);
cout << glGetString(GL_VERSION) << endl;
mainshader = new shader("vertex.txt", "fragment.txt");
screenfbo.setup(640, 640);
texture = entity[0].loadtexture("texture.png");
for (int i = 0; i < 2; i++)
{
entity[i].readdata("entity.txt");
entity[i].init();
entity[i].setlocation((640/2)-32, (640/2)+128);
}
bool pause = false;
while(running)
{
pipeline.setdelta();
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
running = false;
case SDL_MOUSEMOTION:
{
if (!pause)
{
entity[0].x = event.motion.x - (entity[0].width / 2);
entity[0].y = event.motion.y + 168 + (entity[0].height / 2);
}
break;
}
case SDL_MOUSEWHEEL:
{
if (!pause)
{
if (event.wheel.y > 0)
entity[0].angle += 100 * pipeline.delta;
else
entity[0].angle -= 100 * pipeline.delta;
}
break;
}
case SDL_KEYDOWN:
{
if (event.key.keysym.sym == SDLK_SPACE)
{
pause = !pause;
cout << SATcollision(glm::vec2(274.759, 362.106), glm::vec2(318.894, 315.759), glm::vec2(365.241, 359.894), glm::vec2(321.106, 406.241), glm::vec2(288, 384), glm::vec2(352, 384), glm::vec2(252, 448), glm::vec2(322, 488)) << endl; // the function will return true here
for (int i = 0; i < 2; i++)
{
cout << "box " << i << " top left (" << entity[i].topLeft.x << ", " << entity[i].topLeft.y << ")" << endl;
cout << "box " << i << " top right (" << entity[i].topRight.x << ", " << entity[i].topRight.y << ")" << endl;
cout << "box " << i << " bottom right (" << entity[i].bottomRight.x << ", " << entity[i].bottomRight.y << ")" << endl;
cout << "box " << i << " bottom left (" << entity[i].bottomLeft.x << ", " << entity[i].bottomLeft.y << ")" << endl;
}
}
}
}
}
if (!pause)
{
cout << SATcollision(entity[0].topLeft, entity[0].topRight, entity[0].bottomRight, entity[0].bottomLeft, entity[1].topLeft, entity[1].topRight, entity[1].bottomRight, entity[1].bottomLeft) << endl;
if (SATcollision(entity[0].topLeft, entity[0].topRight, entity[0].bottomRight, entity[0].bottomLeft, entity[1].topLeft, entity[1].topRight, entity[1].bottomRight, entity[1].bottomLeft))
r = 0;
else
r = 1;
}
//rendering
glClearColor(GLclampf(0), GLclampf(0), GLclampf(0), GLclampf(1));
mainshader->useShader();
glBindFramebuffer(GL_FRAMEBUFFER, screenfbo.FBO);
glClear(GL_COLOR_BUFFER_BIT);
for (int i = 0; i < 2; i++)
{
pipeline.pushMatrix();
pipeline.ortho(0, 640, 640, 0, -1, 1);
pipeline.translate(camera.calcx(), camera.calcy(), 0);
pipeline.translate(entity[i].x + (entity[i].width / 2), entity[i].y - (entity[i].height / 2), 0);
pipeline.rotate(entity[i].angle, 0, 0, 1);
pipeline.rotate(entity[i].yangle, 0, 1, 0);
pipeline.translate(-(entity[i].x + (entity[i].width / 2)), -(entity[i].y - (entity[i].height / 2)), 0);
pipeline.updateMatrices(mainshader->getProgramID());
entity[i].render(mainshader->getProgramID(), texture, r); // render function where I render quad and find rotated values of points
pipeline.popMatrix();
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
//render screen fbo
pipeline.pushMatrix();
pipeline.ortho(0, 640, 640, 0, -1, 1);
pipeline.translate(((float)640 / 2), ((float)640 / 2), 0);
pipeline.rotate(camera.scamr, 0, 0, 1);
pipeline.translate(-(((float)640 / 2)), -(((float)640 / 2)), 0);
pipeline.updateMatrices(mainshader->getProgramID());
screenfbo.render(mainshader->getProgramID());
pipeline.popMatrix();
mainshader->delShader();
pipeline.swapBuffers();
}
return 0;
pipeline.deletepipeline();
screenfbo.~Framebuffer();
SDL_Quit();
}
|