Add function DrawCubeTextureRec (#2001)
* Add function DrawCubeTextureRec * Add EOF newline * Remove unneeded example
This commit is contained in:
parent
19ef765382
commit
025246620f
2 changed files with 157 additions and 5 deletions
|
@ -1374,6 +1374,7 @@ RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color);
|
||||||
RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires
|
RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires
|
||||||
RLAPI void DrawCubeWiresV(Vector3 position, Vector3 size, Color color); // Draw cube wires (Vector version)
|
RLAPI void DrawCubeWiresV(Vector3 position, Vector3 size, Color color); // Draw cube wires (Vector version)
|
||||||
RLAPI void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color); // Draw cube textured
|
RLAPI void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color); // Draw cube textured
|
||||||
|
RLAPI void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, float width, float height, float length, Color color); // Draw cube with a region of a texture
|
||||||
RLAPI void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere
|
RLAPI void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere
|
||||||
RLAPI void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters
|
RLAPI void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters
|
||||||
RLAPI void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires
|
RLAPI void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires
|
||||||
|
|
151
src/rmodels.c
151
src/rmodels.c
|
@ -463,6 +463,157 @@ void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float hei
|
||||||
rlSetTexture(0);
|
rlSetTexture(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, float width, float height, float length, Color color)
|
||||||
|
{
|
||||||
|
float x = position.x;
|
||||||
|
float y = position.y;
|
||||||
|
float z = position.z;
|
||||||
|
float texture_width = (float)texture.width;
|
||||||
|
float texture_height = (float)texture.height;
|
||||||
|
|
||||||
|
rlCheckRenderBatchLimit(36);
|
||||||
|
|
||||||
|
rlSetTexture(texture.id);
|
||||||
|
|
||||||
|
rlBegin(RL_QUADS);
|
||||||
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
|
// Front Face
|
||||||
|
{
|
||||||
|
// Normal Pointing Towards Viewer
|
||||||
|
rlNormal3f(0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
// Bottom Left Of The Texture and Quad
|
||||||
|
rlTexCoord2f(source.x / texture_width, (source.y + source.height) / texture_height);
|
||||||
|
rlVertex3f(x - width/2, y - height/2, z + length/2);
|
||||||
|
|
||||||
|
// Bottom Right Of The Texture and Quad
|
||||||
|
rlTexCoord2f((source.x + source.width) / texture_width, (source.y + source.height) / texture_height);
|
||||||
|
rlVertex3f(x + width/2, y - height/2, z + length/2);
|
||||||
|
|
||||||
|
// Top Right Of The Texture and Quad
|
||||||
|
rlTexCoord2f((source.x + source.width) / texture_width, source.y / texture_height);
|
||||||
|
rlVertex3f(x + width/2, y + height/2, z + length/2);
|
||||||
|
|
||||||
|
// Top Left Of The Texture and Quad
|
||||||
|
rlTexCoord2f(source.x / texture_width, source.y / texture_height);
|
||||||
|
rlVertex3f(x - width/2, y + height/2, z + length/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Back Face
|
||||||
|
{
|
||||||
|
// Normal Pointing Away From Viewer
|
||||||
|
rlNormal3f(0.0f, 0.0f, - 1.0f);
|
||||||
|
|
||||||
|
// Bottom Right Of The Texture and Quad
|
||||||
|
rlTexCoord2f((source.x + source.width) / texture_width, (source.y + source.height) / texture_height);
|
||||||
|
rlVertex3f(x - width/2, y - height/2, z - length/2);
|
||||||
|
|
||||||
|
// Top Right Of The Texture and Quad
|
||||||
|
rlTexCoord2f((source.x + source.width) / texture_width, source.y / texture_height);
|
||||||
|
rlVertex3f(x - width/2, y + height/2, z - length/2);
|
||||||
|
|
||||||
|
// Top Left Of The Texture and Quad
|
||||||
|
rlTexCoord2f(source.x / texture_width, source.y / texture_height);
|
||||||
|
rlVertex3f(x + width/2, y + height/2, z - length/2);
|
||||||
|
|
||||||
|
// Bottom Left Of The Texture and Quad
|
||||||
|
rlTexCoord2f(source.x / texture_width, (source.y + source.height) / texture_height);
|
||||||
|
rlVertex3f(x + width/2, y - height/2, z - length/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Top Face
|
||||||
|
{
|
||||||
|
// Normal Pointing Up
|
||||||
|
rlNormal3f(0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
|
// Top Left Of The Texture and Quad
|
||||||
|
rlTexCoord2f(source.x / texture_width, source.y / texture_height);
|
||||||
|
rlVertex3f(x - width/2, y + height/2, z - length/2);
|
||||||
|
|
||||||
|
// Bottom Left Of The Texture and Quad
|
||||||
|
rlTexCoord2f(source.x / texture_width, (source.y + source.height) / texture_height);
|
||||||
|
rlVertex3f(x - width/2, y + height/2, z + length/2);
|
||||||
|
|
||||||
|
// Bottom Right Of The Texture and Quad
|
||||||
|
rlTexCoord2f((source.x + source.width) / texture_width, (source.y + source.height) / texture_height);
|
||||||
|
rlVertex3f(x + width/2, y + height/2, z + length/2);
|
||||||
|
|
||||||
|
// Top Right Of The Texture and Quad
|
||||||
|
rlTexCoord2f((source.x + source.width) / texture_width, source.y / texture_height);
|
||||||
|
rlVertex3f(x + width/2, y + height/2, z - length/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bottom Face
|
||||||
|
{
|
||||||
|
// Normal Pointing Down
|
||||||
|
rlNormal3f(0.0f, - 1.0f, 0.0f);
|
||||||
|
|
||||||
|
// Top Right Of The Texture and Quad
|
||||||
|
rlTexCoord2f((source.x + source.width) / texture_width, source.y / texture_height);
|
||||||
|
rlVertex3f(x - width/2, y - height/2, z - length/2);
|
||||||
|
|
||||||
|
// Top Left Of The Texture and Quad
|
||||||
|
rlTexCoord2f(source.x / texture_width, source.y / texture_height);
|
||||||
|
rlVertex3f(x + width/2, y - height/2, z - length/2);
|
||||||
|
|
||||||
|
// Bottom Left Of The Texture and Quad
|
||||||
|
rlTexCoord2f(source.x / texture_width, (source.y + source.height) / texture_height);
|
||||||
|
rlVertex3f(x + width/2, y - height/2, z + length/2);
|
||||||
|
|
||||||
|
// Bottom Right Of The Texture and Quad
|
||||||
|
rlTexCoord2f((source.x + source.width) / texture_width, (source.y + source.height) / texture_height);
|
||||||
|
rlVertex3f(x - width/2, y - height/2, z + length/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Right face
|
||||||
|
{
|
||||||
|
// Normal Pointing Right
|
||||||
|
rlNormal3f(1.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
// Bottom Right Of The Texture and Quad
|
||||||
|
rlTexCoord2f((source.x + source.width) / texture_width, (source.y + source.height) / texture_height);
|
||||||
|
rlVertex3f(x + width/2, y - height/2, z - length/2);
|
||||||
|
|
||||||
|
// Top Right Of The Texture and Quad
|
||||||
|
rlTexCoord2f((source.x + source.width) / texture_width, source.y / texture_height);
|
||||||
|
rlVertex3f(x + width/2, y + height/2, z - length/2);
|
||||||
|
|
||||||
|
// Top Left Of The Texture and Quad
|
||||||
|
rlTexCoord2f(source.x / texture_width, source.y / texture_height);
|
||||||
|
rlVertex3f(x + width/2, y + height/2, z + length/2);
|
||||||
|
|
||||||
|
// Bottom Left Of The Texture and Quad
|
||||||
|
rlTexCoord2f(source.x / texture_width, (source.y + source.height) / texture_height);
|
||||||
|
rlVertex3f(x + width/2, y - height/2, z + length/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Left Face
|
||||||
|
{
|
||||||
|
// Normal Pointing Left
|
||||||
|
rlNormal3f( - 1.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
// Bottom Left Of The Texture and Quad
|
||||||
|
rlTexCoord2f(source.x / texture_width, (source.y + source.height) / texture_height);
|
||||||
|
rlVertex3f(x - width/2, y - height/2, z - length/2);
|
||||||
|
|
||||||
|
// Bottom Right Of The Texture and Quad
|
||||||
|
rlTexCoord2f((source.x + source.width) / texture_width, (source.y + source.height) / texture_height);
|
||||||
|
rlVertex3f(x - width/2, y - height/2, z + length/2);
|
||||||
|
|
||||||
|
// Top Right Of The Texture and Quad
|
||||||
|
rlTexCoord2f((source.x + source.width) / texture_width, source.y / texture_height);
|
||||||
|
rlVertex3f(x - width/2, y + height/2, z + length/2);
|
||||||
|
|
||||||
|
// Top Left Of The Texture and Quad
|
||||||
|
rlTexCoord2f(source.x / texture_width, source.y / texture_height);
|
||||||
|
rlVertex3f(x - width/2, y + height/2, z - length/2);
|
||||||
|
}
|
||||||
|
rlEnd();
|
||||||
|
|
||||||
|
rlSetTexture(0);
|
||||||
|
}
|
||||||
|
|
||||||
// Draw sphere
|
// Draw sphere
|
||||||
void DrawSphere(Vector3 centerPos, float radius, Color color)
|
void DrawSphere(Vector3 centerPos, float radius, Color color)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue