summaryrefslogtreecommitdiffhomepage
path: root/examples/models
diff options
context:
space:
mode:
Diffstat (limited to 'examples/models')
-rw-r--r--examples/models/models_mesh_picking.c (renamed from examples/models/models_ray_picking.c)37
-rw-r--r--examples/models/models_mesh_picking.pngbin0 -> 97991 bytes
-rw-r--r--examples/models/resources/tower.obj (renamed from examples/models/resources/model/lowpoly-tower.obj)0
-rw-r--r--examples/models/resources/tower.png (renamed from examples/models/resources/model/lowpoly-tower.png)bin24939 -> 24939 bytes
4 files changed, 19 insertions, 18 deletions
diff --git a/examples/models/models_ray_picking.c b/examples/models/models_mesh_picking.c
index 67b13155..0b5247ec 100644
--- a/examples/models/models_ray_picking.c
+++ b/examples/models/models_mesh_picking.c
@@ -1,6 +1,6 @@
/*******************************************************************************************
*
-* raylib [models] example - Ray picking in 3d mode, ground plane, triangle, mesh
+* raylib [models] example - Mesh picking in 3d mode, ground plane, triangle, mesh
*
* This example has been created using raylib 1.7 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
@@ -11,11 +11,9 @@
********************************************************************************************/
#include "raylib.h"
-#include "../src/raymath.h"
-
-#include <stdio.h>
-#include <float.h>
+#include "raymath.h"
+#define FLT_MAX 3.40282347E+38F // Maximum value of a float, defined in <float.h>
int main()
{
@@ -24,23 +22,23 @@ int main()
int screenWidth = 800;
int screenHeight = 450;
- InitWindow(screenWidth, screenHeight, "raylib [models] example - 3d ray picking");
+ InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh picking");
// Define the camera to look into our 3d world
Camera camera;
- camera.position = (Vector3){ 10.0f, 8.0f, 10.0f }; // Camera position
+ camera.position = (Vector3){ 10.0f, 8.0f, 10.0f }; // Camera position
camera.target = (Vector3){ 0.0f, 2.3f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.6f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 45.0f; // Camera field-of-view Y
- Ray ray; // Picking line ray
+ Ray ray; // Picking ray
- Model tower = LoadModel("resources/model/lowpoly-tower.obj"); // Load OBJ model
- Texture2D texture = LoadTexture("resources/model/lowpoly-tower.png"); // Load model texture
- tower.material.texDiffuse = texture; // Set model diffuse texture
+ Model tower = LoadModel("resources/tower.obj"); // Load OBJ model
+ Texture2D texture = LoadTexture("resources/tower.png"); // Load model texture
+ tower.material.texDiffuse = texture; // Set model diffuse texture
- Vector3 towerPos = { 0.0f, 0.0f, 0.0f }; // Set model position
- BoundingBox towerBBox = CalculateBoundingBox( tower.mesh );
+ Vector3 towerPos = { 0.0f, 0.0f, 0.0f }; // Set model position
+ BoundingBox towerBBox = CalculateBoundingBox(tower.mesh);
bool hitMeshBBox = false;
bool hitTriangle = false;
@@ -91,7 +89,7 @@ int main()
cursorColor = PURPLE;
hitObjectName = "Triangle";
- bary = Barycenter(nearestHit.hitPosition, ta, tb, tc);
+ bary = VectorBarycenter(nearestHit.hitPosition, ta, tb, tc);
hitTriangle = true;
}
else hitTriangle = false;
@@ -138,15 +136,15 @@ int main()
// If we hit something, draw the cursor at the hit point
if (nearestHit.hit)
{
- DrawCube(nearestHit.hitPosition, 0.5, 0.5, 0.5, cursorColor);
- DrawCubeWires(nearestHit.hitPosition, 0.5, 0.5, 0.5, YELLOW);
+ DrawCube(nearestHit.hitPosition, 0.3, 0.3, 0.3, cursorColor);
+ DrawCubeWires(nearestHit.hitPosition, 0.3, 0.3, 0.3, RED);
Vector3 normalEnd;
normalEnd.x = nearestHit.hitPosition.x + nearestHit.hitNormal.x;
normalEnd.y = nearestHit.hitPosition.y + nearestHit.hitNormal.y;
normalEnd.z = nearestHit.hitPosition.z + nearestHit.hitNormal.z;
- DrawLine3D(nearestHit.hitPosition, normalEnd, YELLOW);
+ DrawLine3D(nearestHit.hitPosition, normalEnd, RED);
}
DrawRay(ray, MAROON);
@@ -187,7 +185,10 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
- CloseWindow(); // Close window and OpenGL context
+ UnloadModel(tower); // Unload model
+ UnloadTexture(texture); // Unload texture
+
+ CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
diff --git a/examples/models/models_mesh_picking.png b/examples/models/models_mesh_picking.png
new file mode 100644
index 00000000..045db585
--- /dev/null
+++ b/examples/models/models_mesh_picking.png
Binary files differ
diff --git a/examples/models/resources/model/lowpoly-tower.obj b/examples/models/resources/tower.obj
index ea03a9fc..ea03a9fc 100644
--- a/examples/models/resources/model/lowpoly-tower.obj
+++ b/examples/models/resources/tower.obj
diff --git a/examples/models/resources/model/lowpoly-tower.png b/examples/models/resources/tower.png
index 7c9239e2..7c9239e2 100644
--- a/examples/models/resources/model/lowpoly-tower.png
+++ b/examples/models/resources/tower.png
Binary files differ