diff options
| author | John Wilbert M. Villamor <lameguy64@gmail.com> | 2020-04-24 19:01:28 +0800 |
|---|---|---|
| committer | John Wilbert M. Villamor <lameguy64@gmail.com> | 2020-04-24 19:01:28 +0800 |
| commit | 1aa0e17df7c325a41de8cf8a57f52ed853f08bf3 (patch) | |
| tree | 5ec7f69ca0104f2b0a41e2ee7d3cb0cf0c9c54c5 /examples/graphics/fpscam/lookat.c | |
| parent | e82da2abe4c264d4b48a48d79cf9b8e4c4fb8ab6 (diff) | |
| download | psn00bsdk-1aa0e17df7c325a41de8cf8a57f52ed853f08bf3.tar.gz | |
Refined toolchain instructions, organized examples, added automatic retry for CdRead(), added FIOCSCAN ioctl in psxsio TTY driver, added tty and console examples.
Diffstat (limited to 'examples/graphics/fpscam/lookat.c')
| -rw-r--r-- | examples/graphics/fpscam/lookat.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/graphics/fpscam/lookat.c b/examples/graphics/fpscam/lookat.c new file mode 100644 index 0000000..d7c9ce4 --- /dev/null +++ b/examples/graphics/fpscam/lookat.c @@ -0,0 +1,40 @@ +// LookAt matrix code (may be implemented into libpsxgte soon) + +#include "lookat.h" + +void crossProduct(SVECTOR *v0, SVECTOR *v1, VECTOR *out) { + + out->vx = ((v0->vy*v1->vz)-(v0->vz*v1->vy))>>12; + out->vy = ((v0->vz*v1->vx)-(v0->vx*v1->vz))>>12; + out->vz = ((v0->vx*v1->vy)-(v0->vy*v1->vx))>>12; + +} + +void LookAt(VECTOR *eye, VECTOR *at, SVECTOR *up, MATRIX *mtx) { + + VECTOR taxis; + SVECTOR zaxis; + SVECTOR xaxis; + SVECTOR yaxis; + VECTOR pos; + VECTOR vec; + + setVector(&taxis, at->vx-eye->vx, at->vy-eye->vy, at->vz-eye->vz); + VectorNormalS(&taxis, &zaxis); + crossProduct(&zaxis, up, &taxis); + VectorNormalS(&taxis, &xaxis); + crossProduct(&zaxis, &xaxis, &taxis); + VectorNormalS(&taxis, &yaxis); + + mtx->m[0][0] = xaxis.vx; mtx->m[1][0] = yaxis.vx; mtx->m[2][0] = zaxis.vx; + mtx->m[0][1] = xaxis.vy; mtx->m[1][1] = yaxis.vy; mtx->m[2][1] = zaxis.vy; + mtx->m[0][2] = xaxis.vz; mtx->m[1][2] = yaxis.vz; mtx->m[2][2] = zaxis.vz; + + pos.vx = -eye->vx;; + pos.vy = -eye->vy;; + pos.vz = -eye->vz;; + + ApplyMatrixLV(mtx, &pos, &vec); + TransMatrix(mtx, &vec); + +}
\ No newline at end of file |
