Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
This commit is contained in:
commit
78b4494e2b
4 changed files with 51 additions and 46 deletions
|
@ -47,8 +47,6 @@ int main()
|
|||
|
||||
dwarf.material = material; // Apply material to model
|
||||
|
||||
Model dwarf2 = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
|
||||
|
||||
Light spotLight = CreateLight(LIGHT_SPOT, (Vector3){3.0f, 5.0f, 2.0f}, (Color){255, 255, 255, 255});
|
||||
spotLight->target = (Vector3){0.0f, 0.0f, 0.0f};
|
||||
spotLight->intensity = 2.0f;
|
||||
|
@ -91,7 +89,9 @@ int main()
|
|||
|
||||
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
||||
|
||||
DrawLights(); // Draw all created lights in 3D world
|
||||
DrawLight(spotLight); // Draw spot light
|
||||
DrawLight(dirLight); // Draw directional light
|
||||
DrawLight(pointLight); // Draw point light
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
|
29
src/models.c
29
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)
|
||||
{
|
||||
|
|
18
src/raylib.h
18
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
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
38
src/rlgl.c
38
src/rlgl.c
|
@ -1070,6 +1070,13 @@ void rlglClose(void)
|
|||
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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue