I am trying to rotate an object (essentially a cube from Maya) 90 degrees one way when tapped, then when tapped again it rotates -90 degrees.
The rotation when tapped is working, however the pivot seems to be located at the origin (0,0,0), so it always rotates around the origin.
I want to be able to manipulate the anchor point but keep the geometry in the same place.
Ideally the anchor point would be moved to the back left of the object if possible?
This is what I have tried so far:
Using :
result.node.pivot = SCNMatrix4MakeTranslation(-30.0, 0.0, -20)
but that seems to just move the pivot point and the geometry together.Bringing in my geometry again from Maya with the pivot in the correct place but Xcode seems to reset all pivots to origin.
Making an empty node moving the pivot to the desired location (roughly) and putting my object in the empty node and that didn't work.
Any help would be great! Thank you in advance :)
Here is my code to rotate the object:
var objectHit = false
var firstTimePressed : Bool = false
var hitTestOptions = [SCNHitTestOption: Any]()
hitTestOptions[SCNHitTestOption.boundingBoxOnly] = true
let results: [SCNHitTestResult] = sceneView.hitTest(latestTouchLocation, options: hitTestOptions)
// The user has touched the virtual object
for result in results {
let object = VirtualObject.isNodePartOfVirtualObject(result.node)
if object != nil {
objectHit = true
}
if object?.childNode(withName: "door", recursively: true) == result.node{
if(firstTimePressed == false){
print("object should open")
result.node.pivot = SCNMatrix4MakeTranslation(-30, 0, -20)
result.node.runAction(SCNAction.rotateBy(x: 0, y: -1.5708, z: 0, duration: 1))
firstTimePressed = true
}
else{
print("object should close")
result.node.pivot = SCNMatrix4MakeTranslation(-30, 0, -20)
result.node.runAction(SCNAction.rotateBy(x: 0, y: 1.5708, z: 0, duration: 1))
firstTimePressed = false
}
}
}