engine offset not working, keyboard change, cameraFace change
This commit is contained in:
parent
e7fd0f5fa2
commit
8b3c045237
@ -49,7 +49,7 @@
|
|||||||
<ProjectGuid>{1B448102-E76C-4347-BDC7-40D02A567DB6}</ProjectGuid>
|
<ProjectGuid>{1B448102-E76C-4347-BDC7-40D02A567DB6}</ProjectGuid>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<RootNamespace>grk-cw9</RootNamespace>
|
<RootNamespace>grk-cw9</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
<ProjectName>grk-project</ProjectName>
|
<ProjectName>grk-project</ProjectName>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
@ -57,14 +57,14 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
38
src/main.cpp
38
src/main.cpp
@ -1,4 +1,4 @@
|
|||||||
#include "glew.h"
|
#include "glew.h"
|
||||||
#include "freeglut.h"
|
#include "freeglut.h"
|
||||||
#include "glm.hpp"
|
#include "glm.hpp"
|
||||||
#include "ext.hpp"
|
#include "ext.hpp"
|
||||||
@ -53,6 +53,8 @@ std::vector<Core::RenderContext> corvetteMeshes;
|
|||||||
float cameraAngle = 0;
|
float cameraAngle = 0;
|
||||||
glm::vec3 cameraPos = glm::vec3(-6, 0, 0);
|
glm::vec3 cameraPos = glm::vec3(-6, 0, 0);
|
||||||
glm::vec3 cameraDir;
|
glm::vec3 cameraDir;
|
||||||
|
glm::vec3 cameraSide;
|
||||||
|
|
||||||
|
|
||||||
glm::mat4 cameraMatrix, perspectiveMatrix;
|
glm::mat4 cameraMatrix, perspectiveMatrix;
|
||||||
|
|
||||||
@ -89,8 +91,8 @@ void keyboard(unsigned char key, int x, int y)
|
|||||||
float moveSpeed = 0.1f;
|
float moveSpeed = 0.1f;
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case 'z': cameraAngle -= angleSpeed; break;
|
case 'q': cameraAngle -= angleSpeed; break;
|
||||||
case 'x': cameraAngle += angleSpeed; break;
|
case 'e': cameraAngle += angleSpeed; break;
|
||||||
case 'w':
|
case 'w':
|
||||||
{
|
{
|
||||||
cameraPos += cameraDir * moveSpeed;
|
cameraPos += cameraDir * moveSpeed;
|
||||||
@ -101,8 +103,8 @@ void keyboard(unsigned char key, int x, int y)
|
|||||||
case 's': cameraPos -= cameraDir * moveSpeed; break;
|
case 's': cameraPos -= cameraDir * moveSpeed; break;
|
||||||
case 'd': cameraPos += glm::cross(cameraDir, glm::vec3(0, 1, 0)) * 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 '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 'z': cameraPos += glm::cross(cameraDir, glm::vec3(0, 0, 1)) * moveSpeed; break;
|
||||||
case 'q': cameraPos -= glm::cross(cameraDir, glm::vec3(1, 0, 0)) * moveSpeed; break;
|
case 'x': cameraPos -= glm::cross(cameraDir, glm::vec3(0, 0, 1)) * moveSpeed; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,6 +114,8 @@ glm::mat4 createCameraMatrix()
|
|||||||
cameraDir = glm::vec3(cosf(cameraAngle), 0.0f, sinf(cameraAngle));
|
cameraDir = glm::vec3(cosf(cameraAngle), 0.0f, sinf(cameraAngle));
|
||||||
glm::vec3 up = glm::vec3(0, 1, 0);
|
glm::vec3 up = glm::vec3(0, 1, 0);
|
||||||
|
|
||||||
|
cameraSide = glm::cross(cameraDir,up);
|
||||||
|
|
||||||
return Core::createViewMatrix(cameraPos, cameraDir, up);
|
return Core::createViewMatrix(cameraPos, cameraDir, up);
|
||||||
}
|
}
|
||||||
float frustumScale = 1.f;
|
float frustumScale = 1.f;
|
||||||
@ -249,10 +253,10 @@ void renderScene()
|
|||||||
glUseProgram(programSun);
|
glUseProgram(programSun);
|
||||||
glUniform3f(glGetUniformLocation(programSun, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
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);
|
glm::mat4 sunModelMatrix = glm::mat4(1.0f);
|
||||||
sunModelMatrix = glm::translate(sunModelMatrix, sunPos);
|
sunModelMatrix = glm::translate(sunModelMatrix, sunPos);
|
||||||
sunModelMatrix = glm::scale(sunModelMatrix, glm::vec3(3.0f, 3.0f, 3.0f));
|
sunModelMatrix = glm::scale(sunModelMatrix, glm::vec3(3.0f, 3.0f, 3.0f));
|
||||||
@ -269,8 +273,13 @@ void renderScene()
|
|||||||
lights[0].position = sunPos;
|
lights[0].position = sunPos;
|
||||||
lights[1].position = sunPos2;
|
lights[1].position = sunPos2;
|
||||||
|
|
||||||
lights[2].position = cameraPos + cameraDir * 0.6f + glm::vec3(0, -0.25f, 0);
|
//lights[2].position = cameraPos + cameraDir * 0.5f + glm::vec3(0, -0.25f, 0);
|
||||||
lights[2].color = glm::vec3(1.0f, 0.0f, 0.0f);
|
//lights[2].position = glm::vec3(cameraPos.x + cameraDir.x * 0.5f +0.f , cameraPos.y-0.25f, cameraPos.z + cameraDir.z * 0.5f );
|
||||||
|
glm::mat4 engineLightPos = glm::translate(cameraPos + cameraDir * 0.3f + cameraSide * -0.5f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle, glm::vec3(0, 1, 0));
|
||||||
|
lights[2].position = glm::vec3(engineLightPos[3][0], engineLightPos[3][1], engineLightPos[3][2]);
|
||||||
|
|
||||||
|
|
||||||
|
lights[2].color = glm::vec3(1.0f, -0.0f, 0.0f);
|
||||||
|
|
||||||
for (int i = 0; i < lights.size(); i++)
|
for (int i = 0; i < lights.size(); i++)
|
||||||
{
|
{
|
||||||
@ -286,13 +295,14 @@ void renderScene()
|
|||||||
|
|
||||||
|
|
||||||
//rysowanie statku
|
//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));
|
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));
|
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 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));
|
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));
|
earth = glm::rotate(earth, time/3.0f, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
@ -386,6 +396,12 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
init();
|
init();
|
||||||
glutKeyboardFunc(keyboard);
|
glutKeyboardFunc(keyboard);
|
||||||
|
|
||||||
|
//to sprawia, że obiekty ukryte przed kamerą nie są renderowane
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
glFrontFace(GL_CW);
|
||||||
|
|
||||||
glutDisplayFunc(renderScene);
|
glutDisplayFunc(renderScene);
|
||||||
glutIdleFunc(idle);
|
glutIdleFunc(idle);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user