From 6fbc6d0c1c1e08a98e9ed94c007be8aad48916c2 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sun, 19 Feb 2023 22:28:31 +0000 Subject: [PATCH] Add 3D projection FossilOrigin-Name: b55b31d1bbac4d060b641f5c9bc0407cc4f5f11ef64d5c4f28b80d6934fe318f --- src/O3DGlideRenderer.m | 16 ++++++++++------ tests/TestsAppDelegate.m | 8 ++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/O3DGlideRenderer.m b/src/O3DGlideRenderer.m index b834af1..78cae08 100644 --- a/src/O3DGlideRenderer.m +++ b/src/O3DGlideRenderer.m @@ -177,11 +177,16 @@ grGlideShutdownCdecl(void) exceptionWithClass: self.class]; grDepthBufferMode(GR_DEPTHBUFFER_WBUFFER); - grDepthBufferFunction(GR_CMP_LESS); + grDepthBufferFunction(GR_CMP_LEQUAL); grDepthMask(FXTRUE); - void *pool = objc_autoreleasePoolPush(); - _matrix = [[OFMatrix4x4 identityMatrix] retain]; + _matrix = [[OFMatrix4x4 alloc] initWithValues: + (const float [4][4]){ + { 1, 0, 0, 0 }, + { 0, 1, 0, 0 }, + { 0, 0, 1, 0 }, + { 0, 0, 1, 1 } + }]; /* Move the range from (-1, 1) to (0, 2) */ [_matrix translateWithVector: OFMakeVector3D(1, 1, 0)]; /* @@ -190,7 +195,6 @@ grGlideShutdownCdecl(void) */ [_matrix scaleWithVector: OFMakeVector3D( grSstScreenWidth() / 2.f, grSstScreenHeight() / 2.f, 1)]; - objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; @@ -226,8 +230,8 @@ grGlideShutdownCdecl(void) OFVector4D vec = [_matrix transformedVector: OFMakeVector4D(vertices[i].position.x, vertices[i].position.y, vertices[i].position.z, 1)]; - glideVertices[i].x = vec.x; - glideVertices[i].y = vec.y; + glideVertices[i].x = vec.x / vec.w; + glideVertices[i].y = vec.y / vec.w; glideVertices[i].oow = 1.f / (vec.z * GR_WDEPTHVALUE_FARTHEST); glideVertices[i].r = vertices[i].color.r * 255; diff --git a/tests/TestsAppDelegate.m b/tests/TestsAppDelegate.m index af40031..ac6e199 100644 --- a/tests/TestsAppDelegate.m +++ b/tests/TestsAppDelegate.m @@ -32,9 +32,9 @@ OF_APPLICATION_DELEGATE(TestsAppDelegate) options: nil] autorelease]; const O3DVertex outerTriangle[] = { - {{ -1, -1, 1 }, { 1, 0, 0 }}, - {{ 0, 1, 1 }, { 0, 1, 0 }}, - {{ 1, -1, 1 }, { 0, 0, 1 }} + {{ -1, -1, 0 }, { 1, 0, 0 }}, + {{ 0, 1, 0 }, { 0, 1, 0 }}, + {{ 1, -1, 0 }, { 0, 0, 1 }} }; const O3DVertex innerTriangle[] = { {{ -0.5, 0.5, 0 }, { 1, 1, 0 }}, @@ -45,8 +45,8 @@ OF_APPLICATION_DELEGATE(TestsAppDelegate) OFDate *startDate = [OFDate date]; while (-startDate.timeIntervalSinceNow < 5) { [renderer beginFrame]; - [renderer drawPolygonWithVertices: innerTriangle count: 3]; [renderer drawPolygonWithVertices: outerTriangle count: 3]; + [renderer drawPolygonWithVertices: innerTriangle count: 3]; [renderer endFrame]; }