Fix small bug and spacing
This commit is contained in:
parent
c320a21f2b
commit
dcd6942ed1
@ -43,7 +43,7 @@ vec3 CalcPointLight(Light l, vec3 n, vec3 v)
|
|||||||
|
|
||||||
// Specular shading
|
// Specular shading
|
||||||
float spec = 0.0;
|
float spec = 0.0;
|
||||||
if(diff > 0.0)
|
if (diff > 0.0)
|
||||||
{
|
{
|
||||||
vec3 h = normalize(-l.direction + v);
|
vec3 h = normalize(-l.direction + v);
|
||||||
spec = pow(dot(n, h), 3 + glossiness);
|
spec = pow(dot(n, h), 3 + glossiness);
|
||||||
@ -61,7 +61,7 @@ vec3 CalcDirectionalLight(Light l, vec3 n, vec3 v)
|
|||||||
|
|
||||||
// Specular shading
|
// Specular shading
|
||||||
float spec = 0.0;
|
float spec = 0.0;
|
||||||
if(diff > 0.0)
|
if (diff > 0.0)
|
||||||
{
|
{
|
||||||
vec3 h = normalize(lightDir + v);
|
vec3 h = normalize(lightDir + v);
|
||||||
spec = pow(dot(n, h), 3 + glossiness);
|
spec = pow(dot(n, h), 3 + glossiness);
|
||||||
@ -84,7 +84,7 @@ vec3 CalcSpotLight(Light l, vec3 n, vec3 v)
|
|||||||
float attenuation = clamp(dot(n, lightToSurface), 0.0, 1.0);
|
float attenuation = clamp(dot(n, lightToSurface), 0.0, 1.0);
|
||||||
attenuation = dot(lightToSurface, -lightDir);
|
attenuation = dot(lightToSurface, -lightDir);
|
||||||
float lightToSurfaceAngle = degrees(acos(attenuation));
|
float lightToSurfaceAngle = degrees(acos(attenuation));
|
||||||
if(lightToSurfaceAngle > l.coneAngle) attenuation = 0.0;
|
if (lightToSurfaceAngle > l.coneAngle) attenuation = 0.0;
|
||||||
float falloff = (l.coneAngle - lightToSurfaceAngle)/l.coneAngle;
|
float falloff = (l.coneAngle - lightToSurfaceAngle)/l.coneAngle;
|
||||||
|
|
||||||
// Combine diffuse and attenuation
|
// Combine diffuse and attenuation
|
||||||
@ -92,7 +92,7 @@ vec3 CalcSpotLight(Light l, vec3 n, vec3 v)
|
|||||||
|
|
||||||
// Specular shading
|
// Specular shading
|
||||||
float spec = 0.0;
|
float spec = 0.0;
|
||||||
if(diffAttenuation > 0.0)
|
if (diffAttenuation > 0.0)
|
||||||
{
|
{
|
||||||
vec3 h = normalize(lightDir + v);
|
vec3 h = normalize(lightDir + v);
|
||||||
spec = pow(dot(n, h), 3 + glossiness);
|
spec = pow(dot(n, h), 3 + glossiness);
|
||||||
@ -115,13 +115,13 @@ void main()
|
|||||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||||
vec3 lighting = colAmbient.rgb;
|
vec3 lighting = colAmbient.rgb;
|
||||||
|
|
||||||
for(int i = 0; i < lightsCount; i++)
|
for (int i = 0; i < lightsCount; i++)
|
||||||
{
|
{
|
||||||
// Check if light is enabled
|
// Check if light is enabled
|
||||||
if(lights[i].enabled == 1)
|
if (lights[i].enabled == 1)
|
||||||
{
|
{
|
||||||
// Calculate lighting based on light type
|
// Calculate lighting based on light type
|
||||||
switch(lights[i].type)
|
switch (lights[i].type)
|
||||||
{
|
{
|
||||||
case 0: lighting += CalcPointLight(lights[i], n, v); break;
|
case 0: lighting += CalcPointLight(lights[i], n, v); break;
|
||||||
case 1: lighting += CalcDirectionalLight(lights[i], n, v); break;
|
case 1: lighting += CalcDirectionalLight(lights[i], n, v); break;
|
||||||
|
46
src/models.c
46
src/models.c
@ -302,9 +302,9 @@ void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color
|
|||||||
rlBegin(RL_TRIANGLES);
|
rlBegin(RL_TRIANGLES);
|
||||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
for(int i = 0; i < (rings + 2); i++)
|
for (int i = 0; i < (rings + 2); i++)
|
||||||
{
|
{
|
||||||
for(int j = 0; j < slices; j++)
|
for (int j = 0; j < slices; j++)
|
||||||
{
|
{
|
||||||
rlVertex3f(cos(DEG2RAD*(270+(180/(rings + 1))*i)) * sin(DEG2RAD*(j*360/slices)),
|
rlVertex3f(cos(DEG2RAD*(270+(180/(rings + 1))*i)) * sin(DEG2RAD*(j*360/slices)),
|
||||||
sin(DEG2RAD*(270+(180/(rings + 1))*i)),
|
sin(DEG2RAD*(270+(180/(rings + 1))*i)),
|
||||||
@ -341,9 +341,9 @@ void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Col
|
|||||||
rlBegin(RL_LINES);
|
rlBegin(RL_LINES);
|
||||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
for(int i = 0; i < (rings + 2); i++)
|
for (int i = 0; i < (rings + 2); i++)
|
||||||
{
|
{
|
||||||
for(int j = 0; j < slices; j++)
|
for (int j = 0; j < slices; j++)
|
||||||
{
|
{
|
||||||
rlVertex3f(cos(DEG2RAD*(270+(180/(rings + 1))*i)) * sin(DEG2RAD*(j*360/slices)),
|
rlVertex3f(cos(DEG2RAD*(270+(180/(rings + 1))*i)) * sin(DEG2RAD*(j*360/slices)),
|
||||||
sin(DEG2RAD*(270+(180/(rings + 1))*i)),
|
sin(DEG2RAD*(270+(180/(rings + 1))*i)),
|
||||||
@ -386,7 +386,7 @@ void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float h
|
|||||||
if (radiusTop > 0)
|
if (radiusTop > 0)
|
||||||
{
|
{
|
||||||
// Draw Body -------------------------------------------------------------------------------------
|
// Draw Body -------------------------------------------------------------------------------------
|
||||||
for(int i = 0; i < 360; i += 360/sides)
|
for (int i = 0; i < 360; i += 360/sides)
|
||||||
{
|
{
|
||||||
rlVertex3f(sin(DEG2RAD*i) * radiusBottom, 0, cos(DEG2RAD*i) * radiusBottom); //Bottom Left
|
rlVertex3f(sin(DEG2RAD*i) * radiusBottom, 0, cos(DEG2RAD*i) * radiusBottom); //Bottom Left
|
||||||
rlVertex3f(sin(DEG2RAD*(i+360/sides)) * radiusBottom, 0, cos(DEG2RAD*(i+360/sides)) * radiusBottom); //Bottom Right
|
rlVertex3f(sin(DEG2RAD*(i+360/sides)) * radiusBottom, 0, cos(DEG2RAD*(i+360/sides)) * radiusBottom); //Bottom Right
|
||||||
@ -398,7 +398,7 @@ void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float h
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw Cap --------------------------------------------------------------------------------------
|
// Draw Cap --------------------------------------------------------------------------------------
|
||||||
for(int i = 0; i < 360; i += 360/sides)
|
for (int i = 0; i < 360; i += 360/sides)
|
||||||
{
|
{
|
||||||
rlVertex3f(0, height, 0);
|
rlVertex3f(0, height, 0);
|
||||||
rlVertex3f(sin(DEG2RAD*i) * radiusTop, height, cos(DEG2RAD*i) * radiusTop);
|
rlVertex3f(sin(DEG2RAD*i) * radiusTop, height, cos(DEG2RAD*i) * radiusTop);
|
||||||
@ -408,7 +408,7 @@ void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float h
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Draw Cone -------------------------------------------------------------------------------------
|
// Draw Cone -------------------------------------------------------------------------------------
|
||||||
for(int i = 0; i < 360; i += 360/sides)
|
for (int i = 0; i < 360; i += 360/sides)
|
||||||
{
|
{
|
||||||
rlVertex3f(0, height, 0);
|
rlVertex3f(0, height, 0);
|
||||||
rlVertex3f(sin(DEG2RAD*i) * radiusBottom, 0, cos(DEG2RAD*i) * radiusBottom);
|
rlVertex3f(sin(DEG2RAD*i) * radiusBottom, 0, cos(DEG2RAD*i) * radiusBottom);
|
||||||
@ -417,7 +417,7 @@ void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float h
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw Base -----------------------------------------------------------------------------------------
|
// Draw Base -----------------------------------------------------------------------------------------
|
||||||
for(int i = 0; i < 360; i += 360/sides)
|
for (int i = 0; i < 360; i += 360/sides)
|
||||||
{
|
{
|
||||||
rlVertex3f(0, 0, 0);
|
rlVertex3f(0, 0, 0);
|
||||||
rlVertex3f(sin(DEG2RAD*(i+360/sides)) * radiusBottom, 0, cos(DEG2RAD*(i+360/sides)) * radiusBottom);
|
rlVertex3f(sin(DEG2RAD*(i+360/sides)) * radiusBottom, 0, cos(DEG2RAD*(i+360/sides)) * radiusBottom);
|
||||||
@ -431,7 +431,7 @@ void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float h
|
|||||||
// NOTE: It could be also used for pyramid and cone
|
// NOTE: It could be also used for pyramid and cone
|
||||||
void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int sides, Color color)
|
void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int sides, Color color)
|
||||||
{
|
{
|
||||||
if(sides < 3) sides = 3;
|
if (sides < 3) sides = 3;
|
||||||
|
|
||||||
rlPushMatrix();
|
rlPushMatrix();
|
||||||
rlTranslatef(position.x, position.y, position.z);
|
rlTranslatef(position.x, position.y, position.z);
|
||||||
@ -439,7 +439,7 @@ void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, fl
|
|||||||
rlBegin(RL_LINES);
|
rlBegin(RL_LINES);
|
||||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
for(int i = 0; i < 360; i += 360/sides)
|
for (int i = 0; i < 360; i += 360/sides)
|
||||||
{
|
{
|
||||||
rlVertex3f(sin(DEG2RAD*i) * radiusBottom, 0, cos(DEG2RAD*i) * radiusBottom);
|
rlVertex3f(sin(DEG2RAD*i) * radiusBottom, 0, cos(DEG2RAD*i) * radiusBottom);
|
||||||
rlVertex3f(sin(DEG2RAD*(i+360/sides)) * radiusBottom, 0, cos(DEG2RAD*(i+360/sides)) * radiusBottom);
|
rlVertex3f(sin(DEG2RAD*(i+360/sides)) * radiusBottom, 0, cos(DEG2RAD*(i+360/sides)) * radiusBottom);
|
||||||
@ -500,7 +500,7 @@ void DrawGrid(int slices, float spacing)
|
|||||||
int halfSlices = slices / 2;
|
int halfSlices = slices / 2;
|
||||||
|
|
||||||
rlBegin(RL_LINES);
|
rlBegin(RL_LINES);
|
||||||
for(int i = -halfSlices; i <= halfSlices; i++)
|
for (int i = -halfSlices; i <= halfSlices; i++)
|
||||||
{
|
{
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
@ -798,9 +798,9 @@ static Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
|
|||||||
|
|
||||||
Vector3 scaleFactor = { size.x/mapX, size.y/255.0f, size.z/mapZ };
|
Vector3 scaleFactor = { size.x/mapX, size.y/255.0f, size.z/mapZ };
|
||||||
|
|
||||||
for(int z = 0; z < mapZ-1; z++)
|
for (int z = 0; z < mapZ-1; z++)
|
||||||
{
|
{
|
||||||
for(int x = 0; x < mapX-1; x++)
|
for (int x = 0; x < mapX-1; x++)
|
||||||
{
|
{
|
||||||
// Fill vertices array with data
|
// Fill vertices array with data
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
@ -1417,7 +1417,7 @@ bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius
|
|||||||
float vector = VectorDotProduct(raySpherePos, ray.direction);
|
float vector = VectorDotProduct(raySpherePos, ray.direction);
|
||||||
float d = sphereRadius*sphereRadius - (distance*distance - vector*vector);
|
float d = sphereRadius*sphereRadius - (distance*distance - vector*vector);
|
||||||
|
|
||||||
if(d >= 0.0f) collision = true;
|
if (d >= 0.0f) collision = true;
|
||||||
|
|
||||||
return collision;
|
return collision;
|
||||||
}
|
}
|
||||||
@ -1432,14 +1432,14 @@ bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadi
|
|||||||
float vector = VectorDotProduct(raySpherePos, ray.direction);
|
float vector = VectorDotProduct(raySpherePos, ray.direction);
|
||||||
float d = sphereRadius*sphereRadius - (distance*distance - vector*vector);
|
float d = sphereRadius*sphereRadius - (distance*distance - vector*vector);
|
||||||
|
|
||||||
if(d >= 0.0f) collision = true;
|
if (d >= 0.0f) collision = true;
|
||||||
|
|
||||||
// Calculate collision point
|
// Calculate collision point
|
||||||
Vector3 offset = ray.direction;
|
Vector3 offset = ray.direction;
|
||||||
float collisionDistance = 0;
|
float collisionDistance = 0;
|
||||||
|
|
||||||
// Check if ray origin is inside the sphere to calculate the correct collision point
|
// Check if ray origin is inside the sphere to calculate the correct collision point
|
||||||
if(distance < sphereRadius) collisionDistance = vector + sqrt(d);
|
if (distance < sphereRadius) collisionDistance = vector + sqrt(d);
|
||||||
else collisionDistance = vector - sqrt(d);
|
else collisionDistance = vector - sqrt(d);
|
||||||
|
|
||||||
VectorScale(&offset, collisionDistance);
|
VectorScale(&offset, collisionDistance);
|
||||||
@ -1777,11 +1777,11 @@ static Mesh LoadOBJ(const char *fileName)
|
|||||||
// First reading pass: Get numVertex, numNormals, numTexCoords, numTriangles
|
// First reading pass: Get numVertex, numNormals, numTexCoords, numTriangles
|
||||||
// NOTE: vertex, texcoords and normals could be optimized (to be used indexed on faces definition)
|
// NOTE: vertex, texcoords and normals could be optimized (to be used indexed on faces definition)
|
||||||
// NOTE: faces MUST be defined as TRIANGLES (3 vertex per face)
|
// NOTE: faces MUST be defined as TRIANGLES (3 vertex per face)
|
||||||
while(!feof(objFile))
|
while (!feof(objFile))
|
||||||
{
|
{
|
||||||
fscanf(objFile, "%c", &dataType);
|
fscanf(objFile, "%c", &dataType);
|
||||||
|
|
||||||
switch(dataType)
|
switch (dataType)
|
||||||
{
|
{
|
||||||
case '#': // Comments
|
case '#': // Comments
|
||||||
case 'o': // Object name (One OBJ file can contain multible named meshes)
|
case 'o': // Object name (One OBJ file can contain multible named meshes)
|
||||||
@ -1842,11 +1842,11 @@ static Mesh LoadOBJ(const char *fileName)
|
|||||||
// Second reading pass: Get vertex data to fill intermediate arrays
|
// Second reading pass: Get vertex data to fill intermediate arrays
|
||||||
// NOTE: This second pass is required in case of multiple meshes defined in same OBJ
|
// NOTE: This second pass is required in case of multiple meshes defined in same OBJ
|
||||||
// TODO: Consider that different meshes can have different vertex data available (position, texcoords, normals)
|
// TODO: Consider that different meshes can have different vertex data available (position, texcoords, normals)
|
||||||
while(!feof(objFile))
|
while (!feof(objFile))
|
||||||
{
|
{
|
||||||
fscanf(objFile, "%c", &dataType);
|
fscanf(objFile, "%c", &dataType);
|
||||||
|
|
||||||
switch(dataType)
|
switch (dataType)
|
||||||
{
|
{
|
||||||
case '#': case 'o': case 'g': case 's': case 'm': case 'u': case 'f': fgets(comments, 200, objFile); break;
|
case '#': case 'o': case 'g': case 's': case 'm': case 'u': case 'f': fgets(comments, 200, objFile); break;
|
||||||
case 'v':
|
case 'v':
|
||||||
@ -1903,11 +1903,11 @@ static Mesh LoadOBJ(const char *fileName)
|
|||||||
if (numNormals == 0) TraceLog(INFO, "[%s] No normals data on OBJ, normals will be generated from faces data", fileName);
|
if (numNormals == 0) TraceLog(INFO, "[%s] No normals data on OBJ, normals will be generated from faces data", fileName);
|
||||||
|
|
||||||
// Third reading pass: Get faces (triangles) data and fill VertexArray
|
// Third reading pass: Get faces (triangles) data and fill VertexArray
|
||||||
while(!feof(objFile))
|
while (!feof(objFile))
|
||||||
{
|
{
|
||||||
fscanf(objFile, "%c", &dataType);
|
fscanf(objFile, "%c", &dataType);
|
||||||
|
|
||||||
switch(dataType)
|
switch (dataType)
|
||||||
{
|
{
|
||||||
case '#': case 'o': case 'g': case 's': case 'm': case 'u': case 'v': fgets(comments, 200, objFile); break;
|
case '#': case 'o': case 'g': case 's': case 'm': case 'u': case 'v': fgets(comments, 200, objFile); break;
|
||||||
case 'f':
|
case 'f':
|
||||||
@ -2023,7 +2023,7 @@ static Material LoadMTL(const char *fileName)
|
|||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(!feof(mtlFile))
|
while (!feof(mtlFile))
|
||||||
{
|
{
|
||||||
fgets(buffer, MAX_BUFFER_SIZE, mtlFile);
|
fgets(buffer, MAX_BUFFER_SIZE, mtlFile);
|
||||||
|
|
||||||
|
10
src/rlgl.c
10
src/rlgl.c
@ -1397,7 +1397,7 @@ RenderTexture2D rlglLoadRenderTexture(int width, int height)
|
|||||||
{
|
{
|
||||||
TraceLog(WARNING, "Framebuffer object could not be created...");
|
TraceLog(WARNING, "Framebuffer object could not be created...");
|
||||||
|
|
||||||
switch(status)
|
switch (status)
|
||||||
{
|
{
|
||||||
case GL_FRAMEBUFFER_UNSUPPORTED: TraceLog(WARNING, "Framebuffer is unsupported"); break;
|
case GL_FRAMEBUFFER_UNSUPPORTED: TraceLog(WARNING, "Framebuffer is unsupported"); break;
|
||||||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: TraceLog(WARNING, "Framebuffer incomplete attachment"); break;
|
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: TraceLog(WARNING, "Framebuffer incomplete attachment"); break;
|
||||||
@ -1768,7 +1768,7 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
|
|||||||
|
|
||||||
// Check if using standard shader to get location points
|
// Check if using standard shader to get location points
|
||||||
// NOTE: standard shader specific locations are got at render time to keep Shader struct as simple as possible (with just default shader locations)
|
// NOTE: standard shader specific locations are got at render time to keep Shader struct as simple as possible (with just default shader locations)
|
||||||
if(material.shader.id == standardShader.id)
|
if (material.shader.id == standardShader.id)
|
||||||
{
|
{
|
||||||
// Send model transformations matrix to shader
|
// Send model transformations matrix to shader
|
||||||
glUniformMatrix4fv(glGetUniformLocation(material.shader.id, "modelMatrix"), 1, false, MatrixToFloat(transform));
|
glUniformMatrix4fv(glGetUniformLocation(material.shader.id, "modelMatrix"), 1, false, MatrixToFloat(transform));
|
||||||
@ -2285,7 +2285,7 @@ void DrawLights(void)
|
|||||||
Draw3DLine(lights[i]->position, lights[i]->target, (lights[i]->enabled ? lights[i]->diffuse : BLACK));
|
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));
|
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));
|
DrawCubeWires(lights[i]->target, 0.3f, 0.3f, 0.3f, (lights[i]->enabled ? lights[i]->diffuse : BLACK));
|
||||||
}
|
} break;
|
||||||
case LIGHT_SPOT:
|
case LIGHT_SPOT:
|
||||||
{
|
{
|
||||||
Draw3DLine(lights[i]->position, lights[i]->target, (lights[i]->enabled ? lights[i]->diffuse : BLACK));
|
Draw3DLine(lights[i]->position, lights[i]->target, (lights[i]->enabled ? lights[i]->diffuse : BLACK));
|
||||||
@ -3081,7 +3081,7 @@ static void SetShaderLights(Shader shader)
|
|||||||
locPoint = glGetUniformLocation(shader.id, locName);
|
locPoint = glGetUniformLocation(shader.id, locName);
|
||||||
glUniform1f(locPoint, lights[i]->intensity);
|
glUniform1f(locPoint, lights[i]->intensity);
|
||||||
|
|
||||||
switch(lights[i]->type)
|
switch (lights[i]->type)
|
||||||
{
|
{
|
||||||
case LIGHT_POINT:
|
case LIGHT_POINT:
|
||||||
{
|
{
|
||||||
@ -3295,7 +3295,7 @@ static void TraceLog(int msgType, const char *text, ...)
|
|||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, text);
|
va_start(args, text);
|
||||||
|
|
||||||
switch(msgType)
|
switch (msgType)
|
||||||
{
|
{
|
||||||
case INFO: fprintf(stdout, "INFO: "); break;
|
case INFO: fprintf(stdout, "INFO: "); break;
|
||||||
case ERROR: fprintf(stdout, "ERROR: "); break;
|
case ERROR: fprintf(stdout, "ERROR: "); break;
|
||||||
|
Loading…
Reference in New Issue
Block a user