summaryrefslogtreecommitdiff
path: root/3d
diff options
context:
space:
mode:
Diffstat (limited to '3d')
-rwxr-xr-x3d/rigidbody/dist/output.wasmbin37871 -> 43282 bytes
-rw-r--r--3d/rigidbody/main.cpp64
2 files changed, 43 insertions, 21 deletions
diff --git a/3d/rigidbody/dist/output.wasm b/3d/rigidbody/dist/output.wasm
index bd15618..9365ee9 100755
--- a/3d/rigidbody/dist/output.wasm
+++ b/3d/rigidbody/dist/output.wasm
Binary files differ
diff --git a/3d/rigidbody/main.cpp b/3d/rigidbody/main.cpp
index 8fe0691..1dfc593 100644
--- a/3d/rigidbody/main.cpp
+++ b/3d/rigidbody/main.cpp
@@ -1,4 +1,5 @@
#include "../../shared_cpp/Renderer3d.h"
+#include "../../shared_cpp/RenderShared.h"
#include "../../shared_cpp/Camera3d.h"
#include "../../shared_cpp/types.h"
#include "../../shared_cpp/WebglContext.h"
@@ -18,50 +19,71 @@ struct Cube {
void load(Renderer3d* renderer) {
Vertex3d cubeVertices[] = {
{
- Vector3 { -1.0, -1.0, 1.0 },
- Vector3()
+ Vector3 { 1.f, 1.f, 1.f },
+ Vector3(),
+ colorFromHex(255.f, 0.f, 0.f, 255.f)
},
{
- Vector3 { 1.0, -1.0, 1.0 },
- Vector3()
+ Vector3 { -1.f, 1.f, 1.f },
+ Vector3(),
+ colorFromHex(0.f, 255.f, 0.f, 255.f)
},
{
- Vector3 { -1.0, 1.0, 1.0 },
- Vector3()
+ Vector3 { -1.f, 1.f, -1.f },
+ Vector3(),
+ colorFromHex(0.f, 0.f, 255.f, 255.f)
},
{
- Vector3 { 1.0, 1.0, 1.0 },
- Vector3()
+ Vector3 { 1.f, 1.f, -1.f },
+ Vector3(),
+ colorFromHex(255.f, 0.f, 255.f, 255.f)
},
{
- Vector3 { -1.0, -1.0, -1.0 },
- Vector3()
+ Vector3 { 1.f, -1.f, 1.f },
+ Vector3(),
+ colorFromHex(255.f, 255.f, 0.f, 255.f)
},
{
- Vector3 { 1.0, -1.0, -1.0 },
- Vector3()
+ Vector3 { -1.f, -1.f, 1.f },
+ Vector3(),
+ colorFromHex(255.f, 0.f, 0.f, 255.f)
},
{
- Vector3 { -1.0, 1.0, -1.0 },
- Vector3()
+ Vector3 { -1.f, -1.f, -1.f },
+ Vector3(),
+ colorFromHex(0.f, 0.f, 255.f, 255.f)
},
{
- Vector3 { 1.0, 1.0, -1.0 },
- Vector3()
+ Vector3 { 1.f, -1.f, -1.f },
+ Vector3(),
+ colorFromHex(255.f, 255.f, 0.f, 255.f)
}
};
uint32 cubeIndices[] = {
- 0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1
+ 0, 1, 3, //top 1
+ 3, 1, 2, //top 2
+ 2, 6, 7, //front 1
+ 7, 3, 2, //front 2
+ 7, 6, 5, //bottom 1
+ 5, 4, 7, //bottom 2
+ 5, 1, 4, //back 1
+ 4, 1, 0, //back 2
+ 4, 3, 7, //right 1
+ 3, 4, 0, //right 2
+ 5, 6, 2, //left 1
+ 5, 1, 2 //left 2
};
- mesh.load(&cubeVertices[0], 8, cubeIndices, 14, renderer);
+ mesh.load(&cubeVertices[0], 8, cubeIndices, 36, renderer);
}
void update(float32 dtSeconds) {
- mesh.model = mesh.model.rotate2D((PI / 8.f) * dtSeconds);
+ float32 multiplier = (PI / 8.f) * dtSeconds;
+ Vector3 currentRotation = Vector3 { multiplier, multiplier, multiplier };
+ mesh.model = mesh.model.rotate(currentRotation.x, currentRotation.y, currentRotation.z);
}
void render(Renderer3d* renderer) {
@@ -97,8 +119,8 @@ int main() {
void load() {
renderer.load(&context);
cube.load(&renderer);
- camera.projection = camera.projection.getPerspectiveProjection(0.1f, 100.f, PI / 2.f, 800.f / 600.f);
- camera.view = camera.view.translate({ 0, 0, -10 });
+ camera.projection = Mat4x4().getPerspectiveProjection(0.1f, 100.f, PI / 2.f, 800.f / 600.f);
+ camera.view = Mat4x4().translate({ 0, 0, -10 });
mainLoop.run(update);
}