Merge pull request #1029 from katharostech/physics-raycast-normal

Add Hit Normal to Physics Ray Cast Result
This commit is contained in:
Lubos Lenco 2018-12-02 16:44:14 +01:00 committed by GitHub
commit 6454b74378
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View file

@ -27,9 +27,13 @@ class CastPhysicsRayNode extends LogicNode {
if (from == 0) { // Object
if (rb != null) return rb.object;
}
else { // Hit
else if (from == 1) { // Hit
var hitPointWorld:Vec4 = rb != null ? physics.hitPointWorld : null;
v.set(hitPointWorld.x, hitPointWorld.y, hitPointWorld.z);
v.set(hitPointWorld.x, hitPointWorld.y, hitPointWorld.z, 1);
return v;
} else { // Normal
var hitNormalWorld:Vec4 = rb != null ? physics.hitNormalWorld : null;
v.set(hitNormalWorld.x, hitNormalWorld.y, hitNormalWorld.z, 0);
return v;
}
#end

View file

@ -43,6 +43,7 @@ class PhysicsWorld extends Trait {
var maxSteps = 1;
public var solverIterations = 10;
public var hitPointWorld = new Vec4();
public var hitNormalWorld = new Vec4();
var pairCache:Bool = false;
static var nullvec = true;
@ -316,10 +317,14 @@ class PhysicsWorld extends Trait {
var body = untyped Ammo.btRigidBody.prototype.upcast(co);
var hit = rayCallback.get_m_hitPointWorld();
hitPointWorld.set(hit.x(), hit.y(), hit.z());
var norm = rayCallback.get_m_hitNormalWorld();
hitNormalWorld.set(norm.x(), norm.y(), norm.z());
rb = rbMap.get(untyped body.userIndex);
#elseif cpp
var hit = rayCallback.m_hitPointWorld;
hitPointWorld.set(hit.x(), hit.y(), hit.z());
var norm = rayCallback.m_hitNormalWorld;
hitNormalWorld.set(norm.x(), norm.y(), norm.z());
rb = rbMap.get(rayCallback.m_collisionObject.getUserIndex());
#end
}

View file

@ -14,5 +14,6 @@ class CastPhysicsRayNode(Node, ArmLogicTreeNode):
self.inputs.new('NodeSocketVector', 'To')
self.outputs.new('ArmNodeSocketObject', 'Object')
self.outputs.new('NodeSocketVector', 'Hit')
self.outputs.new('NodeSocketVector', 'Normal')
add_node(CastPhysicsRayNode, category='Physics')