Use OFMatrix4x4

FossilOrigin-Name: a495ea8f0b893fd9625d22b2b5afa8bdbf84b6781e6b21f07bc5669ca364bd41
This commit is contained in:
Jonathan Schleifer 2023-02-19 00:05:22 +00:00
parent b6ceeeb489
commit 48bd210714
3 changed files with 22 additions and 15 deletions

View file

@ -28,6 +28,7 @@ OF_ASSUME_NONNULL_BEGIN
#endif #endif
OFSize _clippingWindow; OFSize _clippingWindow;
bool _syncsToVerticalBlank; bool _syncsToVerticalBlank;
OFMatrix4x4 *_matrix;
} }
@end @end

View file

@ -179,6 +179,18 @@ grGlideShutdownCdecl(void)
grDepthBufferMode(GR_DEPTHBUFFER_WBUFFER); grDepthBufferMode(GR_DEPTHBUFFER_WBUFFER);
grDepthBufferFunction(GR_CMP_LESS); grDepthBufferFunction(GR_CMP_LESS);
grDepthMask(FXTRUE); 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) { } @catch (id e) {
[self release]; [self release];
@throw e; @throw e;
@ -189,6 +201,8 @@ grGlideShutdownCdecl(void)
- (void)dealloc - (void)dealloc
{ {
[_matrix release];
grSstWinClose(); grSstWinClose();
#ifdef OF_WINDOWS #ifdef OF_WINDOWS
@ -206,22 +220,16 @@ grGlideShutdownCdecl(void)
- (void)drawPolygonWithVertices: (const O3DVertex *)vertices - (void)drawPolygonWithVertices: (const O3DVertex *)vertices
count: (size_t)count 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)); GrVertex *glideVertices = OFAllocZeroedMemory(count, sizeof(GrVertex));
@try { @try {
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
glideVertices[i].x = OFVector4D vec = [_matrix transformedVector:
(vertices[i].position.x + 1) * halfWidth; OFMakeVector4D(vertices[i].position.x,
glideVertices[i].y = vertices[i].position.y, vertices[i].position.z, 1)];
(vertices[i].position.y + 1) * halfHeight; glideVertices[i].x = vec.x;
glideVertices[i].y = vec.y;
glideVertices[i].oow = 1.f / 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].r = vertices[i].color.r * 255;
glideVertices[i].g = vertices[i].color.g * 255; glideVertices[i].g = vertices[i].color.g * 255;
glideVertices[i].b = vertices[i].color.b * 255; glideVertices[i].b = vertices[i].color.b * 255;

View file

@ -18,9 +18,7 @@
OF_ASSUME_NONNULL_BEGIN OF_ASSUME_NONNULL_BEGIN
typedef struct OF_BOXABLE { typedef struct OF_BOXABLE {
struct { OFVector3D position;
float x, y, z;
} position;
struct { struct {
float r, g, b; float r, g, b;
} color; } color;