浏览代码

Corrected bug on billboards

pull/11/head
Palaui 10 年前
父节点
当前提交
63ed471ed2
共有 1 个文件被更改,包括 15 次插入17 次删除
  1. +15
    -17
      src/models.c

+ 15
- 17
src/models.c 查看文件

@ -1145,7 +1145,6 @@ void DrawModelWires(Model model, Vector3 position, float scale, Color color)
} }
// Draw a billboard // Draw a billboard
// TODO: Math review...
void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint) void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint)
{ {
// NOTE: Billboard size will maintain texture aspect ratio, size will be billboard width // NOTE: Billboard size will maintain texture aspect ratio, size will be billboard width
@ -1157,11 +1156,11 @@ void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size,
Vector3 right = { viewMatrix.m0, viewMatrix.m4, viewMatrix.m8 }; Vector3 right = { viewMatrix.m0, viewMatrix.m4, viewMatrix.m8 };
Vector3 up = { viewMatrix.m1, viewMatrix.m5, viewMatrix.m9 }; Vector3 up = { viewMatrix.m1, viewMatrix.m5, viewMatrix.m9 };
/* /*
d-------c
a-------b
| | | |
| * | | * |
| | | |
a-------b
d-------c
*/ */
VectorScale(&right, sizeRatio.x/2); VectorScale(&right, sizeRatio.x/2);
VectorScale(&up, sizeRatio.y/2); VectorScale(&up, sizeRatio.y/2);
@ -1178,18 +1177,17 @@ void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size,
rlBegin(RL_QUADS); rlBegin(RL_QUADS);
rlColor4ub(tint.r, tint.g, tint.b, tint.a); rlColor4ub(tint.r, tint.g, tint.b, tint.a);
rlNormal3f(0.0f, 1.0f, 0.0f);
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(a.x, a.y, a.z); rlTexCoord2f(0.0f, 0.0f); rlVertex3f(a.x, a.y, a.z);
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(b.x, b.y, b.z);
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(c.x, c.y, c.z);
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(d.x, d.y, d.z); rlTexCoord2f(0.0f, 1.0f); rlVertex3f(d.x, d.y, d.z);
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(c.x, c.y, c.z);
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(b.x, b.y, b.z);
rlEnd(); rlEnd();
rlDisableTexture(); rlDisableTexture();
} }
// Draw a billboard (part of a texture defined by a rectangle) // Draw a billboard (part of a texture defined by a rectangle)
// TODO: Math review...
void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint) void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint)
{ {
// NOTE: Billboard size will maintain sourceRec aspect ratio, size will represent billboard width // NOTE: Billboard size will maintain sourceRec aspect ratio, size will represent billboard width
@ -1201,11 +1199,11 @@ void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vec
Vector3 right = { viewMatrix.m0, viewMatrix.m4, viewMatrix.m8 }; Vector3 right = { viewMatrix.m0, viewMatrix.m4, viewMatrix.m8 };
Vector3 up = { viewMatrix.m1, viewMatrix.m5, viewMatrix.m9 }; Vector3 up = { viewMatrix.m1, viewMatrix.m5, viewMatrix.m9 };
/* /*
d-------c
a-------b
| | | |
| * | | * |
| | | |
a-------b
d-------c
*/ */
VectorScale(&right, sizeRatio.x/2); VectorScale(&right, sizeRatio.x/2);
VectorScale(&up, sizeRatio.y/2); VectorScale(&up, sizeRatio.y/2);
@ -1226,18 +1224,18 @@ void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vec
// Bottom-left corner for texture and quad // Bottom-left corner for texture and quad
rlTexCoord2f((float)sourceRec.x / texture.width, (float)sourceRec.y / texture.height); rlTexCoord2f((float)sourceRec.x / texture.width, (float)sourceRec.y / texture.height);
rlVertex3f(a.x, a.y, a.z); rlVertex3f(a.x, a.y, a.z);
// Bottom-right corner for texture and quad
rlTexCoord2f((float)p">(sourceRec.x + sourceRec.width) / texture.width, (float)sourceRec.y / texture.height);
rlVertex3f(b.x, b.y, b.z);
// Top-left corner for texture and quad
rlTexCoord2f((float)sourceRec.x / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height);
rlVertex3f(d.x, d.y, d.z);
// Top-right corner for texture and quad // Top-right corner for texture and quad
rlTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height); rlTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height);
rlVertex3f(c.x, c.y, c.z); rlVertex3f(c.x, c.y, c.z);
// Top-left corner for texture and quad
rlTexCoord2f((float)sourceRec.x / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height);
rlVertex3f(d.x, d.y, d.z);
// Bottom-right corner for texture and quad
rlTexCoord2f((float)p">(sourceRec.x + sourceRec.width) / texture.width, (float)sourceRec.y / texture.height);
rlVertex3f(b.x, b.y, b.z);
rlEnd(); rlEnd();
rlDisableTexture(); rlDisableTexture();

正在加载...
取消
保存