Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Find the top and left edges of a Plane in relation to a collision point

Author
Message
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 31st Jan 2015 19:00 Edited at: 31st Jan 2015 19:00
The idea being that I've raycasted onto a 3d plane and whatever orientation that plane is I can work out a vector at the top and left edges of that plane in relation to point of collision.

Example:


I understand position from centre:


But not an arbitrary point from that centre.

The reason for this is I want to do distance checks from the collision point to the top and left edges.

Any help would be greatly appreciated

"Get in the Van!" - Van B

Attachments

Login to view attachments
Le Verdier
13
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 31st Jan 2015 19:37 Edited at: 31st Jan 2015 19:46
Let o the Top/Left plane point, assuming plane "laid" on X/Z plane:
o = (-PlW/2, 0, PlH/2)

v = ColPoint - o * WorldMat
DistX = v dot WorldMat.XAxis
DistZ = -v dot WorldMat.ZAxis

Do you still work on your editor ???


All hail the new flesh
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 31st Jan 2015 20:02
DistX = v dot WorldMat.XAxis

Would that be: DistX = dot product vector3(v, WorldMat.XAxis)

Cause if so this method isn't working for me.

Quote: "Do you still work on your editor ???"


I stopped for a bit but now I'm starting again

"Get in the Van!" - Van B
Le Verdier
13
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 31st Jan 2015 20:18 Edited at: 31st Jan 2015 20:36
DistX = dot product vector3(v, WorldMat.XAxis)

yes, WorldMat.XAxis is the first line of the matrix..
v is the "colpoint - transformed topleft point "vector


I also recommend the Madbit's plugin, it strongly ease the 3D maths, Extended Rotation

All hail the new flesh
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 31st Jan 2015 22:24 Edited at: 1st Feb 2015 21:22
This should be a very simple case of projecting the collision point onto one of the edge vectors, because the collision point is already on the plane: http://en.wikipedia.org/wiki/Vector_projection



First you need the vertex coordinates v1 and v2. These can either be obtained through vertexdata, or with:


Vector b can be obtained with:
b = (Collision Point) - v1.

Vector a can be obtained with:
a = v2 - v1.

The projected vector b' onto a is:
b' = a * dot(b, a) / (norm(a)^2)

The edge point you're looking for will be:
v1 + b'

The only way to do great work is to love what you do -- Steve Jobs

Attachments

Login to view attachments
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 1st Feb 2015 18:34 Edited at: 1st Feb 2015 18:35
Le Verdier, still can't seem to get this method to work and I like to program the math so I can learn and understand the math that's going on. Once I've got that, if the plugin is more efficient (usually the case) then I switch over to that.

TheComet, I think I understand this... still going through the wiki.

As for your example, based on my math the method only works when the plane is at a 1x1 scale/size. It seems v1 + b' or the result of it scales in multiple sizes bigger than the plane. Any idea what could cause this? And cheers for the help so far



"Get in the Van!" - Van B
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 1st Feb 2015 21:13
Quote: "As for your example, based on my math the method only works when the plane is at a 1x1 scale/size. It seems v1 + b' or the result of it scales in multiple sizes bigger than the plane. Any idea what could cause this?"


Yes. When you scale a DBP object it doesn't actually change size, the transformation is merely added to the world matrix. You're not taking that into account when building your _worldMat matrix. You should be doing:



The only way to do great work is to love what you do -- Steve Jobs
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 1st Feb 2015 21:19 Edited at: 1st Feb 2015 21:22
Sorry for double post but I just realised you interpreted one part of the formula incorrectly.



b' = a * dot(b, a) / (norm(a)^2) - In this formula, norm() doesn't normalize, it returns the length of the vector. You should be using length vector3()^2 rather than normalize vector3() and then squaring each element.

I wrote norm() because that's what Matlab uses.

The only way to do great work is to love what you do -- Steve Jobs
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 1st Feb 2015 21:51 Edited at: 1st Feb 2015 21:51
I shouldn't of used the word scale and specifically said size at creation meaning whatever size I created the plane but that's a good point, scaling will need to be added, thanks for the reminder

Okie dokie, your correction has corrected the code awesome and thanks. I can see how this really works now and what else I could use this for cause at the mo I was only going to use it for surfaces guilds, mesh manipulation and etc...

Also has an alternative use, you can easily find the UV's of the plane by doing and XY distance check, makes interaction with a flat plane simple. Though looking at the code now, I'm thinking there might be other ways to work out UV's specifically on a plain. Since we know how big the object is and where each vert is we don't need to check each triangle. Just need to project a point onto that plane... I think (I will look into this)

Anyway example:


Code needs IanM's Matrix Plugin


"Get in the Van!" - Van B

Attachments

Login to view attachments

Login to post a reply

Server time is: 2025-05-12 12:18:21
Your offset time is: 2025-05-12 12:18:21