diff --git a/src/O3DGlideRenderer.h b/src/O3DGlideRenderer.h index b4cca56..3afd97d 100644 --- a/src/O3DGlideRenderer.h +++ b/src/O3DGlideRenderer.h @@ -28,6 +28,7 @@ OF_ASSUME_NONNULL_BEGIN #endif OFSize _clippingWindow; bool _syncsToVerticalBlank; + OFMatrix4x4 *_matrix; } @end diff --git a/src/O3DGlideRenderer.m b/src/O3DGlideRenderer.m index 80788ac..b834af1 100644 --- a/src/O3DGlideRenderer.m +++ b/src/O3DGlideRenderer.m @@ -179,6 +179,18 @@ grGlideShutdownCdecl(void) grDepthBufferMode(GR_DEPTHBUFFER_WBUFFER); grDepthBufferFunction(GR_CMP_LESS); grDepthMask(FXTRUE); + + void *pool = objc_autoreleasePoolPush(); + _matrix = [[OFMatrix4x4 identityMatrix] retain]; + /* Move the range from (-1, 1) to (0, 2) */ + [_matrix translateWithVector: OFMakeVector3D(1, 1, 0)]; + /* + * Scale with half the resolution (since the range is (0, 2) + * and not (0, 1)). + */ + [_matrix scaleWithVector: OFMakeVector3D( + grSstScreenWidth() / 2.f, grSstScreenHeight() / 2.f, 1)]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; @@ -189,6 +201,8 @@ grGlideShutdownCdecl(void) - (void)dealloc { + [_matrix release]; + grSstWinClose(); #ifdef OF_WINDOWS @@ -206,22 +220,16 @@ grGlideShutdownCdecl(void) - (void)drawPolygonWithVertices: (const O3DVertex *)vertices count: (size_t)count { - /* - * Range is -1 to 1, we add 1, so we get 0 to 2 - so we need to - * multiply with half the width / height. - */ - float halfWidth = grSstScreenWidth() / 2; - float halfHeight = grSstScreenHeight() / 2; - GrVertex *glideVertices = OFAllocZeroedMemory(count, sizeof(GrVertex)); @try { for (size_t i = 0; i < count; i++) { - glideVertices[i].x = - (vertices[i].position.x + 1) * halfWidth; - glideVertices[i].y = - (vertices[i].position.y + 1) * halfHeight; + 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].oow = 1.f / - (vertices[i].position.z * GR_WDEPTHVALUE_FARTHEST); + (vec.z * GR_WDEPTHVALUE_FARTHEST); glideVertices[i].r = vertices[i].color.r * 255; glideVertices[i].g = vertices[i].color.g * 255; glideVertices[i].b = vertices[i].color.b * 255; diff --git a/src/O3DRenderer.h b/src/O3DRenderer.h index 48ab208..b10d199 100644 --- a/src/O3DRenderer.h +++ b/src/O3DRenderer.h @@ -18,9 +18,7 @@ OF_ASSUME_NONNULL_BEGIN typedef struct OF_BOXABLE { - struct { - float x, y, z; - } position; + OFVector3D position; struct { float r, g, b; } color;