diff options
| author | victorfisac <[email protected]> | 2016-11-21 20:27:43 +0100 |
|---|---|---|
| committer | victorfisac <[email protected]> | 2016-11-21 20:27:43 +0100 |
| commit | 0716125ee93db7539a27e831eba3c856f55601ab (patch) | |
| tree | b4ee417efa904f26b6b08bd25d66538ebe267283 /src/models.c | |
| parent | 80f6b2f9635d8e4707b528337c39c0ba7bf9cf5f (diff) | |
| parent | 918fc002d0e75f5ea15036634edf8aa3fba9bedc (diff) | |
| download | raylib-0716125ee93db7539a27e831eba3c856f55601ab.tar.gz raylib-0716125ee93db7539a27e831eba3c856f55601ab.zip | |
Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
Diffstat (limited to 'src/models.c')
| -rw-r--r-- | src/models.c | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/src/models.c b/src/models.c index c0f04387..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)); @@ -1411,7 +1416,7 @@ bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, floa float dy = centerA.y - centerB.y; // Y distance between centers float dz = centerA.z - centerB.z; // Y distance between centers - float distance = sqrt(dx*dx + dy*dy + dz*dz); // Distance between centers + float distance = sqrtf(dx*dx + dy*dy + dz*dz); // Distance between centers if (distance <= (radiusA + radiusB)) collision = true; @@ -1441,14 +1446,14 @@ bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radius float dmin = 0; - if (centerSphere.x < box.min.x) dmin += pow(centerSphere.x - box.min.x, 2); - else if (centerSphere.x > box.max.x) dmin += pow(centerSphere.x - box.max.x, 2); + if (centerSphere.x < box.min.x) dmin += powf(centerSphere.x - box.min.x, 2); + else if (centerSphere.x > box.max.x) dmin += powf(centerSphere.x - box.max.x, 2); - if (centerSphere.y < box.min.y) dmin += pow(centerSphere.y - box.min.y, 2); - else if (centerSphere.y > box.max.y) dmin += pow(centerSphere.y - box.max.y, 2); + if (centerSphere.y < box.min.y) dmin += powf(centerSphere.y - box.min.y, 2); + else if (centerSphere.y > box.max.y) dmin += powf(centerSphere.y - box.max.y, 2); - if (centerSphere.z < box.min.z) dmin += pow(centerSphere.z - box.min.z, 2); - else if (centerSphere.z > box.max.z) dmin += pow(centerSphere.z - box.max.z, 2); + if (centerSphere.z < box.min.z) dmin += powf(centerSphere.z - box.min.z, 2); + else if (centerSphere.z > box.max.z) dmin += powf(centerSphere.z - box.max.z, 2); if (dmin <= (radiusSphere*radiusSphere)) collision = true; @@ -1487,8 +1492,8 @@ bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadi float collisionDistance = 0; // Check if ray origin is inside the sphere to calculate the correct collision point - if (distance < sphereRadius) collisionDistance = vector + sqrt(d); - else collisionDistance = vector - sqrt(d); + if (distance < sphereRadius) collisionDistance = vector + sqrtf(d); + else collisionDistance = vector - sqrtf(d); VectorScale(&offset, collisionDistance); Vector3 cPoint = VectorAdd(ray.position, offset); @@ -1811,7 +1816,8 @@ static Material LoadMTL(const char *fileName) char buffer[MAX_BUFFER_SIZE]; Vector3 color = { 1.0f, 1.0f, 1.0f }; - char *mapFileName = NULL; + 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 { |
