diff --git a/src/models.c b/src/models.c index f59a7b43..1ae95f23 100644 --- a/src/models.c +++ b/src/models.c @@ -66,14 +66,14 @@ static VertexData LoadOBJ(const char *fileName); // NOTE: Cube position is the center position void DrawCube(Vector3 position, float width, float height, float lenght, Color color) { - float x = position.x; - float y = position.y; - float z = position.z; + float x = 0.0f; + float y = 0.0f; + float z = 0.0f; rlPushMatrix(); // NOTE: Be careful! Function order matters (rotate -> scale -> translate) - //rlTranslatef(0.0f, 0.0f, 0.0f); + rlTranslatef(position.x, position.y, position.z); //rlScalef(2.0f, 2.0f, 2.0f); //rlRotatef(45, 0, 1, 0); @@ -146,12 +146,13 @@ void DrawCubeV(Vector3 position, Vector3 size, Color color) // Draw cube wires void DrawCubeWires(Vector3 position, float width, float height, float lenght, Color color) { - float x = position.x; - float y = position.y; - float z = position.z; + float x = 0.0f; + float y = 0.0f; + float z = 0.0f; rlPushMatrix(); + rlTranslatef(position.x, position.y, position.z); //rlRotatef(45, 0, 1, 0); rlBegin(RL_LINES); @@ -445,11 +446,37 @@ void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, fl rlPopMatrix(); } +// Draw a quad +void DrawQuad(Vector3 vertices[4], Vector2 textcoords[4], Vector3 normals[4], Color colors[4]) +{ + rlBegin(RL_QUADS); + rlColor4ub(colors[0].r, colors[0].g, colors[0].b, colors[0].a); + rlNormal3f(normals[0].x, normals[0].y, normals[0].z); + rlTexCoord2f(textcoords[0].x, textcoords[0].y); + rlVertex3f(vertices[0].x, vertices[0].y, vertices[0].z); + + rlColor4ub(colors[1].r, colors[1].g, colors[1].b, colors[1].a); + rlNormal3f(normals[1].x, normals[1].y, normals[1].z); + rlTexCoord2f(textcoords[1].x, textcoords[1].y); + rlVertex3f(vertices[1].x, vertices[1].y, vertices[1].z); + + rlColor4ub(colors[2].r, colors[2].g, colors[2].b, colors[2].a); + rlNormal3f(normals[2].x, normals[2].y, normals[2].z); + rlTexCoord2f(textcoords[2].x, textcoords[2].y); + rlVertex3f(vertices[2].x, vertices[2].y, vertices[2].z); + + rlColor4ub(colors[3].r, colors[3].g, colors[3].b, colors[3].a); + rlNormal3f(normals[3].x, normals[3].y, normals[3].z); + rlTexCoord2f(textcoords[3].x, textcoords[3].y); + rlVertex3f(vertices[3].x, vertices[3].y, vertices[3].z); + rlEnd(); +} + // Draw a plane void DrawPlane(Vector3 centerPos, Vector2 size, Vector3 rotation, Color color) { // NOTE: QUADS usage require defining a texture on OpenGL 3.3+ - rlEnableTexture(1); // Default white texture + if (rlGetVersion() != OPENGL_11) rlEnableTexture(1); // Default white texture // NOTE: Plane is always created on XZ ground and then rotated rlPushMatrix(); @@ -471,7 +498,7 @@ void DrawPlane(Vector3 centerPos, Vector2 size, Vector3 rotation, Color color) rlEnd(); rlPopMatrix(); - rlDisableTexture(); + if (rlGetVersion() != OPENGL_11) rlDisableTexture(); } // Draw a plane with divisions @@ -1041,7 +1068,7 @@ Model LoadCubesmap(Image cubesmap) // Move data from mapVertices temp arays to vertices float array vData.vertexCount = vCounter; - printf("Vertex count: %i\n", vCounter); + //printf("Vertex count: %i\n", vCounter); vData.vertices = (float *)malloc(vData.vertexCount * 3 * sizeof(float)); vData.normals = (float *)malloc(vData.vertexCount * 3 * sizeof(float)); diff --git a/src/raylib.h b/src/raylib.h index c061a9b0..89648ef1 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -446,6 +446,7 @@ void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires +void DrawQuad(Vector3 vertices[4], Vector2 textcoords[4], Vector3 normals[4], Color colors[4]); // Draw a quad void DrawPlane(Vector3 centerPos, Vector2 size, Vector3 rotation, Color color); // Draw a plane void DrawPlaneEx(Vector3 centerPos, Vector2 size, Vector3 rotation, int slicesX, int slicesZ, Color color); // Draw a plane with divisions void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) diff --git a/src/raymath.c b/src/raymath.c index e598b381..56b79b42 100644 --- a/src/raymath.c +++ b/src/raymath.c @@ -559,8 +559,8 @@ Matrix MatrixFromAxisAngle2(Vector3 axis, float angle) float axisX = axis.x, axisY = axis.y, axisZ = axis.y; // Calculate angles - float cosres = (float)cos(-angle); - float sinres = (float)sin(-angle); + float cosres = (float)cos(angle); + float sinres = (float)sin(angle); float t = 1.0f - cosres; // Do the conversion math once @@ -672,6 +672,8 @@ Matrix MatrixTransform(Vector3 translation, Vector3 rotation, Vector3 scale) { Matrix result = MatrixIdentity(); + // TODO: Review, use DEG2RAD here? + //Matrix mRotation = MatrixRotate(rotation.x*DEG2RAD, rotation.y*DEG2RAD, rotation.z*DEG2RAD); Matrix mRotation = MatrixRotate(rotation.x, rotation.y, rotation.z); Matrix mScale = MatrixScale(scale.x, scale.y, scale.z); Matrix mTranslate = MatrixTranslate(translation.x, translation.y, translation.z); diff --git a/src/rlgl.c b/src/rlgl.c index ddd55a2d..43052237 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -299,14 +299,21 @@ void rlRotatef(float angleDeg, float x, float y, float z) // TODO: Support rotation in multiple axes Matrix rot = MatrixIdentity(); + // OPTION 1: It works... if (x == 1) rot = MatrixRotateX(angleDeg*DEG2RAD); else if (y == 1) rot = MatrixRotateY(angleDeg*DEG2RAD); else if (z == 1) rot = MatrixRotateZ(angleDeg*DEG2RAD); - //Vector3 vec = (Vector3){ 0, 0, 1 }; + // OPTION 2: Requires review... + //Vector3 vec = (Vector3){ 0, 1, 0 }; //VectorNormalize(&vec); - //rot = MatrixFromAxisAngle(vec, angleDeg*DEG2RAD); // Working - + //rot = MatrixFromAxisAngle(vec, angleDeg*DEG2RAD); // Working? + + // OPTION 3: TODO: Review, it doesn't work! + //Vector3 vec = (Vector3){ x, y, z }; + //VectorNormalize(&vec); + //rot = MatrixRotate(angleDeg*vec.x, angleDeg*vec.x, angleDeg*vec.x); + MatrixTranspose(&rot); *currentMatrix = MatrixMultiply(*currentMatrix, rot);