Add 3D projection

FossilOrigin-Name: b55b31d1bbac4d060b641f5c9bc0407cc4f5f11ef64d5c4f28b80d6934fe318f
This commit is contained in:
Jonathan Schleifer 2023-02-19 22:28:31 +00:00
parent 48bd210714
commit 6fbc6d0c1c
2 changed files with 14 additions and 10 deletions

View file

@ -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;

View file

@ -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];
}