Add a slider for each individual plane scale

This commit is contained in:
illyum 2024-09-18 17:24:48 -06:00
parent d52d63e310
commit 496cc2ae8c

View File

@ -32,8 +32,8 @@ struct RubixCube {
void DrawRubixCube(RubixCube* cube);
void DrawPlane3D(Plane3D* plane);
Plane3D CreatePlane3D(float width, float height, Vector3 position, Color color, Vector3 normal);
RubixCube CreateRubixCube(Vector3 position, float size);
Plane3D CreatePlane3D(float width, float height, Vector3 position, Color color, Vector3 normal, float scale);
RubixCube CreateRubixCube(Vector3 position, float size, float planeScale);
int main() {
SetConfigFlags(FLAG_VSYNC_HINT);
@ -50,7 +50,9 @@ int main() {
float cubeSize = 3.0f;
float previousCubeSize = cubeSize;
RubixCube cube = CreateRubixCube({0.0f, 0.0f, 0.0f}, cubeSize);
float planeScale = 1.0f;
RubixCube cube = CreateRubixCube({0.0f, 0.0f, 0.0f}, cubeSize, planeScale);
// Disable backface culling
rlDisableBackfaceCulling();
@ -71,15 +73,15 @@ int main() {
rlImGuiBegin();
ImGui::Begin("Controls");
ImGui::SliderFloat("Cube Size", &cubeSize, 1.0f, 10.0f);
ImGui::SliderFloat("Plane Scale", &planeScale, 0.1f, 1.0f);
ImGui::End();
rlImGuiEnd();
if (cubeSize != previousCubeSize) {
cube = CreateRubixCube({0.0f, 0.0f, 0.0f}, cubeSize);
if (cubeSize != previousCubeSize || planeScale != 1.0f) {
cube = CreateRubixCube({0.0f, 0.0f, 0.0f}, cubeSize, planeScale);
previousCubeSize = cubeSize;
}
BeginMode3D(cam);
DrawRubixCube(&cube);
@ -89,12 +91,15 @@ int main() {
EndMode3D();
EndDrawing();
}
rlImGuiShutdown();
CloseWindow();
return 0;
}
void DrawRubixCube(RubixCube* cube) {
rlDisableBackfaceCulling();
for (int face = 0; face < 6; face++) {
for (int i = 0; i < 9; i++) {
DrawPlane3D(&cube->faces[face][i]);
@ -102,7 +107,7 @@ void DrawRubixCube(RubixCube* cube) {
}
}
RubixCube CreateRubixCube(Vector3 position, float size) {
RubixCube CreateRubixCube(Vector3 position, float size, float planeScale) {
RubixCube cube;
cube.pos = position;
@ -118,27 +123,27 @@ RubixCube CreateRubixCube(Vector3 position, float size) {
switch (face) {
case FRONT:
planePos = { position.x + x * planeSize, position.y + y * planeSize, position.z + size / 2 };
cube.faces[face][faceIndex++] = CreatePlane3D(planeSize, planeSize, planePos, RED, {0, 0, 1});
cube.faces[face][faceIndex++] = CreatePlane3D(planeSize, planeSize, planePos, RED, {0, 0, 1}, planeScale);
break;
case BACK:
planePos = { position.x + x * planeSize, position.y + y * planeSize, position.z - size / 2 };
cube.faces[face][faceIndex++] = CreatePlane3D(planeSize, planeSize, planePos, ORANGE, {0, 0, -1});
cube.faces[face][faceIndex++] = CreatePlane3D(planeSize, planeSize, planePos, ORANGE, {0, 0, -1}, planeScale);
break;
case LEFT:
planePos = { position.x - size / 2, position.y + y * planeSize, position.z + x * planeSize };
cube.faces[face][faceIndex++] = CreatePlane3D(planeSize, planeSize, planePos, BLUE, {-1, 0, 0});
cube.faces[face][faceIndex++] = CreatePlane3D(planeSize, planeSize, planePos, BLUE, {-1, 0, 0}, planeScale);
break;
case RIGHT:
planePos = { position.x + size / 2, position.y + y * planeSize, position.z + x * planeSize };
cube.faces[face][faceIndex++] = CreatePlane3D(planeSize, planeSize, planePos, GREEN, {1, 0, 0});
cube.faces[face][faceIndex++] = CreatePlane3D(planeSize, planeSize, planePos, GREEN, {1, 0, 0}, planeScale);
break;
case TOP:
planePos = { position.x + x * planeSize, position.y + size / 2, position.z + y * planeSize };
cube.faces[face][faceIndex++] = CreatePlane3D(planeSize, planeSize, planePos, YELLOW, {0, 1, 0});
cube.faces[face][faceIndex++] = CreatePlane3D(planeSize, planeSize, planePos, YELLOW, {0, 1, 0}, planeScale);
break;
case BOTTOM:
planePos = { position.x + x * planeSize, position.y - size / 2, position.z + y * planeSize };
cube.faces[face][faceIndex++] = CreatePlane3D(planeSize, planeSize, planePos, WHITE, {0, -1, 0});
cube.faces[face][faceIndex++] = CreatePlane3D(planeSize, planeSize, planePos, WHITE, {0, -1, 0}, planeScale);
break;
}
}
@ -153,37 +158,7 @@ void DrawPlane3D(Plane3D* plane) {
DrawTriangle3D(plane->two.pointOne, plane->two.pointTwo, plane->two.pointThree, plane->color);
}
Plane3D CreatePlane3D(float width, float height) {
Plane3D plane3D;
plane3D.color = BLUE;
plane3D.one.pointOne = { -width / 2.0f, -height / 2.0f, 0.0f };
plane3D.one.pointTwo = { width / 2.0f, -height / 2.0f, 0.0f };
plane3D.one.pointThree = { -width / 2.0f, height / 2.0f, 0.0f };
plane3D.two.pointOne = { width / 2.0f, -height / 2.0f, 0.0f };
plane3D.two.pointTwo = { width / 2.0f, height / 2.0f, 0.0f };
plane3D.two.pointThree = { -width / 2.0f, height / 2.0f, 0.0f };
return plane3D;
}
Plane3D CreatePlane3D(float width, float height, Vector3 position, Color color) {
Plane3D plane3D;
plane3D.color = color;
plane3D.one.pointOne = { position.x - width / 2.0f, position.y - height / 2.0f, position.z };
plane3D.one.pointTwo = { position.x + width / 2.0f, position.y - height / 2.0f, position.z };
plane3D.one.pointThree = { position.x - width / 2.0f, position.y + height / 2.0f, position.z };
plane3D.two.pointOne = { position.x + width / 2.0f, position.y - height / 2.0f, position.z };
plane3D.two.pointTwo = { position.x + width / 2.0f, position.y + height / 2.0f, position.z };
plane3D.two.pointThree = { position.x - width / 2.0f, position.y + height / 2.0f, position.z };
return plane3D;
}
Plane3D CreatePlane3D(float width, float height, Vector3 position, Color color, Vector3 normal) {
Plane3D CreatePlane3D(float width, float height, Vector3 position, Color color, Vector3 normal, float scale) {
Plane3D plane3D;
plane3D.color = color;
@ -197,13 +172,16 @@ Plane3D CreatePlane3D(float width, float height, Vector3 position, Color color,
up = {0, 1, 0};
}
plane3D.one.pointOne = Vector3Add(Vector3Add(position, Vector3Scale(right, -width / 2)), Vector3Scale(up, -height / 2));
plane3D.one.pointTwo = Vector3Add(Vector3Add(position, Vector3Scale(right, width / 2)), Vector3Scale(up, -height / 2));
plane3D.one.pointThree = Vector3Add(Vector3Add(position, Vector3Scale(right, -width / 2)), Vector3Scale(up, height / 2));
float scaledWidth = width * scale;
float scaledHeight = height * scale;
plane3D.two.pointOne = Vector3Add(Vector3Add(position, Vector3Scale(right, width / 2)), Vector3Scale(up, -height / 2));
plane3D.two.pointTwo = Vector3Add(Vector3Add(position, Vector3Scale(right, width / 2)), Vector3Scale(up, height / 2));
plane3D.two.pointThree = Vector3Add(Vector3Add(position, Vector3Scale(right, -width / 2)), Vector3Scale(up, height / 2));
plane3D.one.pointOne = Vector3Add(Vector3Add(position, Vector3Scale(right, -scaledWidth / 2)), Vector3Scale(up, -scaledHeight / 2));
plane3D.one.pointTwo = Vector3Add(Vector3Add(position, Vector3Scale(right, scaledWidth / 2)), Vector3Scale(up, -scaledHeight / 2));
plane3D.one.pointThree = Vector3Add(Vector3Add(position, Vector3Scale(right, -scaledWidth / 2)), Vector3Scale(up, scaledHeight / 2));
plane3D.two.pointOne = Vector3Add(Vector3Add(position, Vector3Scale(right, scaledWidth / 2)), Vector3Scale(up, -scaledHeight / 2));
plane3D.two.pointTwo = Vector3Add(Vector3Add(position, Vector3Scale(right, scaledWidth / 2)), Vector3Scale(up, scaledHeight / 2));
plane3D.two.pointThree = Vector3Add(Vector3Add(position, Vector3Scale(right, -scaledWidth / 2)), Vector3Scale(up, scaledHeight / 2));
return plane3D;
}
}