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]; exceptionWithClass: self.class];
grDepthBufferMode(GR_DEPTHBUFFER_WBUFFER); grDepthBufferMode(GR_DEPTHBUFFER_WBUFFER);
grDepthBufferFunction(GR_CMP_LESS); grDepthBufferFunction(GR_CMP_LEQUAL);
grDepthMask(FXTRUE); grDepthMask(FXTRUE);
void *pool = objc_autoreleasePoolPush(); _matrix = [[OFMatrix4x4 alloc] initWithValues:
_matrix = [[OFMatrix4x4 identityMatrix] retain]; (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) */ /* Move the range from (-1, 1) to (0, 2) */
[_matrix translateWithVector: OFMakeVector3D(1, 1, 0)]; [_matrix translateWithVector: OFMakeVector3D(1, 1, 0)];
/* /*
@ -190,7 +195,6 @@ grGlideShutdownCdecl(void)
*/ */
[_matrix scaleWithVector: OFMakeVector3D( [_matrix scaleWithVector: OFMakeVector3D(
grSstScreenWidth() / 2.f, grSstScreenHeight() / 2.f, 1)]; grSstScreenWidth() / 2.f, grSstScreenHeight() / 2.f, 1)];
objc_autoreleasePoolPop(pool);
} @catch (id e) { } @catch (id e) {
[self release]; [self release];
@throw e; @throw e;
@ -226,8 +230,8 @@ grGlideShutdownCdecl(void)
OFVector4D vec = [_matrix transformedVector: OFVector4D vec = [_matrix transformedVector:
OFMakeVector4D(vertices[i].position.x, OFMakeVector4D(vertices[i].position.x,
vertices[i].position.y, vertices[i].position.z, 1)]; vertices[i].position.y, vertices[i].position.z, 1)];
glideVertices[i].x = vec.x; glideVertices[i].x = vec.x / vec.w;
glideVertices[i].y = vec.y; glideVertices[i].y = vec.y / vec.w;
glideVertices[i].oow = 1.f / glideVertices[i].oow = 1.f /
(vec.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;

View file

@ -32,9 +32,9 @@ OF_APPLICATION_DELEGATE(TestsAppDelegate)
options: nil] autorelease]; options: nil] autorelease];
const O3DVertex outerTriangle[] = { const O3DVertex outerTriangle[] = {
{{ -1, -1, 1 }, { 1, 0, 0 }}, {{ -1, -1, 0 }, { 1, 0, 0 }},
{{ 0, 1, 1 }, { 0, 1, 0 }}, {{ 0, 1, 0 }, { 0, 1, 0 }},
{{ 1, -1, 1 }, { 0, 0, 1 }} {{ 1, -1, 0 }, { 0, 0, 1 }}
}; };
const O3DVertex innerTriangle[] = { const O3DVertex innerTriangle[] = {
{{ -0.5, 0.5, 0 }, { 1, 1, 0 }}, {{ -0.5, 0.5, 0 }, { 1, 1, 0 }},
@ -45,8 +45,8 @@ OF_APPLICATION_DELEGATE(TestsAppDelegate)
OFDate *startDate = [OFDate date]; OFDate *startDate = [OFDate date];
while (-startDate.timeIntervalSinceNow < 5) { while (-startDate.timeIntervalSinceNow < 5) {
[renderer beginFrame]; [renderer beginFrame];
[renderer drawPolygonWithVertices: innerTriangle count: 3];
[renderer drawPolygonWithVertices: outerTriangle count: 3]; [renderer drawPolygonWithVertices: outerTriangle count: 3];
[renderer drawPolygonWithVertices: innerTriangle count: 3];
[renderer endFrame]; [renderer endFrame];
} }