playMaker

Author Topic: is a vertex in a certain space? [~SOLVED]  (Read 2795 times)

kiriri

  • Hero Member
  • *****
  • Posts: 506
is a vertex in a certain space? [~SOLVED]
« on: June 06, 2012, 02:08:03 PM »
 So I'm currently working hard on a set of decal functions . So far I've got a projecting mesh one which creates vertices by ray collision , and a project simple plane decal. However, I want a very accurate one which will be able to create multiple split parts of a decal if it hits multiple meshes, and I also need one that will properly work on skinned meshes. I'm close to finishing those too, but there's one hindrance:

So far I've used a lot of playmaker stuff as references, but I couldn't find a way to determine whether a certain vertex (or vector 3 (point)) is within a 3 dimensional cuboid (between 3 vector3 ) .

The reason why I'm asking here first is so that I know whether I should implement it as an action after I found a way. So far I'm considering something like the algebra 3 way I remember from school:
vec0 + s*vec1 + r*vec2 + t*vec3 = VecPoint
if r,s,t less than 1 and greater than 0, the point is in the cuboid, else it is not. (the vectors are not normalized)

I haven't been able to find a way to auto-calculate  r , s and t though.
If this is not possible yet, let me know please, so I can add it as an action :D (Though I'm not quite sure how to :S )
« Last Edit: June 06, 2012, 03:37:56 PM by kiriri »
Best,
Sven

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: is a vertex in a certain space?
« Reply #1 on: June 06, 2012, 03:16:18 PM »
hi,

 I would go for a much simpler approach, using Unity Bound class and api.

http://unity3d.com/support/documentation/ScriptReference/Bounds.Contains.html

You basically create a bound class, and then use the function contains to find out if a point is within this bound.

Knowing this, its then easier to work with, and no math nor vector math involved :)

 If you have problems wrapping this into a custom action, try using the playmaker custom action wizard in the playmaker tool menu, else simply duplicate one of the standard action in the playmaker/action folder to use as a base.

If you still have issues, let me know, I'll make it so that you can see how to approach such custom action.

bye,

 Jean

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: is a vertex in a certain space?
« Reply #2 on: June 06, 2012, 03:22:21 PM »
seriously, that was too simple :D Thanks a lot, I don't think I'll be needing any help to create an action for this ;D
Do you know how expensive this function is? could it be used per frame without any worries?

... now that I thought so hard about it, I wonder how that function is defined... :D
Best,
Sven

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: is a vertex in a certain space?
« Reply #3 on: June 06, 2012, 03:26:55 PM »
oh, I just noticed a problem, how would I be able to construct a bounding box which is not aligned to the axis? Like one that goes diagonally:
width : 1/2/0
length : 2/-1/0
height : 0/0/1
origin : 0/0/0
like that?

If that's not possible then that's not all that bad either, I could always use multiple bounding boxes for each collision, though that's slightly inaccurate... or I could rotate the bounding box to the vector of the ray... (EDIT) which I just found out is not possible... meh, why is stuff always this hard?

EDIT: I'll write my own function, I found a 2D function already, can't be too hard to make it 3D.
« Last Edit: June 06, 2012, 03:55:05 PM by kiriri »
Best,
Sven

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: is a vertex in a certain space? [~SOLVED]
« Reply #4 on: June 07, 2012, 01:23:39 AM »
Hi,

 If your cuboid is not aligned with the world, then I would strongly suggest you simply use a radius for searching. and instead of defining a box to find if a point is within that volume, define a sphere, which is basically just a radius, and define your radius as a power of two so that you simply extract the square magnitude of your point against the center, which is a lot more efficient than getting the magnitude ( because of the squre root operation)

 Bye,

 Jean