Added simple static models and new control
This commit is contained in:
parent
4a32e7fc15
commit
5b5121c8f8
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +1,6 @@
|
|||||||
main_6_1.cpp
|
main_6_1.cpp
|
||||||
C:\Users\User\Desktop\grk-cw\cw 6\src\main_6_1.cpp(144,12): warning C4244: "argument": konwersja z "time_t" do "unsigned int", możliwa utrata danych
|
E:\Projects\Visual Studio 2019\GRK\cw 6\src\main_6_1.cpp(93,23): warning C4244: '=': conversion from 'int' to 'float', possible loss of data
|
||||||
Camera.obj : warning LNK4075: zignorowano opcję „/EDITANDCONTINUE” z powodu określenia opcji „/INCREMENTAL:NO”
|
E:\Projects\Visual Studio 2019\GRK\cw 6\src\main_6_1.cpp(94,23): warning C4244: '=': conversion from 'int' to 'float', possible loss of data
|
||||||
grk-cw6.vcxproj -> C:\Users\User\Desktop\grk-cw\Debug\grk-cw6.exe
|
E:\Projects\Visual Studio 2019\GRK\cw 6\src\main_6_1.cpp(228,12): warning C4244: 'argument': conversion from 'time_t' to 'unsigned int', possible loss of data
|
||||||
|
Camera.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
|
||||||
|
grk-cw6.vcxproj -> E:\Projects\Visual Studio 2019\GRK\Debug\grk-cw6.exe
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +1,2 @@
|
|||||||
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30037:VCServicingVersionATL=14.29.30038:VCServicingVersionCrtHeaders=14.29.30040:VCServicingVersionCompilers=14.29.30040:TargetPlatformVersion=10.0.19041.0:
|
#TargetFrameworkVersion=v4.0:PlatformToolSet=v142:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0
|
||||||
Debug|Win32|C:\Users\User\Desktop\grk-cw\|
|
Debug|Win32|E:\Projects\Visual Studio 2019\GRK\|
|
||||||
|
Binary file not shown.
Binary file not shown.
BIN
cw 6/Debug/grk-cw6.tlog/link.delete.1.tlog
Normal file
BIN
cw 6/Debug/grk-cw6.tlog/link.delete.1.tlog
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
cw 6/models/Submarine.3DS
Normal file
BIN
cw 6/models/Submarine.3DS
Normal file
Binary file not shown.
BIN
cw 6/models/TropicalFish01.3ds
Normal file
BIN
cw 6/models/TropicalFish01.3ds
Normal file
Binary file not shown.
@ -17,19 +17,19 @@ GLuint programTexture;
|
|||||||
Core::Shader_Loader shaderLoader;
|
Core::Shader_Loader shaderLoader;
|
||||||
|
|
||||||
Core::RenderContext shipContext;
|
Core::RenderContext shipContext;
|
||||||
Core::RenderContext sphereContext;
|
Core::RenderContext fishContext;
|
||||||
|
|
||||||
glm::vec3 cameraPos = glm::vec3(0, 0, 5);
|
glm::vec3 cameraPos = glm::vec3(0, 0, 0);
|
||||||
glm::vec3 cameraDir; // Wektor "do przodu" kamery
|
glm::vec3 cameraDir; // Wektor "do przodu" kamery
|
||||||
glm::vec3 cameraSide; // Wektor "w bok" kamery
|
glm::vec3 cameraSide; // Wektor "w bok" kamery
|
||||||
|
|
||||||
|
glm::vec3 vehiclePos = glm::vec3(0, 0, 0);
|
||||||
|
glm::vec3 vehicleDir; // Wektor "do przodu" kamery
|
||||||
|
glm::vec3 vehicleSide; // Wektor "w bok" kamery
|
||||||
|
float vehicleAngle = 0;
|
||||||
|
|
||||||
float cameraAngle = 0;
|
float cameraAngle = 0;
|
||||||
|
|
||||||
int ARRAY_LENGTH = 10;
|
|
||||||
|
|
||||||
int arr_x[10] = {0};
|
|
||||||
int arr_y[10] = {0};
|
|
||||||
int arr_z[10] = {0};
|
|
||||||
|
|
||||||
glm::mat4 cameraMatrix, perspectiveMatrix;
|
glm::mat4 cameraMatrix, perspectiveMatrix;
|
||||||
|
|
||||||
glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -0.9f, -1.0f));
|
glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -0.9f, -1.0f));
|
||||||
@ -37,6 +37,27 @@ glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -0.9f, -1.0f));
|
|||||||
glm::quat rotation = glm::quat(1, 0, 0, 0);
|
glm::quat rotation = glm::quat(1, 0, 0, 0);
|
||||||
|
|
||||||
GLuint textureAsteroid;
|
GLuint textureAsteroid;
|
||||||
|
GLuint textureFish01;
|
||||||
|
|
||||||
|
|
||||||
|
int WIN_WIDTH = 1280;
|
||||||
|
int WIN_HEIGHT = 720;
|
||||||
|
|
||||||
|
glm::vec3 planetLocation[10];
|
||||||
|
|
||||||
|
float mouseXPosition;
|
||||||
|
float mouseYPosition;
|
||||||
|
float mouseXPositionLast;
|
||||||
|
float mouseYPositionLast;
|
||||||
|
float delta_x = 0;
|
||||||
|
float delta_y = 0;
|
||||||
|
glm::quat rotationCamera;
|
||||||
|
glm::quat rotation_y;
|
||||||
|
glm::quat rotation_x;
|
||||||
|
float dy = 0;
|
||||||
|
float dx = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void keyboard(unsigned char key, int x, int y)
|
void keyboard(unsigned char key, int x, int y)
|
||||||
{
|
{
|
||||||
@ -45,26 +66,66 @@ 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 'z': vehicleAngle -= angleSpeed; delta_x = vehicleAngle; break;
|
||||||
case 'x': cameraAngle += angleSpeed; break;
|
case 'x': vehicleAngle += angleSpeed; cameraAngle = vehicleAngle; break;
|
||||||
case 'w': cameraPos += cameraDir * moveSpeed; break;
|
case 'w': vehiclePos += vehicleDir * moveSpeed; break;
|
||||||
case 's': cameraPos -= cameraDir * moveSpeed; break;
|
case 's': vehiclePos -= vehicleDir * moveSpeed; break;
|
||||||
case 'd': cameraPos += cameraSide * moveSpeed; break;
|
case 'd': vehiclePos += vehicleSide * moveSpeed; break;
|
||||||
case 'a': cameraPos -= cameraSide * moveSpeed; break;
|
case 'a': vehiclePos -= vehicleSide * moveSpeed; break;
|
||||||
|
//case 'h': rotation_y = glm::quat(1, 0, 0, 0); rotation_x = glm::quat(1, 0, 0, 0); rotationCamera = glm::quat(1, 0, 0, 0); break;
|
||||||
|
//case 'h': rotation_y = glm::quat(1, 0, 0, 0); rotation_x = glm::quat(1, 0, 0, 0); rotationCamera = glm::quat(1, 0, 0, 0); break;
|
||||||
|
|
||||||
|
case 'h': rotation_y = glm::quat(1, 0, 0, 0); rotation_x = glm::quat(vehicleAngle, 0, 0, 0); rotationCamera = glm::quat(1, 0, 0, 0); break;
|
||||||
|
|
||||||
|
//delta_x = 0; delta_y = 0; cameraPos = glm::vec3(0, 0, 5); rotation = glm::quat(1, 0, 0, 0); dy = 0; dx = 0; mouseXPositionLast = mouseXPosition; mouseYPositionLast = mouseYPosition;
|
||||||
|
//glutWarpPointer(WIN_WIDTH / 2, WIN_HEIGHT/ 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//rot_y = glm::angleAxis(vehicleAngle * 0.01f, glm::vec3(0, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouse(int x, int y)
|
void mouse(int x, int y)
|
||||||
{
|
{
|
||||||
|
if (mouseXPositionLast >= 0) {
|
||||||
|
delta_x = x - mouseXPositionLast;
|
||||||
|
delta_y = y - mouseYPositionLast;
|
||||||
|
}
|
||||||
|
mouseXPositionLast = x;
|
||||||
|
mouseYPositionLast = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 createCameraMatrix()
|
glm::mat4 createCameraMatrix()
|
||||||
{
|
{
|
||||||
cameraDir = glm::vec3(cosf(cameraAngle - glm::radians(90.0f)), 0.0f, sinf(cameraAngle - glm::radians(90.0f)));
|
//delta_x = delta_x + vehicleAngle;
|
||||||
glm::vec3 up = glm::vec3(0, 1, 0);
|
glm::quat rot_x = glm::angleAxis(delta_y * 0.01f, glm::vec3(1, 0, 0));
|
||||||
cameraSide = glm::cross(cameraDir, up);
|
glm::quat rot_y = glm::angleAxis(delta_x * 0.01f, glm::vec3(0, 1, 0));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
dy += delta_y;
|
||||||
|
dx += delta_x;
|
||||||
|
delta_x = 0;
|
||||||
|
delta_y = 0;
|
||||||
|
|
||||||
|
|
||||||
|
vehicleDir = glm::vec3(cosf(vehicleAngle - glm::radians(90.0f)), 0.0f, sinf(vehicleAngle - glm::radians(90.0f)));
|
||||||
|
|
||||||
|
vehicleSide = glm::cross(vehicleDir, glm::vec3(0, 1, 0));
|
||||||
|
|
||||||
|
rotation_x = glm::normalize(rot_x * rotation_x);
|
||||||
|
rotation_y = glm::normalize(rot_y * rotation_y);
|
||||||
|
|
||||||
|
rotationCamera = glm::normalize(rotation_y * rotation_x);
|
||||||
|
|
||||||
|
glm::quat inverse_rot = glm::inverse(rotationCamera);
|
||||||
|
|
||||||
|
cameraDir = inverse_rot * glm::vec3(0, 0, -1);
|
||||||
|
glm::vec3 up = glm::vec3(0, 1, 0);
|
||||||
|
cameraSide = inverse_rot * glm::vec3(1, 0, 0);
|
||||||
|
|
||||||
|
|
||||||
|
return Core::createViewMatrixQuat(vehiclePos + glm::vec3(0, 2, 2), rotationCamera);
|
||||||
|
|
||||||
return Core::createViewMatrix(cameraPos, cameraDir, up);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawObjectColor(Core::RenderContext context, glm::mat4 modelMatrix, glm::vec3 color)
|
void drawObjectColor(Core::RenderContext context, glm::mat4 modelMatrix, glm::vec3 color)
|
||||||
@ -111,16 +172,35 @@ void renderScene()
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glClearColor(0.0f, 0.1f, 0.3f, 1.0f);
|
glClearColor(0.0f, 0.1f, 0.3f, 1.0f);
|
||||||
|
|
||||||
glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0,-0.25f,0)) * glm::rotate(glm::radians(180.0f), glm::vec3(0,1,0)) * glm::scale(glm::vec3(0.25f));
|
glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0, 0, 0));
|
||||||
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.5f) * glm::rotate(-cameraAngle, glm::vec3(0,1,0)) * shipInitialTransformation;
|
// Scaling models
|
||||||
|
glm::vec3 shipScale = glm::vec3(0.01, 0.01, 0.01);
|
||||||
|
shipInitialTransformation = glm::scale(shipInitialTransformation, shipScale);
|
||||||
|
|
||||||
|
shipInitialTransformation = shipInitialTransformation * glm::translate(glm::vec3(0, 0, 0)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.5f));
|
||||||
|
glm::mat4 shipModelMatrix = glm::translate(vehiclePos + vehicleDir) * glm::rotate(-vehicleAngle, glm::vec3(0, 1, 0)) * shipInitialTransformation;
|
||||||
drawObjectColor(shipContext, shipModelMatrix, glm::vec3(0.6f));
|
drawObjectColor(shipContext, shipModelMatrix, glm::vec3(0.6f));
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < ARRAY_LENGTH; i++) {
|
glm::mat4 modelMatrix = glm::translate(glm::vec3(0, 0, 0));
|
||||||
drawObjectTexture(sphereContext, glm::translate(glm::vec3(arr_x[i], arr_y[i], arr_z[i])), textureAsteroid);
|
// Scaling models
|
||||||
|
glm::vec3 scale = glm::vec3(0.001, 0.001, 0.001);
|
||||||
|
modelMatrix = glm::scale(modelMatrix, scale);
|
||||||
|
|
||||||
|
drawObjectTexture(fishContext, modelMatrix, textureFish01);
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
glm::mat4 modelMatrix = glm::translate(planetLocation[i]);
|
||||||
|
// Scaling models
|
||||||
|
glm::vec3 scale = glm::vec3(0.001, 0.001, 0.001);
|
||||||
|
modelMatrix = glm::scale(modelMatrix, scale);
|
||||||
|
|
||||||
|
drawObjectTexture(fishContext, modelMatrix, textureFish01);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawObjectTexture(sphereContext, glm::translate(glm::vec3(0,0,0)), textureAsteroid);
|
|
||||||
|
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
@ -140,20 +220,19 @@ void loadModelToContext(std::string path, Core::RenderContext& context)
|
|||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
planetLocation[i] = glm::ballRand(20.0);
|
||||||
|
}
|
||||||
|
|
||||||
srand(time(0));
|
srand(time(0));
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
programColor = shaderLoader.CreateProgram("shaders/shader_color.vert", "shaders/shader_color.frag");
|
programColor = shaderLoader.CreateProgram("shaders/shader_color.vert", "shaders/shader_color.frag");
|
||||||
programTexture = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
|
programTexture = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
|
||||||
loadModelToContext("models/spaceship.obj", shipContext);
|
loadModelToContext("models/Submarine.3DS", shipContext);
|
||||||
loadModelToContext("models/sphere.obj", sphereContext);
|
loadModelToContext("models/TropicalFish01.3ds", fishContext);
|
||||||
|
|
||||||
for (int i = 0; i < ARRAY_LENGTH; i++) {
|
|
||||||
arr_x[i] = rand() % 11 - 10;
|
|
||||||
arr_y[i] = rand() % 11 - 10;
|
|
||||||
arr_z[i] = rand() % 11 - 10;
|
|
||||||
}
|
|
||||||
textureAsteroid = Core::LoadTexture("textures/asteroid.png");
|
textureAsteroid = Core::LoadTexture("textures/asteroid.png");
|
||||||
|
textureFish01 = Core::LoadTexture("textures/TropicalFish01.jpg");
|
||||||
}
|
}
|
||||||
|
|
||||||
void shutdown()
|
void shutdown()
|
||||||
@ -172,11 +251,13 @@ int main(int argc, char ** argv)
|
|||||||
glutInit(&argc, argv);
|
glutInit(&argc, argv);
|
||||||
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
|
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
|
||||||
glutInitWindowPosition(200, 200);
|
glutInitWindowPosition(200, 200);
|
||||||
glutInitWindowSize(600, 600);
|
glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
|
||||||
|
|
||||||
glutCreateWindow("OpenGL Pierwszy Program");
|
glutCreateWindow("OpenGL Pierwszy Program");
|
||||||
glewInit();
|
glewInit();
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
glutWarpPointer(WIN_WIDTH / 2, WIN_HEIGHT / 2);
|
||||||
glutKeyboardFunc(keyboard);
|
glutKeyboardFunc(keyboard);
|
||||||
glutPassiveMotionFunc(mouse);
|
glutPassiveMotionFunc(mouse);
|
||||||
glutDisplayFunc(renderScene);
|
glutDisplayFunc(renderScene);
|
||||||
|
BIN
cw 6/textures/TropicalFish01.jpg
Normal file
BIN
cw 6/textures/TropicalFish01.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 211 KiB |
Loading…
Reference in New Issue
Block a user