diff options
| author | Ray <raysan5@gmail.com> | 2016-05-31 00:51:55 +0200 |
|---|---|---|
| committer | Ray <raysan5@gmail.com> | 2016-05-31 00:51:55 +0200 |
| commit | caa7bc366b949310fbb9c7eafbb9fa7050e1514a (patch) | |
| tree | a39e43fafe81335266f3d6ee1ff13454a55db25e /src | |
| parent | 8a4e28f81db16c034274e5d78dddfe33824e59fe (diff) | |
| download | raylib-caa7bc366b949310fbb9c7eafbb9fa7050e1514a.tar.gz raylib-caa7bc366b949310fbb9c7eafbb9fa7050e1514a.zip | |
Reviewed DrawLight() function and some tweaks
Diffstat (limited to 'src')
| -rw-r--r-- | src/models.c | 29 | ||||
| -rw-r--r-- | src/raylib.h | 18 | ||||
| -rw-r--r-- | src/rlgl.c | 38 |
3 files changed, 45 insertions, 40 deletions
diff --git a/src/models.c b/src/models.c index 092a43fc..8c5ed914 100644 --- a/src/models.c +++ b/src/models.c @@ -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) { diff --git a/src/raylib.h b/src/raylib.h index dfec956d..cba73e52 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -431,18 +431,18 @@ typedef struct Model { // Light type typedef struct LightData { - int id; - int type; // LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT - bool enabled; + unsigned int id; // Light id + int type; // Light type: LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT + bool enabled; // Light enabled - Vector3 position; - Vector3 target; // Used on LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) - float radius; // Lost of light intensity with distance (world distance) + Vector3 position; // Light position + Vector3 target; // Light target: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) + float radius; // Light attenuation radius light intensity reduced with distance (world distance) - Color diffuse; // Light color + Color diffuse; // Light diffuse color float intensity; // Light intensity level - float coneAngle; // Spot light max angle + float coneAngle; // Light cone max angle: LIGHT_SPOT } LightData, *Light; // Light types @@ -817,6 +817,7 @@ void DrawPlane(Vector3 centerPos, Vector2 size, Color color); void DrawRay(Ray ray, Color color); // Draw a ray line void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) void DrawGizmo(Vector3 position); // Draw simple gizmo +void DrawLight(Light light); // Draw light in 3D world //DrawTorus(), DrawTeapot() are useless... //------------------------------------------------------------------------------------ @@ -873,7 +874,6 @@ void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // S void SetBlendMode(int mode); // Set blending mode (alpha, additive, multiplied) Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool -void DrawLights(void); // Draw all created lights in 3D world void DestroyLight(Light light); // Destroy a light and take it out of the list //---------------------------------------------------------------------------------- @@ -1069,6 +1069,13 @@ void rlglClose(void) // Delete default white texture glDeleteTextures(1, &whiteTexture); TraceLog(INFO, "[TEX ID %i] Unloaded texture data (base white texture) from VRAM", whiteTexture); + + // Unload lights + if (lightsCount > 0) + { + for (int i = 0; i < lightsCount; i++) free(lights[i]); + lightsCount = 0; + } free(draws); #endif @@ -2292,37 +2299,6 @@ Light CreateLight(int type, Vector3 position, Color diffuse) return light; } -// Draw all created lights in 3D world -void DrawLights(void) -{ - for (int i = 0; i < lightsCount; i++) - { - switch (lights[i]->type) - { - case LIGHT_POINT: - { - DrawSphereWires(lights[i]->position, 0.3f*lights[i]->intensity, 4, 8, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); - Draw3DCircle(lights[i]->position, lights[i]->radius, 0.0f, (Vector3){ 0, 0, 0 }, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); - Draw3DCircle(lights[i]->position, lights[i]->radius, 90.0f, (Vector3){ 1, 0, 0 }, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); - Draw3DCircle(lights[i]->position, lights[i]->radius, 90.0f, (Vector3){ 0, 1, 0 }, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); - } break; - case LIGHT_DIRECTIONAL: - { - Draw3DLine(lights[i]->position, lights[i]->target, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); - DrawSphereWires(lights[i]->position, 0.3f*lights[i]->intensity, 4, 8, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); - DrawCubeWires(lights[i]->target, 0.3f, 0.3f, 0.3f, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); - } break; - case LIGHT_SPOT: - { - Draw3DLine(lights[i]->position, lights[i]->target, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); - DrawCylinderWires(lights[i]->position, 0.0f, 0.3f*lights[i]->coneAngle/50, 0.6f, 5, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); - DrawCubeWires(lights[i]->target, 0.3f, 0.3f, 0.3f, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); - } break; - default: break; - } - } -} - // Destroy a light and take it out of the list void DestroyLight(Light light) { |
