Add a slider for each individual plane scale
This commit is contained in:
parent
d52d63e310
commit
496cc2ae8c
82
main.cpp
82
main.cpp
@ -32,8 +32,8 @@ struct RubixCube {
|
|||||||
|
|
||||||
void DrawRubixCube(RubixCube* cube);
|
void DrawRubixCube(RubixCube* cube);
|
||||||
void DrawPlane3D(Plane3D* plane);
|
void DrawPlane3D(Plane3D* plane);
|
||||||
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);
|
||||||
RubixCube CreateRubixCube(Vector3 position, float size);
|
RubixCube CreateRubixCube(Vector3 position, float size, float planeScale);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
SetConfigFlags(FLAG_VSYNC_HINT);
|
SetConfigFlags(FLAG_VSYNC_HINT);
|
||||||
@ -50,7 +50,9 @@ int main() {
|
|||||||
|
|
||||||
float cubeSize = 3.0f;
|
float cubeSize = 3.0f;
|
||||||
float previousCubeSize = cubeSize;
|
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
|
// Disable backface culling
|
||||||
rlDisableBackfaceCulling();
|
rlDisableBackfaceCulling();
|
||||||
@ -71,15 +73,15 @@ int main() {
|
|||||||
rlImGuiBegin();
|
rlImGuiBegin();
|
||||||
ImGui::Begin("Controls");
|
ImGui::Begin("Controls");
|
||||||
ImGui::SliderFloat("Cube Size", &cubeSize, 1.0f, 10.0f);
|
ImGui::SliderFloat("Cube Size", &cubeSize, 1.0f, 10.0f);
|
||||||
|
ImGui::SliderFloat("Plane Scale", &planeScale, 0.1f, 1.0f);
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
rlImGuiEnd();
|
rlImGuiEnd();
|
||||||
|
|
||||||
if (cubeSize != previousCubeSize) {
|
if (cubeSize != previousCubeSize || planeScale != 1.0f) {
|
||||||
cube = CreateRubixCube({0.0f, 0.0f, 0.0f}, cubeSize);
|
cube = CreateRubixCube({0.0f, 0.0f, 0.0f}, cubeSize, planeScale);
|
||||||
previousCubeSize = cubeSize;
|
previousCubeSize = cubeSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BeginMode3D(cam);
|
BeginMode3D(cam);
|
||||||
|
|
||||||
DrawRubixCube(&cube);
|
DrawRubixCube(&cube);
|
||||||
@ -89,12 +91,15 @@ int main() {
|
|||||||
EndMode3D();
|
EndMode3D();
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rlImGuiShutdown();
|
||||||
|
CloseWindow();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawRubixCube(RubixCube* cube) {
|
void DrawRubixCube(RubixCube* cube) {
|
||||||
|
rlDisableBackfaceCulling();
|
||||||
for (int face = 0; face < 6; face++) {
|
for (int face = 0; face < 6; face++) {
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
DrawPlane3D(&cube->faces[face][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;
|
RubixCube cube;
|
||||||
cube.pos = position;
|
cube.pos = position;
|
||||||
|
|
||||||
@ -118,27 +123,27 @@ RubixCube CreateRubixCube(Vector3 position, float size) {
|
|||||||
switch (face) {
|
switch (face) {
|
||||||
case FRONT:
|
case FRONT:
|
||||||
planePos = { position.x + x * planeSize, position.y + y * planeSize, position.z + size / 2 };
|
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;
|
break;
|
||||||
case BACK:
|
case BACK:
|
||||||
planePos = { position.x + x * planeSize, position.y + y * planeSize, position.z - size / 2 };
|
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;
|
break;
|
||||||
case LEFT:
|
case LEFT:
|
||||||
planePos = { position.x - size / 2, position.y + y * planeSize, position.z + x * planeSize };
|
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;
|
break;
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
planePos = { position.x + size / 2, position.y + y * planeSize, position.z + x * planeSize };
|
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;
|
break;
|
||||||
case TOP:
|
case TOP:
|
||||||
planePos = { position.x + x * planeSize, position.y + size / 2, position.z + y * planeSize };
|
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;
|
break;
|
||||||
case BOTTOM:
|
case BOTTOM:
|
||||||
planePos = { position.x + x * planeSize, position.y - size / 2, position.z + y * planeSize };
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,37 +158,7 @@ void DrawPlane3D(Plane3D* plane) {
|
|||||||
DrawTriangle3D(plane->two.pointOne, plane->two.pointTwo, plane->two.pointThree, plane->color);
|
DrawTriangle3D(plane->two.pointOne, plane->two.pointTwo, plane->two.pointThree, plane->color);
|
||||||
}
|
}
|
||||||
|
|
||||||
Plane3D CreatePlane3D(float width, float height) {
|
Plane3D CreatePlane3D(float width, float height, Vector3 position, Color color, Vector3 normal, float scale) {
|
||||||
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 plane3D;
|
Plane3D plane3D;
|
||||||
plane3D.color = color;
|
plane3D.color = color;
|
||||||
|
|
||||||
@ -197,13 +172,16 @@ Plane3D CreatePlane3D(float width, float height, Vector3 position, Color color,
|
|||||||
up = {0, 1, 0};
|
up = {0, 1, 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
plane3D.one.pointOne = Vector3Add(Vector3Add(position, Vector3Scale(right, -width / 2)), Vector3Scale(up, -height / 2));
|
float scaledWidth = width * scale;
|
||||||
plane3D.one.pointTwo = Vector3Add(Vector3Add(position, Vector3Scale(right, width / 2)), Vector3Scale(up, -height / 2));
|
float scaledHeight = height * scale;
|
||||||
plane3D.one.pointThree = Vector3Add(Vector3Add(position, Vector3Scale(right, -width / 2)), Vector3Scale(up, height / 2));
|
|
||||||
|
|
||||||
plane3D.two.pointOne = 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.two.pointTwo = Vector3Add(Vector3Add(position, Vector3Scale(right, width / 2)), Vector3Scale(up, height / 2));
|
plane3D.one.pointTwo = Vector3Add(Vector3Add(position, Vector3Scale(right, scaledWidth / 2)), Vector3Scale(up, -scaledHeight / 2));
|
||||||
plane3D.two.pointThree = Vector3Add(Vector3Add(position, Vector3Scale(right, -width / 2)), Vector3Scale(up, height / 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;
|
return plane3D;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user