Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (804) Games in Android Showcase (239) games submitted by our members Games in WIP (868) 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 3246 times) 0 Members and 1 Guest are viewing this topic.
KaiHH

JGO Kernel

Medals: 796

 « 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: 564
Projects: 8
Exp: 8 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

 Riven (578 views) 2019-09-04 15:33:17 hadezbladez (5495 views) 2018-11-16 13:46:03 hadezbladez (2398 views) 2018-11-16 13:41:33 hadezbladez (5756 views) 2018-11-16 13:35:35 hadezbladez (1219 views) 2018-11-16 13:32:03 EgonOlsen (4659 views) 2018-06-10 19:43:48 EgonOlsen (5667 views) 2018-06-10 19:43:44 EgonOlsen (3193 views) 2018-06-10 19:43:20 DesertCoockie (4093 views) 2018-05-13 18:23:11 nelsongames (5104 views) 2018-04-24 18:15:36
 princec 10x Ali-RS 6x philfrei 5x VaTTeRGeR 5x KaiHH 5x mudlee 5x elect 4x Rain8 3x SteveSmith 2x hansolo_ 2x Apo 1x JaredBGreat 1x ral0r2 1x SugarBlood 1x saocrinn 1x Abuse 1x
 A NON-ideal modular configuration for Eclipse with JavaFXby philfrei2019-12-19 19:35:12Java Gaming Resourcesby philfrei2019-05-14 16:15:13Deployment and Packagingby philfrei2019-05-08 15:15:36Deployment and Packagingby philfrei2019-05-08 15:13:34Deployment and Packagingby philfrei2019-02-17 20:25:53Deployment and Packagingby mudlee2018-08-22 18:09:50Java Gaming Resourcesby gouessej2018-08-22 08:19:41Deployment and Packagingby gouessej2018-08-22 08:04:08
 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