|
|
@@ -24,6 +24,136 @@ void drawPixel(S3L_PixelInfo *p)
|
|
|
S3L_Unit cubeVertices[] = { S3L_CUBE_VERTICES(S3L_FRACTIONS_PER_UNIT) };
|
|
|
S3L_Index cubeTriangles[] = { S3L_CUBE_TRIANGLES };
|
|
|
|
|
|
+#define SPHERE_VERTEX_COUNT 42
|
|
|
+const S3L_Unit sphereVertices[SPHERE_VERTEX_COUNT * 3] = {
|
|
|
+ 0, -512, 0, // 0
|
|
|
+ 370, -228, -269, // 3
|
|
|
+ -141, -228, -435, // 6
|
|
|
+ -457, -228, 0, // 9
|
|
|
+ -141, -228, 435, // 12
|
|
|
+ 370, -228, 269, // 15
|
|
|
+ 141, 228, -435, // 18
|
|
|
+ -370, 228, -269, // 21
|
|
|
+ -370, 228, 269, // 24
|
|
|
+ 141, 228, 435, // 27
|
|
|
+ 457, 228, 0, // 30
|
|
|
+ 0, 512, 0, // 33
|
|
|
+ -83, -435, -255, // 36
|
|
|
+ 217, -435, -158, // 39
|
|
|
+ 134, -269, -414, // 42
|
|
|
+ 435, -269, 0, // 45
|
|
|
+ 217, -435, 158, // 48
|
|
|
+ -269, -435, 0, // 51
|
|
|
+ -352, -269, -255, // 54
|
|
|
+ -83, -435, 255, // 57
|
|
|
+ -352, -269, 255, // 60
|
|
|
+ 134, -269, 414, // 63
|
|
|
+ 486, 0, -158, // 66
|
|
|
+ 486, 0, 158, // 69
|
|
|
+ 0, 0, -512, // 72
|
|
|
+ 300, 0, -414, // 75
|
|
|
+ -486, 0, -158, // 78
|
|
|
+ -300, 0, -414, // 81
|
|
|
+ -300, 0, 414, // 84
|
|
|
+ -486, 0, 158, // 87
|
|
|
+ 300, 0, 414, // 90
|
|
|
+ 0, 0, 512, // 93
|
|
|
+ 352, 269, -255, // 96
|
|
|
+ -134, 269, -414, // 99
|
|
|
+ -435, 269, 0, // 102
|
|
|
+ -134, 269, 414, // 105
|
|
|
+ 352, 269, 255, // 108
|
|
|
+ 83, 435, -255, // 111
|
|
|
+ 269, 435, 0, // 114
|
|
|
+ -217, 435, -158, // 117
|
|
|
+ -217, 435, 158, // 120
|
|
|
+ 83, 435, 255 // 123
|
|
|
+}; // sphereVertices
|
|
|
+
|
|
|
+#define SPHERE_TRIANGLE_COUNT 80
|
|
|
+const S3L_Index sphereTriangleIndices[SPHERE_TRIANGLE_COUNT * 3] = {
|
|
|
+ 0, 13, 12, // 0
|
|
|
+ 1, 13, 15, // 3
|
|
|
+ 0, 12, 17, // 6
|
|
|
+ 0, 17, 19, // 9
|
|
|
+ 0, 19, 16, // 12
|
|
|
+ 1, 15, 22, // 15
|
|
|
+ 2, 14, 24, // 18
|
|
|
+ 3, 18, 26, // 21
|
|
|
+ 4, 20, 28, // 24
|
|
|
+ 5, 21, 30, // 27
|
|
|
+ 1, 22, 25, // 30
|
|
|
+ 2, 24, 27, // 33
|
|
|
+ 3, 26, 29, // 36
|
|
|
+ 4, 28, 31, // 39
|
|
|
+ 5, 30, 23, // 42
|
|
|
+ 6, 32, 37, // 45
|
|
|
+ 7, 33, 39, // 48
|
|
|
+ 8, 34, 40, // 51
|
|
|
+ 9, 35, 41, // 54
|
|
|
+ 10, 36, 38, // 57
|
|
|
+ 38, 41, 11, // 60
|
|
|
+ 38, 36, 41, // 63
|
|
|
+ 36, 9, 41, // 66
|
|
|
+ 41, 40, 11, // 69
|
|
|
+ 41, 35, 40, // 72
|
|
|
+ 35, 8, 40, // 75
|
|
|
+ 40, 39, 11, // 78
|
|
|
+ 40, 34, 39, // 81
|
|
|
+ 34, 7, 39, // 84
|
|
|
+ 39, 37, 11, // 87
|
|
|
+ 39, 33, 37, // 90
|
|
|
+ 33, 6, 37, // 93
|
|
|
+ 37, 38, 11, // 96
|
|
|
+ 37, 32, 38, // 99
|
|
|
+ 32, 10, 38, // 102
|
|
|
+ 23, 36, 10, // 105
|
|
|
+ 23, 30, 36, // 108
|
|
|
+ 30, 9, 36, // 111
|
|
|
+ 31, 35, 9, // 114
|
|
|
+ 31, 28, 35, // 117
|
|
|
+ 28, 8, 35, // 120
|
|
|
+ 29, 34, 8, // 123
|
|
|
+ 29, 26, 34, // 126
|
|
|
+ 26, 7, 34, // 129
|
|
|
+ 27, 33, 7, // 132
|
|
|
+ 27, 24, 33, // 135
|
|
|
+ 24, 6, 33, // 138
|
|
|
+ 25, 32, 6, // 141
|
|
|
+ 25, 22, 32, // 144
|
|
|
+ 22, 10, 32, // 147
|
|
|
+ 30, 31, 9, // 150
|
|
|
+ 30, 21, 31, // 153
|
|
|
+ 21, 4, 31, // 156
|
|
|
+ 28, 29, 8, // 159
|
|
|
+ 28, 20, 29, // 162
|
|
|
+ 20, 3, 29, // 165
|
|
|
+ 26, 27, 7, // 168
|
|
|
+ 26, 18, 27, // 171
|
|
|
+ 18, 2, 27, // 174
|
|
|
+ 24, 25, 6, // 177
|
|
|
+ 24, 14, 25, // 180
|
|
|
+ 14, 1, 25, // 183
|
|
|
+ 22, 23, 10, // 186
|
|
|
+ 22, 15, 23, // 189
|
|
|
+ 15, 5, 23, // 192
|
|
|
+ 16, 21, 5, // 195
|
|
|
+ 16, 19, 21, // 198
|
|
|
+ 19, 4, 21, // 201
|
|
|
+ 19, 20, 4, // 204
|
|
|
+ 19, 17, 20, // 207
|
|
|
+ 17, 3, 20, // 210
|
|
|
+ 17, 18, 3, // 213
|
|
|
+ 17, 12, 18, // 216
|
|
|
+ 12, 2, 18, // 219
|
|
|
+ 15, 16, 5, // 222
|
|
|
+ 15, 13, 16, // 225
|
|
|
+ 13, 0, 16, // 228
|
|
|
+ 12, 14, 2, // 231
|
|
|
+ 12, 13, 14, // 234
|
|
|
+ 13, 1, 14 // 237
|
|
|
+}; // sphereTriangleIndices
|
|
|
+
|
|
|
int main()
|
|
|
{
|
|
|
SDL_Window *window = SDL_CreateWindow("test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, S3L_RESOLUTION_X, S3L_RESOLUTION_Y, SDL_WINDOW_SHOWN);
|
|
|
@@ -34,71 +164,58 @@ int main()
|
|
|
|
|
|
int running = 1;
|
|
|
|
|
|
- S3L_Model3D cubeModel;
|
|
|
-
|
|
|
- S3L_initModel3D(cubeVertices,S3L_CUBE_VERTEX_COUNT,cubeTriangles,S3L_CUBE_TRIANGLE_COUNT,&cubeModel);
|
|
|
-
|
|
|
-
|
|
|
- S3L_Scene scene;
|
|
|
-
|
|
|
- S3L_initScene(&cubeModel,1,&scene);
|
|
|
-
|
|
|
- scene.camera.transform.translation.z = -3 * S3L_FRACTIONS_PER_UNIT;
|
|
|
-
|
|
|
-
|
|
|
-TPE_Body body;
|
|
|
-
|
|
|
-TPE_bodyInit(&body);
|
|
|
+ #define MODELS 2
|
|
|
|
|
|
-S3L_Mat4 m;
|
|
|
-cubeModel.customTransformMatrix = &m;
|
|
|
+ S3L_Model3D models[MODELS];
|
|
|
|
|
|
+ S3L_initModel3D(sphereVertices,SPHERE_VERTEX_COUNT,sphereTriangleIndices,SPHERE_TRIANGLE_COUNT,&(models[0]));
|
|
|
|
|
|
+ models[1] = models[0];
|
|
|
|
|
|
-TPE_Vec4 p, v;
|
|
|
+ S3L_Scene scene;
|
|
|
|
|
|
-TPE_vec4Set(&p,512,512,0,0);
|
|
|
-TPE_vec4Set(&v,30,0,0,0);
|
|
|
+ S3L_initScene(models,MODELS,&scene);
|
|
|
+
|
|
|
+ scene.camera.transform.translation.z = -4 * S3L_FRACTIONS_PER_UNIT;
|
|
|
+
|
|
|
+ S3L_Mat4 m1, m2;
|
|
|
+
|
|
|
+ models[0].customTransformMatrix = &m1;
|
|
|
+ models[1].customTransformMatrix = &m2;
|
|
|
|
|
|
+ //----------------------------------
|
|
|
|
|
|
+ TPE_Body sphere1, sphere2;
|
|
|
|
|
|
-//TPE_vec4Set(&p,0,512,0,0);
|
|
|
-//TPE_bodySetRotation(&body,p,10);
|
|
|
+ TPE_bodyInit(&sphere1);
|
|
|
+ TPE_bodyInit(&sphere2);
|
|
|
|
|
|
-//TPE_vec4Set(&p,512,0,0,0);
|
|
|
-//TPE_bodyAddRotation(&body,p,20);
|
|
|
+ sphere1.shape = TPE_SHAPE_SPHERE;
|
|
|
+ sphere1.shapeParams[0] = 512;
|
|
|
+ sphere1.position.x = -800;
|
|
|
|
|
|
-TPE_bodyApplyVelocity(&body,p,v);
|
|
|
+ sphere2.shape = TPE_SHAPE_SPHERE;
|
|
|
+ sphere2.shapeParams[0] = 512;
|
|
|
+ sphere2.position.x = 800;
|
|
|
|
|
|
-//TPE_bodySetRotation(&body,axis,5);
|
|
|
-
|
|
|
TPE_Unit frame = 0;
|
|
|
|
|
|
+sphere1.velocity.x = 3;
|
|
|
+sphere2.velocity.x = -3;
|
|
|
+
|
|
|
while (running)
|
|
|
{
|
|
|
+ TPE_bodyGetTransformMatrix(&sphere1,m1);
|
|
|
+ TPE_bodyGetTransformMatrix(&sphere2,m2);
|
|
|
|
|
|
-/*
|
|
|
-TPE_PRINTF_VEC4(body.rotation.originalOrientation);
|
|
|
-TPE_PRINTF_VEC4(body.rotation.axisVelocity);
|
|
|
-printf("%d\n",body.rotation.currentAngle);
|
|
|
-*/
|
|
|
-
|
|
|
-TPE_bodyGetTransformMatrix(&body,m);
|
|
|
-TPE_bodyStep(&body);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-//S3L_logMat4(m);
|
|
|
+ TPE_bodyStep(&sphere1);
|
|
|
+ TPE_bodyStep(&sphere2);
|
|
|
|
|
|
-/*
|
|
|
-S3L_makeRotationMatrixZXY(128,0,0,&m);
|
|
|
+TPE_Vec4 p, n;
|
|
|
|
|
|
-S3L_logMat4(m);
|
|
|
+if (TPE_bodyCollides(&sphere1,&sphere2,&p,&n))
|
|
|
+ printf("aaa\n");
|
|
|
|
|
|
-break;
|
|
|
-*/
|
|
|
for (uint32_t i = 0; i < PIXELS_SIZE; ++i)
|
|
|
pixels[i] = 0;
|
|
|
|