Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Object files
*.o
*.ko
*.obj
# *.obj
*.elf

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
# *.lib
# *.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
# *.dll
*.so
*.so.*
*.dylib
Expand Down
45 changes: 27 additions & 18 deletions 03_challenge_maze3d/lessons/07_maze_game_collisions.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* stb_image.h - Multiple formats image loading (BMP, PNG, TGA, JPG...)
*
* Compile example using:
* gcc -o $(NAME_PART).exe $(FILE_NAME) -Iexternal -lglfw3 -lopengl32 -lgdi32 -Wall -std=c99
* gcc -o $(NAME_PART).exe $(FILE_NAME) -Iexternal -Iexternal/glfw/include \
* -Lexternal/glfw/lib -lglfw3 -lopengl32 -lgdi32 -Wall -std=c99
*
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
*
Expand Down Expand Up @@ -273,29 +274,31 @@ int main(void)
matModelview = MatrixLookAt(camera.position, camera.target, camera.up);

// LESSON 04: Load 3d model
//Mesh mesh = LoadOBJ("resources/dwarf.obj"); // Load mesh data from OBJ file
//UploadMeshData(&mesh); // Upload mesh data to GPU memory (VRAM)
Mesh meshTower = LoadOBJ("resources/tower.obj"); // Load mesh data from OBJ file
UploadMeshData(&meshTower); // Upload mesh data to GPU memory (VRAM)

// LESSON 04: Load model diffuse texture
//Image image = LoadImage("resources/dwarf_diffuse.png");
//Texture2D texture = LoadTexture(image.data, image.width, image.height, image.format);
//UnloadImage(image);
Image imTower = LoadImage("resources/tower.png");
Texture2D texTower = LoadTexture(imTower.data, imTower.width, imTower.height, imTower.format);
UnloadImage(imTower);

Model modelTower = LoadModel(meshTower, texTower);

// LESSON 05: Cubicmap generation
Image imMap = LoadImage("resources/map04.png");
Mesh mesh = GenMeshCubicmap(imMap, 1.0f);
UploadMeshData(&mesh);
Mesh meshMap = GenMeshCubicmap(imMap, 1.0f);
UploadMeshData(&meshMap);

// LESSON 07: Get map image data to be used for collision detection
Color *mapPixels = GetImageData(imMap);
UnloadImage(imMap);

// LESSON 05: Load cubicmap texture
Image image = LoadImage("resources/cubemap_atlas01.png");
Texture2D texture = LoadTexture(image.data, image.width, image.height, image.format);
UnloadImage(image);
Image imMapAtlas = LoadImage("resources/cubemap_atlas01.png");
Texture2D texMapAtlas = LoadTexture(imMapAtlas.data, imMapAtlas.width, imMapAtlas.height, imMapAtlas.format);
UnloadImage(imMapAtlas);

Model model = LoadModel(mesh, texture);
Model modelMap = LoadModel(meshMap, texMapAtlas);

Vector3 position = Vector3Zero(); // Model position on screen

Expand Down Expand Up @@ -356,8 +359,9 @@ int main(void)
// LESSON 03: Draw loaded texture on screen
//DrawTexture(texture, position, WHITE);

// LESSON 04: Draw loaded 3d model (cubicmap)
DrawModel(model, position, 1.0f, WHITE);
// LESSON 04: Draw loaded 3d models
DrawModel(modelMap, position, 1.0f, WHITE);
DrawModel(modelTower, (Vector3){ 3, 0, 3 }, 0.1f, WHITE);

glfwSwapBuffers(window); // Swap buffers: show back buffer into front
PollInputEvents(); // Register input events (keyboard, mouse)
Expand All @@ -367,7 +371,8 @@ int main(void)

// De-Initialization
//--------------------------------------------------------------------------------------
UnloadModel(model); // Unload model data (includes texture unloading)
UnloadModel(modelMap); // Unload model data (includes texture unloading)
UnloadModel(modelTower); // Unload model data (includes texture unloading)

CloseWindow();
//--------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1322,6 +1327,13 @@ static void DrawModel(Model model, Vector3 position, float scale, Color tint)
// Combine model transform matrix with matrix generated by function parameters (matTransform)
model.transform = MatrixMultiply(model.transform, matTransform);

// Combine model transform with modelview matrix (defines camera transformation)
model.transform = MatrixMultiply(model.transform, matModelview);

// Calculate model-view-projection matrix (MVP)
// NOTE: Camera transformation is already accumulated to model.transform
Matrix matMVP = MatrixMultiply(model.transform, matProjection); // Transform to screen-space coordinates

model.material.colDiffuse = tint; // Assign tint as diffuse color

glUseProgram(model.material.shader.id); // Bind material shader
Expand All @@ -1342,9 +1354,6 @@ static void DrawModel(Model model, Vector3 position, float scale, Color tint)
// Bind mesh VAO (vertex array objects)
glBindVertexArray(model.mesh.vaoId);

// Calculate model-view-matProjection matrix (MVP)
Matrix matMVP = MatrixMultiply(matModelview, matProjection); // Transform to screen-space coordinates

// Send combined model-view-matProjection matrix to shader
glUniformMatrix4fv(model.material.shader.mvpLoc, 1, false, MatrixToFloat(matMVP));

Expand Down
22 changes: 22 additions & 0 deletions 03_challenge_maze3d/lessons/external/glfw/COPYING.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2002-2006 Marcus Geelnard
Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org>

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would
be appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not
be misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.

Loading