diff options
Diffstat (limited to 'src/models.c')
| -rw-r--r-- | src/models.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/models.c b/src/models.c index b7e36b8a..48f8b813 100644 --- a/src/models.c +++ b/src/models.c @@ -4,6 +4,12 @@ * * Basic functions to draw 3d shapes and load/draw 3d models (.OBJ) * +* External libs: +* rlgl - raylib OpenGL abstraction layer +* +* Module Configuration Flags: +* ... +* * Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event @@ -34,8 +40,7 @@ #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" // Matrix data type and Matrix functions +#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2 //---------------------------------------------------------------------------------- // Defines and Macros @@ -76,11 +81,11 @@ void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color) } // Draw a circle in 3D world space -void DrawCircle3D(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color) +void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color) { rlPushMatrix(); rlTranslatef(center.x, center.y, center.z); - rlRotatef(rotationAngle, rotation.x, rotation.y, rotation.z); + rlRotatef(rotationAngle, rotationAxis.x, rotationAxis.y, rotationAxis.z); rlBegin(RL_LINES); for (int i = 0; i < 360; i += 10) @@ -579,9 +584,9 @@ void DrawLight(Light light) { DrawSphereWires(light->position, 0.3f*light->intensity, 8, 8, (light->enabled ? light->diffuse : GRAY)); - DrawCircle3D(light->position, light->radius, 0.0f, (Vector3){ 0, 0, 0 }, (light->enabled ? light->diffuse : GRAY)); - DrawCircle3D(light->position, light->radius, 90.0f, (Vector3){ 1, 0, 0 }, (light->enabled ? light->diffuse : GRAY)); - DrawCircle3D(light->position, light->radius, 90.0f, (Vector3){ 0, 1, 0 }, (light->enabled ? light->diffuse : GRAY)); + DrawCircle3D(light->position, light->radius, (Vector3){ 0, 0, 0 }, 0.0f, (light->enabled ? light->diffuse : GRAY)); + DrawCircle3D(light->position, light->radius, (Vector3){ 1, 0, 0 }, 90.0f, (light->enabled ? light->diffuse : GRAY)); + DrawCircle3D(light->position, light->radius, (Vector3){ 0, 1, 0 },90.0f, (light->enabled ? light->diffuse : GRAY)); } break; case LIGHT_DIRECTIONAL: { @@ -597,7 +602,7 @@ void DrawLight(Light light) Vector3 dir = VectorSubtract(light->target, light->position); VectorNormalize(&dir); - DrawCircle3D(light->position, 0.5f, 0.0f, dir, (light->enabled ? light->diffuse : GRAY)); + DrawCircle3D(light->position, 0.5f, dir, 0.0f, (light->enabled ? light->diffuse : GRAY)); //DrawCylinderWires(light->position, 0.0f, 0.3f*light->coneAngle/50, 0.6f, 5, (light->enabled ? light->diffuse : GRAY)); DrawCubeWires(light->target, 0.3f, 0.3f, 0.3f, (light->enabled ? light->diffuse : GRAY)); @@ -1812,6 +1817,7 @@ static Material LoadMTL(const char *fileName) char buffer[MAX_BUFFER_SIZE]; Vector3 color = { 1.0f, 1.0f, 1.0f }; char mapFileName[128]; + int result = 0; FILE *mtlFile; @@ -1896,13 +1902,13 @@ static Material LoadMTL(const char *fileName) { if (buffer[5] == 'd') // map_Kd string Diffuse color texture map. { - sscanf(buffer, "map_Kd %s", mapFileName); - if (mapFileName != NULL) material.texDiffuse = LoadTexture(mapFileName); + result = sscanf(buffer, "map_Kd %s", mapFileName); + if (result != EOF) material.texDiffuse = LoadTexture(mapFileName); } else if (buffer[5] == 's') // map_Ks string Specular color texture map. { - sscanf(buffer, "map_Ks %s", mapFileName); - if (mapFileName != NULL) material.texSpecular = LoadTexture(mapFileName); + result = sscanf(buffer, "map_Ks %s", mapFileName); + if (result != EOF) material.texSpecular = LoadTexture(mapFileName); } else if (buffer[5] == 'a') // map_Ka string Ambient color texture map. { @@ -1911,13 +1917,13 @@ static Material LoadMTL(const char *fileName) } break; case 'B': // map_Bump string Bump texture map. { - sscanf(buffer, "map_Bump %s", mapFileName); - if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName); + result = sscanf(buffer, "map_Bump %s", mapFileName); + if (result != EOF) material.texNormal = LoadTexture(mapFileName); } break; case 'b': // map_bump string Bump texture map. { - sscanf(buffer, "map_bump %s", mapFileName); - if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName); + result = sscanf(buffer, "map_bump %s", mapFileName); + if (result != EOF) material.texNormal = LoadTexture(mapFileName); } break; case 'd': // map_d string Opacity texture map. { @@ -1941,8 +1947,8 @@ static Material LoadMTL(const char *fileName) } break; case 'b': // bump string Bump texture map { - sscanf(buffer, "bump %s", mapFileName); - if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName); + result = sscanf(buffer, "bump %s", mapFileName); + if (result != EOF) material.texNormal = LoadTexture(mapFileName); } break; case 'T': // Tr float Transparency Tr (alpha). Tr is inverse of d { |
