Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (753) Games in Android Showcase (228) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Compute view/proj matrices for head tracking rendering  (Read 1782 times) 0 Members and 1 Guest are viewing this topic.
KaiHH

JGO Kernel

Medals: 511

 « Posted 2017-06-13 21:09:16 »

Ever wondered how you can compute a view and projection matrix given the eye position and any arbitrarily positioned and oriented near plane rectangle, such as what Johnny Lee did with his WiiRemote virtual reality hack using a simple monitor and the WiiRemote? Or do you own a TrackIR device and don't know what to do with it?
It's pretty simple. Here is how:
 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38 /** * Create a view and projection matrix from a given eye position, a given bottom left corner position p of the near plane rectangle * and the extents of the near plane rectangle along its local x and y axes, and store the resulting matrices * in projDest and viewDest. *

* This method creates a view and perspective projection matrix assuming that there is a pinhole camera at position eye * projecting the scene onto the near plane defined by the rectangle. *

* All positions and lengths are in the same (world) units. *  * @param eye *          the position of the camera * @param p *          the bottom left corner of the near plane rectangle (will map to the bottom left corner in window coordinates) * @param x *          the direction and length of the local "bottom/top" X axis/side of the near plane rectangle * @param y *          the direction and length of the local "left/right" Y axis/side of the near plane rectangle * @param nearFarDist *          the distance between the far and near plane (the near plane will be calculated by this method) * @param projDest *          will hold the resulting projection matrix * @param viewDest *          will hold the resulting view matrix */public static void projViewFromRectangle(Vector3f eye, Vector3f p, Vector3f x, Vector3f y, float nearFarDist, Matrix4f projDest, Matrix4f viewDest) {    float zx = y.y * x.z - y.z * x.y, zy = y.z * x.x - y.x * x.z, zz = y.x * x.y - y.y * x.x;    float zd = zx * (p.x - eye.x) + zy * (p.y - eye.y) + zz * (p.z - eye.z);    float zs = zd >= 0 ? 1 : -1; zx *= zs; zy *= zs; zz *= zs; zd *= zs;     viewDest.setLookAt(eye.x, eye.y, eye.z, eye.x + zx, eye.y + zy, eye.z + zz, y.x, y.y, y.z);    float px = viewDest.m00 * p.x + viewDest.m10 * p.y + viewDest.m20 * p.z + viewDest.m30;    float py = viewDest.m01 * p.x + viewDest.m11 * p.y + viewDest.m21 * p.z + viewDest.m31;    float tx = viewDest.m00 * x.x + viewDest.m10 * x.y + viewDest.m20 * x.z;    float ty = viewDest.m01 * y.x + viewDest.m11 * y.y + viewDest.m21 * y.z;    float len = (float) Math.sqrt(zx * zx + zy * zy + zz * zz);    float near = zd / len;    projDest.setFrustum(px, px + tx, py, py + ty, near, near + nearFarDist);}

This is JOML code, however setLookAt() and setFrustum() are semantically exactly identical to glLoadIdentity() + gluLookAt() and glLoadIdentity() + glFrustum().
orange451

JGO Kernel

Medals: 358
Projects: 6
Exp: 6 years

 « Reply #1 - Posted 2017-06-14 14:23:35 »

Any sick videos to show it off?

First Recon. A java made online first person shooter!
theagentd
 « Reply #2 - Posted 2017-06-14 14:50:50 »

I may have something to show at some point. =P

Myomyomyo.
Pages: [1]
 ignore  |  Print

 ivj94 (583 views) 2018-03-24 14:47:39 ivj94 (48 views) 2018-03-24 14:46:31 ivj94 (382 views) 2018-03-24 14:43:53 Solater (62 views) 2018-03-17 05:04:08 nelsongames (109 views) 2018-03-05 17:56:34 Gornova (159 views) 2018-03-02 22:15:33 buddyBro (702 views) 2018-02-28 16:59:18 buddyBro (92 views) 2018-02-28 16:45:17 xxMrPHDxx (493 views) 2017-12-31 17:17:51 xxMrPHDxx (733 views) 2017-12-31 17:15:51
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org