Author Topic: question?why checkForCollision worked only single side?  (Read 1899 times)

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
question?why checkForCollision worked only single side?
« on: September 01, 2014, 06:46:31 am »
SOLVED THX EGO

1.
             │
         →→ │→→→→→→→→Passed
            │
The checkforcollision is not worked,pass through the plane   



2.                   

                 │
stoped       │←←←←
                  │
The checkforcollision worked,everyththing is work.



what is wrong,anyone can tell me how to solved it,thanks.             
« Last Edit: October 20, 2014, 02:55:17 pm by Uncle Ray »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: question?why checkForCollision worked only single side?
« Reply #1 on: September 01, 2014, 07:40:47 am »
The collision detection methods don't work on back faces. If you need this behaviour, you have to use separate objects (one normal, one inverted) at least during the collision detection stage (you might want to set the inverted object to invisible in the render stage).

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: question?why checkForCollision worked only single side?
« Reply #2 on: September 01, 2014, 08:20:01 am »
but when object set invisible,all collision method will never work.
because all the collision_detect  without calmindistance(the only which can detect invisible object)
can not detect invisible object.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: question?why checkForCollision worked only single side?
« Reply #3 on: September 01, 2014, 08:34:34 am »
It doesn't matter if it's visible during rendering or not. It only matters what's visible when doing the collision detection. So you can add "collision objects" to the world that won't be rendered but used for collision detection only by altering their visibility between the two operations.

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: question?why checkForCollision worked only single side?
« Reply #4 on: September 02, 2014, 04:40:07 am »
sorry,i am not clear got it.how to add "collision objects" to the world that won't be rendered ?


Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: question?why checkForCollision worked only single side?
« Reply #5 on: September 02, 2014, 04:44:03 am »
is that createDummyObj?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: question?why checkForCollision worked only single side?
« Reply #6 on: September 02, 2014, 09:19:31 am »
No, there are just regular objects. In your case, it would be a copy of your plane that is inverted. For example by calling invert(). It sits in the same location as the normal plane. In your case, you might not even have to deal with visibility because it might be feasible to let the plane visible all the time. But that depends on your scene. What are you using that plane for and has culling been disabled on it?

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: question?why checkForCollision worked only single side?
« Reply #7 on: September 02, 2014, 09:37:18 am »
In my scene,i creat a car racing game,this plane is used for fense,i want it to be invsible,and keep the collition-detect,let the car runing in the track rightly.
how to make a invisble object ues the collide_detect(i know the calmindistance is ok,but others....)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: question?why checkForCollision worked only single side?
« Reply #8 on: September 02, 2014, 11:16:51 am »
If it's a fence, just build it in a way that it is two sided and you don't have to deal with visibility at all. You can't detect collisions on invisible objects...i guess, i'm still not clear enough on what i mean. It's basically this: You render one set of objects and you detect collisions on another one. There's no magic method that deals with this, you have to do this in your own code. I usually do it this way:

  • Create the renderable object (based on your own class like MyObject3D...more on that later)
  • Create the collision object
  • Make the collision mesh a child object of the renderable object
  • At a method to MyObject3D that toggles the states, like setCollisionMode(<boolean>);
  • If you set it to true, collision mesh will be visible. If set to false, renderable mesh will be visible.
  • Call setCollisionMode(false) on the object and do the rendering
  • Call setCollisionMode(true) on the object and do the collision detections

However, i don't think that this will be needed in your case. Just make a two sided model out of your fence (i.e. visible from both sides) and you are good to go.

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: question?why checkForCollision worked only single side?
« Reply #9 on: September 02, 2014, 04:45:55 pm »
I know your means,two objects set in the same place but  opposite backface(which is depended on opengl rendering clockwise or counterclockwise)

Here is my question
1.collide two sides?
your suggestion is right,the problem is solved.Thx,ego.

2.invisible object collide?
you said in jpct collide with invisible object was impossible.

Here is my idea:
could i bounding a texture which is transparent with the object.
Although the object setvisible(true),but it's texture is transparent,in fact we can't see the object.   

Is this the best method for the invisible object collide detect?
or,if there is better method,could your tell me how,
 i dont want the detailed code,just the thought.

At last,thank ego again.for your huge help with me.
 

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: question?why checkForCollision worked only single side?
« Reply #10 on: September 02, 2014, 07:25:04 pm »
I found the second solution,if i want the "A" invisible and collideable,here is the code:

{
Object3D A;
A.setTransparency(0);
Config.glTransparencyOffset=0;
}

it's perfect,invisible,and all the collide method are worked.
last question,is there a better solution for invisible and colideable?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: question?why checkForCollision worked only single side?
« Reply #11 on: September 03, 2014, 09:22:45 am »
You could do that, but it causes additional overhead when rendering the scene. It might not be noticable though.

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: question?why checkForCollision worked only single side?
« Reply #12 on: September 03, 2014, 11:14:50 am »
Thx,is there a better solution for invisible collide?


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: question?why checkForCollision worked only single side?
« Reply #13 on: September 03, 2014, 12:09:56 pm »
Yes...just what i said multiple times before: Alter the visibility between rendering and collision detection. In your case, set the transparent plane to invisible during rendering and you'll save the additional render cycles for processing it.