Platforms to show: All Mac Windows Linux Cross-Platform

/Mac64bit/SceneKit/Camera with fix elements
Function:
Required plugins for this example: MBS MacCG Plugin, MBS MacBase Plugin, MBS Mac64bit Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Mac64bit/SceneKit/Camera with fix elements
This example is the version from Tue, 4th May 2020.
Project "Camera with fix elements.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Mapp Inherits SCNControlMBS
ControlInstance Mapp Inherits SCNControlMBS
EventHandler Sub Open() MyView = Me.View MyScene = New SCNSceneMBS MyView.scene = MyScene myView.autoenablesDefaultLighting = True MyCamera = New SCNCameraMBS CameraNode = New SCNNodeMBS CameraNode.Camera = MyCamera CameraNode.Position = New SCNVector3MBS(0, 0, 7) MyCamera.zNear = 0.7 MyCamera.zFar = 23 myview.pointOfView = CameraNode MyView.allowsCameraControl = True myView.backgroundColor = NSColorMBS.blackColor timer1.Mode = Timer.ModeMultiple timer1.Period=1 FixToCamera Rotate90Degree End EventHandler
End Control
Control Top Inherits PushButton
ControlInstance Top Inherits PushButton
EventHandler Sub Action() // Set the Point of view on the top CameraNode.Position = New SCNVector3MBS(0, 7, 0) CameraNode.EulerAngles = New SCNVector3MBS(4.71239, 0, 0) myview.pointOfView = CameraNode myview.play End EventHandler
End Control
Control left Inherits PushButton
ControlInstance left Inherits PushButton
EventHandler Sub Action() // Set the Point of view on the left side CameraNode.Position = New SCNVector3MBS(7, 0, 0) CameraNode.EulerAngles = New SCNVector3MBS(0, 1.5708, 0) myview.pointOfView = CameraNode myview.play End EventHandler
End Control
Control right Inherits PushButton
ControlInstance right Inherits PushButton
EventHandler Sub Action() // Set the Point of view on the right side CameraNode.Position = New SCNVector3MBS(-7, 0, 0) CameraNode.EulerAngles = New SCNVector3MBS(0, 4.71239, 0) myview.pointOfView = CameraNode myview.play End EventHandler
End Control
Control Front Inherits PushButton
ControlInstance Front Inherits PushButton
EventHandler Sub Action() // Set the Point of view on the front CameraNode.Position = New SCNVector3MBS(0, 0, 7) CameraNode.EulerAngles = New SCNVector3MBS(0, 0, 0) myview.pointOfView = CameraNode myview.play End EventHandler
End Control
Control CameraControlCheck Inherits CheckBox
ControlInstance CameraControlCheck Inherits CheckBox
EventHandler Sub Action() MyView.allowsCameraControl = Me.value End EventHandler
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() //Set the camera view to the position of the point of view CameraNode.Position = MyView.pointOfView.Position CameraNode.orientation = MyView.pointOfView.orientation CameraNode.EulerAngles = MyView.pointOfView.EulerAngles End EventHandler
End Control
Sub FixToCamera() //sphere green Dim sphere1Geometry As New SCNSphereMBS(1) Dim sphere1 As New SCNNodeMBS(sphere1Geometry) sphere1Geometry.firstMaterial.diffuse.contents = NSColorMBS.greenColor sphere1Geometry.firstMaterial.emission.intensity = 2000 sphere1.Position = New SCNVector3MBS(3, 0, -10) //Child of the camera CameraNode.addChildNode(sphere1) //sphere red Dim sphere2Geometry As New SCNSphereMBS(1) Dim sphere2 As New SCNNodeMBS(sphere2Geometry) sphere2Geometry.firstMaterial.diffuse.contents = NSColorMBS.redColor sphere2.Position = New SCNVector3MBS(-3, 0, -10) //Child of the camera CameraNode.addChildNode(sphere2) //Add the camera to the Scene MyScene.rootNode.addChildNode(CameraNode) End Sub
Sub Rotate90Degree() //Add the Node to the Scene Dim NodeOneGeometry As New SCNPyramidMBS(1, 1, 1) Dim NodeOne As New SCNNodeMBS(NodeOneGeometry) NodeOneGeometry.firstMaterial.diffuse.contents = NSColorMBS.purpleColor NodeOne.Position = New SCNVector3MBS(0, 0, 0) MyScene.rootNode.addChildNode(NodeOne) //The angle must be given as radians //Convert: angleDegree*(Pi/180) Dim angleDegree As Double = 90 Const Pi = 3.14159265358979323846264338327950 Dim angleRad As Double angleRad = angleDegree * (Pi / 180) //create the movements Dim rotate90 As SCNActionMBS = SCNActionMBS.rotateBy(angleRad, 0, 0, 2) Dim moveBy As SCNActionMBS = SCNActionMBS.moveBy(1, 0, 0, 1) Dim pos As New SCNVector3MBS(0, 0, 0) Dim moveTo As SCNActionMBS = SCNActionMBS.moveTo(pos, 1) Dim sequence As SCNActionMBS = SCNActionMBS.sequence(Array (rotate90, moveBy, moveTo)) Dim repeat As SCNActionMBS = SCNActionMBS.repeatActionForever(sequence) NodeOne.runAction(repeat) End Sub
Property CameraNode As SCNNodeMBS
Property MyCamera As SCNCameraMBS
Property MyScene As SCNSceneMBS
Property MyView As SCNViewMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Mac64bit Plugin.

The biggest plugin in space...




Links
MBS Xojo Plugins

Start Chat