aboutsummaryrefslogtreecommitdiff
path: root/src/models.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/models.c')
-rw-r--r--src/models.c52
1 files changed, 40 insertions, 12 deletions
diff --git a/src/models.c b/src/models.c
index 092a43fc..15565c98 100644
--- a/src/models.c
+++ b/src/models.c
@@ -26,16 +26,16 @@
#include "raylib.h"
#if defined(PLATFORM_ANDROID)
- #include "utils.h" // Android fopen function map
+ #include "utils.h" // Android fopen function map
#endif
-#include <stdio.h> // Standard input/output functions, used to read model files data
-#include <stdlib.h> // Declares malloc() and free() for memory management
-#include <string.h> // Required for strcmp()
-#include <math.h> // Used for sin, cos, tan
+#include <stdio.h> // Required for: FILE, fopen(), fclose(), fscanf(), feof(), rewind(), fgets()
+#include <stdlib.h> // Required for: malloc(), free()
+#include <string.h> // Required for: strcmp()
+#include <math.h> // Required for: sin(), cos()
-#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
-#include "raymath.h" // Required for data type Matrix and Matrix functions
+#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
+#include "raymath.h" // Matrix data type and Matrix functions
//----------------------------------------------------------------------------------
// Defines and Macros
@@ -569,6 +569,35 @@ void DrawGizmo(Vector3 position)
rlPopMatrix();
}
+
+// Draw light in 3D world
+void DrawLight(Light light)
+{
+ switch (light->type)
+ {
+ case LIGHT_POINT:
+ {
+ DrawSphereWires(light->position, 0.3f*light->intensity, 4, 8, (light->enabled ? light->diffuse : BLACK));
+ Draw3DCircle(light->position, light->radius, 0.0f, (Vector3){ 0, 0, 0 }, (light->enabled ? light->diffuse : BLACK));
+ Draw3DCircle(light->position, light->radius, 90.0f, (Vector3){ 1, 0, 0 }, (light->enabled ? light->diffuse : BLACK));
+ Draw3DCircle(light->position, light->radius, 90.0f, (Vector3){ 0, 1, 0 }, (light->enabled ? light->diffuse : BLACK));
+ } break;
+ case LIGHT_DIRECTIONAL:
+ {
+ Draw3DLine(light->position, light->target, (light->enabled ? light->diffuse : BLACK));
+ DrawSphereWires(light->position, 0.3f*light->intensity, 4, 8, (light->enabled ? light->diffuse : BLACK));
+ DrawCubeWires(light->target, 0.3f, 0.3f, 0.3f, (light->enabled ? light->diffuse : BLACK));
+ } break;
+ case LIGHT_SPOT:
+ {
+ Draw3DLine(light->position, light->target, (light->enabled ? light->diffuse : BLACK));
+ DrawCylinderWires(light->position, 0.0f, 0.3f*light->coneAngle/50, 0.6f, 5, (light->enabled ? light->diffuse : BLACK));
+ DrawCubeWires(light->target, 0.3f, 0.3f, 0.3f, (light->enabled ? light->diffuse : BLACK));
+ } break;
+ default: break;
+ }
+}
+
// Load a 3d model (from file)
Model LoadModel(const char *fileName)
{
@@ -576,7 +605,7 @@ Model LoadModel(const char *fileName)
// TODO: Initialize default data for model in case loading fails, maybe a cube?
- if (strcmp(GetExtension(fileName),"obj") == 0) model.mesh = LoadOBJ(fileName);
+ if (strcmp(GetExtension(fileName), "obj") == 0) model.mesh = LoadOBJ(fileName);
else TraceLog(WARNING, "[%s] Model extension not recognized, it can't be loaded", fileName);
if (model.mesh.vertexCount == 0) TraceLog(WARNING, "Model could not be loaded");
@@ -735,7 +764,7 @@ Material LoadMaterial(const char *fileName)
{
Material material = { 0 };
- if (strcmp(GetExtension(fileName),"mtl") == 0) material = LoadMTL(fileName);
+ if (strcmp(GetExtension(fileName), "mtl") == 0) material = LoadMTL(fileName);
else TraceLog(WARNING, "[%s] Material extension not recognized, it can't be loaded", fileName);
return material;
@@ -750,8 +779,7 @@ Material LoadDefaultMaterial(void)
material.texDiffuse = GetDefaultTexture(); // White texture (1x1 pixel)
//material.texNormal; // NOTE: By default, not set
//material.texSpecular; // NOTE: By default, not set
-
- material.colTint = WHITE; // Tint color
+
material.colDiffuse = WHITE; // Diffuse color
material.colAmbient = WHITE; // Ambient color
material.colSpecular = WHITE; // Specular color
@@ -1269,7 +1297,7 @@ void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rota
//Matrix matModel = MatrixMultiply(model.transform, matTransform); // Transform to world-space coordinates
model.transform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation);
- model.material.colTint = tint;
+ model.material.colDiffuse = tint; // TODO: Multiply tint color by diffuse color?
rlglDrawMesh(model.mesh, model.material, model.transform);
}