instantreality forum
news: Welcome to the instantreality forums!
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
January 17, 2018, 02:30:50 am


Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Strange behavior of CollectionCollisionSensor node.  (Read 2131 times)
soedenitel
Newbie
*
Posts: 9


View Profile
« on: August 02, 2011, 08:22:37 am »

My purpose is to detect collisions between moving objects. In the example below a small ball is flying to the wall. The ball should be stopped at the moment of touching the wall. If the ball is located in the middle of the wall (wall translation is 2 0 0) it is all right (collision is detected).
Code:
#VRML V2.0 utf8

DEF BULLET_HOLDER Transform {
rotation -2 0 1 -1.5
children DEF BULLET Shape {
geometry Sphere {
radius 0.1
}
appearance Appearance {
material Material{
diffuseColor 1 0 0
}
}
}
}


DEF SHIELD_HOLDER Transform {
translation 2 0 0
children [
DEF SHIELD Shape {
geometry Box{
size .1 2 2
}
appearance Appearance {
material Material {
diffuseColor 1.0 1.0 0
}
}
}
DEF SHIELD_SENSOR TouchSensor {}
]
}

DEF COLLISION_SENSOR CollectionCollisionSensor {
collideLinks [
USE BULLET_HOLDER,
USE SHIELD_HOLDER
]
}

DEF TIMER TimeSensor {
enabled TRUE
loop TRUE
cycleInterval .01
}


DEF COLLISION_SCRIPT Script{
eventIn SFNode object1
eventIn SFNode object2
eventIn SFBool setCollide
eventIn SFTime tact

eventOut SFString obj1
eventOut SFString obj2
eventOut SFColor color
eventOut SFBool collide
eventOut SFBool timerEnabled

field SFNode bullet USE BULLET_HOLDER
field SFVec3f bulletOffset .01 0 0
field SFNode shield USE SHIELD_HOLDER
field SFFloat shieldRotationAngle 0.005


url "vrmlscript:
function setCollide( value ){
collide = value;
timerEnabled = !value;
print( 'COLLISION_SCRIPT\tcollide = ' + value );
}

function object1( value ){
if( value != null)
print( 'COLLISION_SCRIPT\tOMG1\t' + value );
}

function object2( value ){
if( value != null)
print( 'COLLISION_SCRIPT\tOMG2\t' + value );
}

function tact() {
bullet.translation = bullet.translation.add( bulletOffset );
//shield.rotation.angle += shieldRotationAngle;
}
"
}

ROUTE COLLISION_SENSOR.object1 TO COLLISION_SCRIPT.object1
ROUTE COLLISION_SENSOR.object2 TO COLLISION_SCRIPT.object2
ROUTE COLLISION_SENSOR.collide TO COLLISION_SCRIPT.setCollide
ROUTE TIMER.cycleTime TO COLLISION_SCRIPT.tact
ROUTE COLLISION_SCRIPT.timerEnabled TO TIMER.enabled

If we will change disposition to the next (wall is lifted on 0.5 meter)
Code:
DEF SHIELD_HOLDER Transform {
translation 2 0.5 0
in this case collision is not detected Sad Why is it so?

If the wall will be lifted up on additional 0.5 meter the collision could be detected again.  Shocked

Code:
DEF SHIELD_HOLDER Transform {
translation 2 1 0
Why are collisions not detectable if the value of 'y' translation of the wall is between 0 and 1?
« Last Edit: August 02, 2011, 08:35:08 am by soedenitel » Logged
soedenitel
Newbie
*
Posts: 9


View Profile
« Reply #1 on: August 02, 2011, 10:20:21 am »

Decision in a value of the 'resolution' field.
Code:
DEF SHIELD_HOLDER Transform {
rotation 1 1 0 0
translation 3 .5 .25
children [
DEF SHIELD Shape {
geometry Box{
size .1 2 2
resolution 10
}
appearance Appearance {
material Material {
diffuseColor 1.0 1.0 0
}
}
}
]
}
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.15 | SMF © 2011, Simple Machines