physics body物理形體
physics shapes物理形狀
獲取相機(jī)中心
ARFrame * frame = self.jpARSCNView.session.currentFrame;
SCNMatrix4 mat = SCNMatrix4FromMat4(frame.camera.transform);
SCNVector3 dir = SCNVector3Make(-1* mat.m31, -1* mat.m32 , -1* mat.m33);
SCNVector3 pos = SCNVector3Make(mat.m41,mat.m42 ,mat.m43);
bulletsNode.position = pos;
SCNVector3 bulletDirection = dir;
[bulletsNode.physicsBody applyForce:bulletDirection impulse:YES];
[self.jpARSCNView.scene.rootNode addChildNode:bulletsNode];
檢測(cè)碰撞事件
和以往iOS的代理事件不同 它還要多設(shè)置categoryBitMask荒叶、contactTestBitMask屬性的id 用于標(biāo)志2個(gè)物體是否會(huì)發(fā)生碰撞
代理設(shè)置
<SCNPhysicsContactDelegate>
_jpARSCNView.scene.physicsWorld.contactDelegate = self;
self.physicsBody.categoryBitMask = 2;
self.physicsBody.contactTestBitMask = 1;
// 這里是自己獨(dú)立開一條線程出來(lái)
— (void)physicsWorld:(SCNPhysicsWorld *)world didBeginContact:(SCNPhysicsContact *)contact ;