A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
kubatp
Gnome
Posts: 354
Joined: Tue Jan 06, 2009 1:12 pm
x 22

Hi,
I create a manual object with quads and I keep the coordinates in memory array. I later need to find out a height (y-coordinate) of the point on this manual object. Manual object is a grid and from the grid I have closest corners (p1, p2, p3 and p4). Somewhere in the quad is a point for which I have x and z coordinate and I need to find y.
Is there an easy way to get it?
Thank you for help

kubatp
Gnome
Posts: 354
Joined: Tue Jan 06, 2009 1:12 pm
x 22

### Re: Finding y-coordinate in Quad

Nobody can help me here? I presumed that many people had similar problems already

Herb
Orc
Posts: 412
Joined: Thu Jun 04, 2009 3:21 am
Location: Kalamazoo,MI
x 38

### Re: Finding y-coordinate in Quad

Yes, I've done something similar. I have a large quad and I needed to get the X,Y on it when I click the mouse on the Ogre::Plane. So, I used the wiki's article on Raycasting to the polygon level to do it. Basically you could tweak it to send a raycast from above (doesn't have to be mouse click based) down on your shape to get an intersection to get the Y value. Basic raycasting doesn't work as it's by bounding box, but this article has sample code to get down to the polygon level which will get you the precision you need.

scrawl
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 214

### Re: Finding y-coordinate in Quad

This is more of a linear algebra question than an Ogre question, I'm sure you could find a better explanation on other sites.
Check which triangle the point is on. Define a plane equation for that triangle using the 3 points notation. Then solve the plane equation using the s and t values that define your target point.

kubatp
Gnome
Posts: 354
Joined: Tue Jan 06, 2009 1:12 pm
x 22

### Re: Finding y-coordinate in Quad

Hi,
Herb wrote:I used the wiki's article on Raycasting to the polygon level to do it
Yes, I considered this option, but I dont really want to do raycasting when I can solve this mathematically.
scrawl wrote:This is more of a linear algebra question
Yes, you are absolutely right. I just wanted to ask if anyone else was already solving this problem and might give me a quick answer. I simply thought that this is something many people solved already before and I didn't want to reinvent the wheel.

c6burns
Beholder
Posts: 1511
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 134

### Re: Finding y-coordinate in Quad

It's not really an Ogre question, but ...

Equation of plane:
Ax + By + Cz + D = 0

Algebra:
By = -Ax - Cz - D
y = (-Ax - Cz - D) / B

A, B, C and D are known because you defined the plane. So ... plug in your known x and z values to find y. If unclear, google it because I am so shit at maths, so if I'm explaining to this to you then you need to do some reading. I remember covering this in high school algebra.

You can see an implementation of this in Terrain::getHeightAtTerrainPosition where it returns: (note: it treats height as z)
(-plane.normal.x * x - plane.normal.y * y - plane.d) / plane.normal.z;

EDIT: Ah you bums posted while I was posting

kubatp
Gnome
Posts: 354
Joined: Tue Jan 06, 2009 1:12 pm
x 22

### Re: Finding y-coordinate in Quad

Hi,
thank you very much for your help, especially pointing to this getHeightAtTerrainPosition. It helped me a lot and solved the problem.