mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-20 10:18:14 +00:00
WARNING: REMOVED: DrawCubeTexture()
, DrawCubeTextureRec()
Those two functions have been moved to a new example: `models_draw_cube_texture`. The reasons for this decision: - Function inflexibility: Many users with the need to draw a textured cube could need to customize the texture applied to every face, that function did not allow that kind of functionality. - rlgl functionality exposure: The implementation exposed will teach users how to implement custom textured triangles drawing.
This commit is contained in:
145
src/rmodels.c
145
src/rmodels.c
@@ -397,151 +397,6 @@ void DrawCubeWiresV(Vector3 position, Vector3 size, Color color)
|
||||
DrawCubeWires(position, size.x, size.y, size.z, color);
|
||||
}
|
||||
|
||||
// Draw cube
|
||||
// NOTE: Cube position is the center position
|
||||
void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color)
|
||||
{
|
||||
float x = position.x;
|
||||
float y = position.y;
|
||||
float z = position.z;
|
||||
|
||||
rlSetTexture(texture.id);
|
||||
|
||||
//rlPushMatrix();
|
||||
// NOTE: Transformation is applied in inverse order (scale -> rotate -> translate)
|
||||
//rlTranslatef(2.0f, 0.0f, 0.0f);
|
||||
//rlRotatef(45, 0, 1, 0);
|
||||
//rlScalef(2.0f, 2.0f, 2.0f);
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
// Front Face
|
||||
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer
|
||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Right Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left Of The Texture and Quad
|
||||
// Back Face
|
||||
rlNormal3f(0.0f, 0.0f, - 1.0f); // Normal Pointing Away From Viewer
|
||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Right Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Left Of The Texture and Quad
|
||||
// Top Face
|
||||
rlNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up
|
||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Bottom Left Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Bottom Right Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad
|
||||
// Bottom Face
|
||||
rlNormal3f(0.0f, - 1.0f, 0.0f); // Normal Pointing Down
|
||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Top Right Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Top Left Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad
|
||||
// Right face
|
||||
rlNormal3f(1.0f, 0.0f, 0.0f); // Normal Pointing Right
|
||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Left Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad
|
||||
// Left Face
|
||||
rlNormal3f( - 1.0f, 0.0f, 0.0f); // Normal Pointing Left
|
||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Left Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Right Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad
|
||||
rlEnd();
|
||||
//rlPopMatrix();
|
||||
|
||||
rlSetTexture(0);
|
||||
}
|
||||
|
||||
// Draw cube with texture piece applied to all faces
|
||||
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 texWidth = (float)texture.width;
|
||||
float texHeight = (float)texture.height;
|
||||
|
||||
rlSetTexture(texture.id);
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
// Front face
|
||||
rlNormal3f(0.0f, 0.0f, 1.0f);
|
||||
rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x - width/2, y - height/2, z + length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x + width/2, y - height/2, z + length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x + width/2, y + height/2, z + length/2);
|
||||
rlTexCoord2f(source.x/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x - width/2, y + height/2, z + length/2);
|
||||
|
||||
// Back face
|
||||
rlNormal3f(0.0f, 0.0f, - 1.0f);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x - width/2, y - height/2, z - length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x - width/2, y + height/2, z - length/2);
|
||||
rlTexCoord2f(source.x/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x + width/2, y + height/2, z - length/2);
|
||||
rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x + width/2, y - height/2, z - length/2);
|
||||
|
||||
// Top face
|
||||
rlNormal3f(0.0f, 1.0f, 0.0f);
|
||||
rlTexCoord2f(source.x/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x - width/2, y + height/2, z - length/2);
|
||||
rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x - width/2, y + height/2, z + length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x + width/2, y + height/2, z + length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x + width/2, y + height/2, z - length/2);
|
||||
|
||||
// Bottom face
|
||||
rlNormal3f(0.0f, - 1.0f, 0.0f);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x - width/2, y - height/2, z - length/2);
|
||||
rlTexCoord2f(source.x/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x + width/2, y - height/2, z - length/2);
|
||||
rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x + width/2, y - height/2, z + length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x - width/2, y - height/2, z + length/2);
|
||||
|
||||
// Right face
|
||||
rlNormal3f(1.0f, 0.0f, 0.0f);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x + width/2, y - height/2, z - length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x + width/2, y + height/2, z - length/2);
|
||||
rlTexCoord2f(source.x/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x + width/2, y + height/2, z + length/2);
|
||||
rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x + width/2, y - height/2, z + length/2);
|
||||
|
||||
// Left face
|
||||
rlNormal3f( - 1.0f, 0.0f, 0.0f);
|
||||
rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x - width/2, y - height/2, z - length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x - width/2, y - height/2, z + length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x - width/2, y + height/2, z + length/2);
|
||||
rlTexCoord2f(source.x/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x - width/2, y + height/2, z - length/2);
|
||||
|
||||
rlEnd();
|
||||
|
||||
rlSetTexture(0);
|
||||
}
|
||||
|
||||
// Draw sphere
|
||||
void DrawSphere(Vector3 centerPos, float radius, Color color)
|
||||
{
|
||||
|
Reference in New Issue
Block a user