Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (686) Games in Android Showcase (198) games submitted by our members Games in WIP (758) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Geting XYZ of a point along a line (vector)  (Read 896 times) 0 Members and 1 Guest are viewing this topic.
pixelprime

Junior Devvie

Medals: 3

 « Posted 2013-03-31 11:50:59 »

I know this may seem like a dumb question, but I'm having some odd problems when trying to calculate the position of a point in space along a vector.

My objective is to grab the XYZ coordinates of a point in space directly in front of the camera with a set distance.

I know the pitch, roll and yaw angles of the camera already, and my existing calculation looks like the following (angles in this example are originally stored as degrees, then converted into radians):

The problem I have is that the new point - which does project in front of the camera as intended - doesn't seem to work along the Y axis correctly. It 'clamps' between the angles of -45° to +45°.

So, rotating the camera around the Y axis (yawing) seems to work great - the point 'fires' off from the camera in the right direction - but the plotting of the point in around the camera's pitch arc is out of whack!

For reference, this code is intended to be used as a line-of-sight calculation for detecting what the player is looking at.

Any help would be greatly appreciated. Thank you!
quew8

JGO Knight

Medals: 51

 « Reply #1 - Posted 2013-03-31 13:56:56 »

Your problem is that you've forgotten that pitch effects x, y and z values. It's very hard to explain without a diagram so I'm afraid I'm not even going to try.
Anyway here is the code I think you want:

The important bit is the times f. The rest is just me absent mindedly changing code.
Please do bear in mind that I have to draw this out at least 3 times every time I try to solve the problem and I still get it wrong sometimes.
pixelprime

Junior Devvie

Medals: 3

 « Reply #2 - Posted 2013-04-01 14:21:55 »

Thanks for taking the time to post an example. Yes, it appears I've missed this somewhat obvious factor here, so I'll give your modifications a try and report my findings back here.

Thanks again!
pixelprime

Junior Devvie

Medals: 3

 « Reply #3 - Posted 2013-04-01 19:58:10 »

I just wanted to drop a final post on to say that the code worked a treat - thank you very much!

I modified my original XYZ projection code with the coefficient cosine / sine angles and everything now behaves as expected, thanks a bundle!
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 roseslayer (424 views) 2016-08-06 11:43:29 roseslayer (384 views) 2016-08-06 09:43:11 xTheGamerCodes (461 views) 2016-08-04 15:40:59 xTheGamerCodes (455 views) 2016-08-04 15:40:24 orrenravid (804 views) 2016-07-16 03:57:23 theagentd (880 views) 2016-07-11 14:28:54 Hydroque (976 views) 2016-07-06 05:56:57 Hydroque (995 views) 2016-07-03 08:52:54 GrandCastle (807 views) 2016-07-01 09:13:47 GrandCastle (638 views) 2016-07-01 09:09:45
 Archive 43x Ecumene 26x Spasi 23x theagentd 21x DarkCart 15x h.pernpeintner 14x gouessej 14x EgonOlsen 13x orange451 12x ags1 11x admin 10x Riven 9x Slyth2727 9x Brynn 8x philjord 8x TheMeatMan 8x
 Rendering resourcesby Roquen2016-08-08 05:55:21Rendering resourcesby Roquen2016-08-08 05:52:42Rendering resourcesby Roquen2016-08-08 05:50:38Rendering resourcesby Roquen2016-08-08 05:49:53Rendering resourcesby Roquen2016-08-08 05:32:39Making a Dynamic Plugin Systemby Hydroque2016-06-25 00:13:25Java Data structures2016-06-13 21:22:09Java Data structures2016-06-13 21:20:42
 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