craksy
Member
|
hit detection 2D/3D
hey
is it possible to do hit detection on mixed 2D and 3D objects?
the thing is that i made a simple drag select/box select/whatever (what are those things called anyway?), like for a simple RTS or something.
its working fine except ... i dont know how to make hit detection on 3D objects with it :/
how exactly would i do this?
thanks
-Craksy
|
|
10-14-2009 07:59 PM |
|
craksy
Member
|
Re: hit detection 2D/3D
yeah exactly
what is those called anyway?
and thanks
i hope you will be able to help me out xD
|
|
10-15-2009 09:16 AM |
|
craksy
Member
|
Re: hit detection 2D/3D
awesome
thanks m8 xD
|
|
10-15-2009 09:55 AM |
|
Esenthel
Administrator
|
Re: hit detection 2D/3D
these functions will help you (from Camera.h)
Code:
Vec2 PosToScreen (Vec &pos ); // convert 3D position to 2D screen position
Vec2 PosToScreenM(Vec &pos ); // convert 3D position to 2D screen position (transformed by current object matrix)
Bool PosToScreen (Vec &pos,Vec2 &screen); // convert 3D position to 2D screen position , false on fail (point is behind the camera)
Bool PosToScreenM(Vec &pos,Vec2 &screen); // convert 3D position to 2D screen position (transformed by current object matrix), false on fail (point is behind the camera)
|
|
10-15-2009 11:59 AM |
|
craksy
Member
|
Re: hit detection 2D/3D
yeah i thought about that after looking at the "hit detection under mouse" (or something like that) tutorial.
but exactly what am i supposed to do?
ray testing only hit tests a point right? im looking more for a kinda areal hit detection i guess?
hmm... anyway i like to figure out things myself, instead of just copying others code, so if you could just give me a push in the right direction it would be great
thanks in advance
|
|
10-15-2009 12:24 PM |
|
craksy
Member
|
RE: hit detection 2D/3D
anyone? :/ please...
i know i ask stupid questions a lot, but i really want to understand this.
help would be appreciated
|
|
10-15-2009 09:06 PM |
|
Esenthel
Administrator
|
RE: hit detection 2D/3D
try using the functions I have posted above, first convert a position to onscreen 2D position, then you can check if it cuts a custom 2D Rectangle
|
|
10-15-2009 09:39 PM |
|
craksy
Member
|
RE: hit detection 2D/3D
you mean converting the characters position to screen 2D pos, and checking with the rect?
but i couldnt fint anything to hit detect Rect :S
only Ball, box, and capsule, and stuff like that...
|
|
10-15-2009 09:58 PM |
|
craksy
Member
|
RE: hit detection 2D/3D
basically i wanna know what function can be used to do collision detection on a 2 dimensional area...
so far iv'e only seen Cuts() which only works with balls, boxes, capsules and other shaped, and Ray() which tests in a straight line... i cant think of anyway to use them with a square :/
|
|
10-16-2009 04:57 PM |
|
Esenthel
Administrator
|
RE: hit detection 2D/3D
there is also Cuts for Rect, check Rectangle.h header file
|
|
10-16-2009 06:05 PM |
|
craksy
Member
|
RE: hit detection 2D/3D
oh... i only looked at the physics.h as i assumed all collision detection would be there :/
im sorry for wasting your time :/
but thanks a lot
|
|
10-16-2009 06:17 PM |
|
craksy
Member
|
RE: hit detection 2D/3D
Thanks a lot for your help
i figured it out, and it.... almost works
here's some of the code, of my Update() function:
Code:
if(Ms.b(0)){
if(!MouseP.any()) MouseP = Ms.pos;
rectangle.set(MouseP, Ms.pos);
REPA(Chrs){
Vec2 chrPos = PosToScreen(Chrs[i].pos());
hit = (Cuts(chrPos, rectangle) ? true : false);
}
}
else{
MouseP.zero();
rectangle.zero(); //i only used zero() because i couldn't figure out how to make it null
}
in my draw function i just have:
Code:
rectangle.draw(BLUE, false);
D.text(0, -.8, ((hit) ? "Yay it hit :D" : "no hit"));
anyway as said: it almost works.
it only returns true if i drag from bottom left of character and up/right.
if i drag from fx. top right of character and drag down/left nothing happens :S
why is that?
hope you can help me out
-Craksy
|
|
10-16-2009 07:46 PM |
|
Esenthel
Administrator
|
RE: hit detection 2D/3D
you're using
Rect& set (Vec2 &min,Vec2 &max)
which assumes that you specify first the 'min' values, and then 'max' values
in your case you should use
Rect& from (Vec2 &a,Vec2 &b); // create from 2 points
|
|
10-16-2009 08:37 PM |
|