engineOffset #2
@ -57,7 +57,7 @@
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
|
@ -6,7 +6,7 @@ struct PointLight {
|
||||
float intensity;
|
||||
};
|
||||
|
||||
#define NR_POINT_LIGHTS 3
|
||||
#define NR_POINT_LIGHTS 5
|
||||
|
||||
uniform vec3 objectColor;
|
||||
uniform vec3 lightPos;
|
||||
|
54
src/main.cpp
54
src/main.cpp
@ -1,4 +1,4 @@
|
||||
#include "glew.h"
|
||||
#include "glew.h"
|
||||
#include "freeglut.h"
|
||||
#include "glm.hpp"
|
||||
#include "ext.hpp"
|
||||
@ -53,6 +53,8 @@ std::vector<Core::RenderContext> corvetteMeshes;
|
||||
float cameraAngle = 0;
|
||||
glm::vec3 cameraPos = glm::vec3(-6, 0, 0);
|
||||
glm::vec3 cameraDir;
|
||||
glm::vec3 cameraSide;
|
||||
|
||||
|
||||
glm::mat4 cameraMatrix, perspectiveMatrix;
|
||||
|
||||
@ -89,20 +91,21 @@ void keyboard(unsigned char key, int x, int y)
|
||||
float moveSpeed = 0.1f;
|
||||
switch (key)
|
||||
{
|
||||
case 'z': cameraAngle -= angleSpeed; break;
|
||||
case 'x': cameraAngle += angleSpeed; break;
|
||||
case 'q': cameraAngle -= angleSpeed; break;
|
||||
case 'e': cameraAngle += angleSpeed; break;
|
||||
case 'w':
|
||||
{
|
||||
cameraPos += cameraDir * moveSpeed;
|
||||
lights[2].intensity = 0.001;
|
||||
lights[3].intensity = 0.001;
|
||||
engineLightTimer = 0;
|
||||
break;
|
||||
}
|
||||
case 's': cameraPos -= cameraDir * moveSpeed; break;
|
||||
case 'd': cameraPos += glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
|
||||
case 'a': cameraPos -= glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
|
||||
case 'e': cameraPos += glm::cross(cameraDir, glm::vec3(1, 0, 0)) * moveSpeed; break;
|
||||
case 'q': cameraPos -= glm::cross(cameraDir, glm::vec3(1, 0, 0)) * moveSpeed; break;
|
||||
case 'z': cameraPos += glm::cross(cameraDir, glm::vec3(0, 0, 1)) * moveSpeed; break;
|
||||
case 'x': cameraPos -= glm::cross(cameraDir, glm::vec3(0, 0, 1)) * moveSpeed; break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,6 +115,8 @@ glm::mat4 createCameraMatrix()
|
||||
cameraDir = glm::vec3(cosf(cameraAngle), 0.0f, sinf(cameraAngle));
|
||||
glm::vec3 up = glm::vec3(0, 1, 0);
|
||||
|
||||
cameraSide = glm::cross(cameraDir,up);
|
||||
|
||||
return Core::createViewMatrix(cameraPos, cameraDir, up);
|
||||
}
|
||||
float frustumScale = 1.f;
|
||||
@ -249,10 +254,10 @@ void renderScene()
|
||||
glUseProgram(programSun);
|
||||
glUniform3f(glGetUniformLocation(programSun, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||
|
||||
//ustalanie pozycji słońc (lightPos)
|
||||
//ustalanie pozycji s³oñc (lightPos)
|
||||
|
||||
|
||||
//rysowanie słońc
|
||||
//rysowanie s³oñc
|
||||
glm::mat4 sunModelMatrix = glm::mat4(1.0f);
|
||||
sunModelMatrix = glm::translate(sunModelMatrix, sunPos);
|
||||
sunModelMatrix = glm::scale(sunModelMatrix, glm::vec3(3.0f, 3.0f, 3.0f));
|
||||
@ -269,8 +274,13 @@ void renderScene()
|
||||
lights[0].position = sunPos;
|
||||
lights[1].position = sunPos2;
|
||||
|
||||
lights[2].position = cameraPos + cameraDir * 0.6f + glm::vec3(0, -0.25f, 0);
|
||||
lights[2].color = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.6f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f));
|
||||
glm::mat4 engineLeft = glm::translate(shipModelMatrix, glm::vec3(500,0,-1500));
|
||||
lights[2].position = glm::vec3(engineLeft[3][0], engineLeft[3][1], engineLeft[3][2]);
|
||||
|
||||
glm::mat4 engineRight = glm::translate(shipModelMatrix, glm::vec3(-500, 0, -1500));
|
||||
lights[3].position = glm::vec3(engineRight[3][0], engineRight[3][1], engineRight[3][2]);
|
||||
|
||||
|
||||
for (int i = 0; i < lights.size(); i++)
|
||||
{
|
||||
@ -286,13 +296,14 @@ void renderScene()
|
||||
|
||||
|
||||
//rysowanie statku
|
||||
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.6f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f));
|
||||
//glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.6f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f));
|
||||
|
||||
drawFromAssimpModel(programTex, corvette, shipModelMatrix, glm::vec3(1));
|
||||
|
||||
|
||||
|
||||
|
||||
//rysowanie Ziemi z księżycem
|
||||
//rysowanie Ziemi z ksiê¿ycem
|
||||
glm::mat4 earth = drawPlanet(time / 5.0f, sunPos*glm::vec3(1.5f,1,1), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(-10.5f, 0.0f, -10.5f), glm::vec3(0.5f, 0.5f, 0.5f));
|
||||
glm::mat4 moon = drawMoon(earth, time/2.0f, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0, 1, 1), glm::vec3(1.5f, 1.0f, 1.0f), glm::vec3(0.3f, 0.3f, 0.3f));
|
||||
earth = glm::rotate(earth, time/3.0f, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
@ -300,7 +311,11 @@ void renderScene()
|
||||
drawObjectTexture(programTex, sphereContext, moon, glm::vec3(0.9f, 1.0f, 0.9f), moonTexture);
|
||||
|
||||
if (engineLightTimer < 50) engineLightTimer++;
|
||||
else lights[2].intensity = 0.0001;
|
||||
else
|
||||
{
|
||||
lights[2].intensity = 0.00001;
|
||||
lights[3].intensity = 0.00001;
|
||||
}
|
||||
|
||||
glUseProgram(0);
|
||||
glutSwapBuffers();
|
||||
@ -345,10 +360,17 @@ void init()
|
||||
|
||||
Light l3;
|
||||
l3.position = engineLight;
|
||||
l3.color = glm::vec3(0.5f, 0.5f, 0.5f);
|
||||
l3.color = glm::vec3(1.0f, -0.0f, 0.0f);
|
||||
l3.intensity = 0.0001;
|
||||
lights.push_back(l3);
|
||||
|
||||
Light l4;
|
||||
l4.position = engineLight;
|
||||
l4.color = glm::vec3(1.0f, -0.0f, 0.0f);
|
||||
l4.intensity = 0.0001;
|
||||
lights.push_back(l4);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
@ -386,6 +408,12 @@ int main(int argc, char** argv)
|
||||
|
||||
init();
|
||||
glutKeyboardFunc(keyboard);
|
||||
|
||||
//to sprawia, że obiekty ukryte przed kamerą nie są renderowane
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glFrontFace(GL_CW);
|
||||
|
||||
glutDisplayFunc(renderScene);
|
||||
glutIdleFunc(idle);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user