off topic until such time as Xojo has iOS Scenekit support I guess…

But had anyone played with rotations (box, sphere and/or camera)

It seems that Scenekit rotates in the direction of the change … clockwise if angle increases, counter if decreases…

BUT, the problem I see is when you pass the boundary of 0 and 359 degrees…

if at 359 degrees and you increase by 1 degree… it rotates the object BACKWARDS (ie. a full reverse rotation), instead of the correct direction
and the same if going from 0 to (-1/359) degrees.

This of course creates a visual glitch in the animation

I’m using SCNTransaction.setAnimationDuration as well, as the increments are actually 5 degrees (not one)… it looks great until it crosses that boundary

What if you step from 359 to 360 and then adjust to 0 without a redraw?

Thats the problem… I can’t find a way to NOT do a redraw… It seems that the scene refreshes automagically anytime you adjust a property that affects the visual aspects in any way.

Silly question - could you pause the SCNView, change the setting, then resume? I’ve never used SceneKit so maybe it would stutter or something but maybe it’s worth a try.

I have yet to find any property that might allow anything like that…
actually kinda surprised that someone hasn’t included SceneKit into MacOsLib… its really kinda awesome :slight_smile:

Hmmmmmmm … just found scene.Paused=true|false … lets see if that works

How do you implement a rotation in SceneKit? From CoreAnimations and SpriteKit, I know similar issues. In one case (don’t remember exactly which one it was) this jumping could be avoided by not using a rotation property but by modifying the transformation matrix.

And SceneKit: Isn’t that 64bit exclusive like SpriteKit? In any case, reading your testimonial I have the feeling adding it to iOSLib would be quite interesting to me. And most of iOSLib is prepared for an easy translation to Mac OS X once we got 64bit there too …

 self.rotation = SCNVector4(x: 0, y: 1, z: 0, w:a)

where self is the object to be rotated, x,y or z is the axis to rotate around, and “A” is the angle in radians to rotate “to”

SceneKit seems to automatically handle the animation, and will rotate clockwise or counteclockwise depending on if “A” is > or < the current rotation angle (stored internal to the object)

And SceneKit is new as of iOS8 (so guess Xojo won’t be supporting it for a while :frowning: )
and been in OSX for past couple releases I think

Give me a few days, Dave. I will have to dig into the definitions. But it’s so similar to SpriteKit I will surely remember. And it all sounds so fascinating I couldn’t resist:

(If you wonder what that is:

here is a snippet from iOS simulator of what I’m playing with… obviously some of the math to position things is a bit off

the “lines” are there on purpose to help me visulize how they line up.

The “smiley” is 3 linked nodes… The Sphere, The Face (another sphere) and the Shadow
A sphere can only have one “material” or texture… and I want to have any color with multiple “faces”… so the two spheres occupy the same XYZ space, one is textured with the “color”, the other with a transparent masked “face” graphic.

When I learn more, I might be able to dispense with the “shadow” and let SCENEKIT do shadows for me, but I have’nt gotten to playing with lighting and effects yet.

Hehe … yes, but I see where you’re going. Have a nice day :smiley:

I just updated the link I sent you in private with the addition above. It’s not much in it yet (and really bedtime for me now), but I must say in this case iOS simulator seems to do a good job – panning and dragging the box is really smooth. Just hit the untitled button.

EDIT: A last reply for tonight. If SceneKit is really that much like SpriteKit, you will probably get a non-jumping rotation by using the transform property. With a SCNMatrix4Rotate call on the current rotation object, you should get the right movement.

My understanding is SpriteKit is 2D while SceneKit is 3D… FYI… fixed the math… better picture above :slight_smile:

I’ll look into that article… but so far this is been fun :slight_smile:

All the headache of doing all the “work” is taken care of… I still need to add “colliision” detecting… right now I can “walk thru walls”.

Also I have the camera left and right, and yellow smiley spin set at 3degrees on a 1/10 second timer… .I may remove the timer and just allow 8 directions (make it easier to calculate movement paths)

I can’t duplicate this behavior. Can you show more of the relevant code?

You said you used SCNTransaction so I modified the template SceneKit game to rotate the ship on mouseDown. Goes around the 2pi boundary without jumping backwards.

[code]class GameView: SCNView {
var theShip: SCNNode!
var angle: CGFloat = 0.0

override func mouseDown(theEvent: NSEvent) {


    angle += 6.28318 * 0.21  //on the 5th click angle passes the 2pi boundary
    theShip!.rotation = SCNVector4(x: 0, y: 1, z: 0, w:angle)




AFAIK just need 64bit and it’s supported. 64bit desktop is in beta (AFAIK).

Ah… I DIDN’T use BEGIN/COMMIT… :slight_smile: that may be the key… thanks

I don’t think you need to. Without BEGIN/COMMIT should work like an implicit transaction which is fine because only the rotation property is changed. An explicit transaction, as far as I believe to have understood, would be recommended if you do a lot of modification you want to hold together.

Strange… I moved a few procedures around to make it easier to read, and the “problem” vanished… animation is super smooth, and looks AWESOME :slight_smile:

Dave, did you have time to experiment with the lighting? I rebuilt the in Xojo up to

[quote]Now that you’ve set up some lights, delete the following line from sceneSetup:
sceneView.autoenablesDefaultLighting = true
Build and run! Pinch to zoom out, and you’ll find your box properly illuminated:[/quote]

But no – I colored the additional lights and they are clearly visible. Once I remove the defaultLighting, I see only white. Did you encounter similar? (In case you’d like to see it in Xojo I updated the link I sent you)

No I have not yet experimented with lighting… The example I had included simple ambient light… and when I turned it off, the scene did not really seem to change. I’m thinking for this kind of “game”, a light that tracks with the camera might be best.

Right now I’m trying to get “names” to float above the “Smiley”… and while I have THAT working… there are two things I cannot get to work.

  • Have the text “centered”… it is left justified no matter what I do
  • have the text always face the camera. Adding look at contrainsts cause the text to become a reverse mirror image

[pic above has been updated…again]

About the text positioning: Is the centerpoint for a text node the center too or is it its left origin? Looks like they are fixed nicely in the middle, but by their left side.
And if they’re mirrored: How about applying a transformation that mirrors them too?
Overall, looks like real fast progress on your side!

  • the text point is dead center above the smiley. I found code that “supposely” centers in on that point, but it doesn’t work
        var v1 = SCNVector3(x: 0,y: 0,z: 0) // this is "supposed" to force text centering, but doesn't seem to
        var v2 = SCNVector3(x: 0,y: 0,z: 0)
        myText = SCNText(string:"Name",extrusionDepth:0.1)
        myText!.font = UIFont (name: "Arial", size: 3)
        myText!.firstMaterial!.diffuse.contents = UIColor.whiteColor()
        myText!.getBoundingBoxMin(&v1, max: &v2)
        let theText=Node3D(0,wallSize/2,0)

        // theText.rotation = SCNVector4(x: 0, y: 0, z: 0, w:Float(M_PI))
        force text to always face the camera
            let constraint = SCNLookAtConstraint(target: theCamera!)
          constraint.gimbalLockEnabled = true
          theText.constraints = [constraint]

  • and the commented code would have rotated the text 180deg (my idea being the mirror would return to normal, but here it STAYED mirrored :frowning: )

… while I have found out the position property doesn’t work!?!? The bar in the image should have an offset to the box it crosses, but it always stays in its center. Hmm … SCNVector3 is a structure of three CGFloats, isn’t it? And I would set a node’s position with setPosition: – no crash, only my values are ignored all the time. This could explain the invisibility without autolighting – I placed my lights within the object. Anyone wants to debug this? I’m currently out of ideas.
(Updated the image above)

EDIT: Ok, it is clearly too hot. Note: It helps if you don’t do anything like

#If Target64Bit // whatever #elseifTarget64Bit // do something different #Endif