When I move a node, other nodes in the graph move. Moving one node stops it from moving further. But how to stop all nodes movements together?
By default, the nodes are locked and will not move but when you click on the unlock button (see attached screen shot), the node will move when you move the node connected to it. There is no setting to stop all nodes movements together.
Related
I am working on a basic racing game using Apple's SceneKit and am running into issues simulating a car. Using the SCNPhysicsVehicle behavior, I am able to properly set up the car and drive it using the documented methods.
However, I am unable to get the car's position. It seems logical that the SCNPhysicsVehicle would move the SCNNodes that contain the chassis and the wheels as the car moves but the SCNNodes remain at their original position and orientation. Strangely enough, the chassis' SCNPhysicsBody's velocity remains accurate throughout the simulation so I can assume that the car's position is based off of the SCNPhysicsBody and not the SCNNode. Unfortunately, there is no documented method that I have found to get an SCNPhysicsBody's position.
Getting a car's position should be trivial and is essential to create a racing game but I can't seem to find any way of getting it. Any thoughts or suggestions would be appreciated.
Scene Kit automatically updates the position of the node that owns an SCNPhysicsBody based on the physics simulation, so SCNNode.position is the right property to look for.
The catch is that there are actually two versions of that node in play. The one you typically access is called the "model" node. It reflects the target values for properties you set, even if you set those properties through an animation. The presentationNode reflects the state of the node currently being rendered — if an animation is in progress, the node's properties have intermediate values, not the target values of the animation.
Actions, physics, constraints, and any scene graph changes you make inside update/render loop methods directly target the "presentation" version of your scene graph. So, to read node properties that have been set by the physics simulation, get the presentationNode for the node you're interested in (the node that owns the vehicle's chassisBody physics body), then read the presentation node's position (or other properties).
I have the same problem with my player node.
I move it with applyForce (to manage collision detection).
But when i check node position after some movement, the node position has not move (presentation node is the actual position as rickster write in his answer)
I manage to update the scnNode.position with renderer loop
You have to set position of your node with the presentationNode position.
node.position = node.presentationNode.position
Set this into renderer(_: updateAtTime) and your node position will sync with any animation you made to the physicsBody
In SceneKit, you can add a lookAtConstraint constraint to your SceneView's Point Of View, to make Camera look at a certain node.
Is there a standard way of doing the same but for a specific face of a geometry?
So that, if I touch a specific face of a cube, camera would move so that the Z axis of the camera node gets in line with the normal of the touched face? So that the cube would look like a plane form the new perspective.
No.
That would require movement of the camera, in addition to re-aiming it.
Imagine I'm in front of my house. I have a great view of the front and can just barely see the side to my left. In my Scene I tap the side of the house. A LookAt constraint would merely change the angle of the camera. It would not be aligned with the normal of that barely visible side.
To align with the normal, I'd have to walk around the house until I can stare at the house and be perpendicular to the side I tapped. At what radius? What path? You have to figure that out yourself.
Depending on what effect you're trying for, you might want to rotate the model instead of moving the camera. Rotate the tapped node locally (or as a child of an invisible parent) so that its minus-Z axis points out the tapped face, and keep a lookAtConstraint on the node, not the camera. This approach will change the look of the object, though: you will see it rotating, and the shading changing appropriately.
So that, if I touch a specific face of a cube, camera would move so that the Z axis of the camera node gets in line with the normal of the touched face?
Supposing you are using hit-testing to determine what object got touched, a SCNHitTestResult will give you both localCoordinates and localNormal from which it should be fairly easy to derive a camera transform.
One easy way would be to have the camera as a child node of the box, compute a position that would look like localCoordinates + distance * localNormal and finally a transform using GLKMatrix4MakeLookAt and SCNMatrix4FromGLKMatrix4.
Note that you can also use worldCoordinates, worldNormal, as well as conversion utilities such as SCNNode.convertTransform(_:from:).
mutating on mnuages answer, use a hit test or ray trace to find where the user tapped on the mesh, then add a node at that location, and constrain the camera to lookAt that node.
I am working on a basic racing game using Apple's SceneKit and am running into issues simulating a car. Using the SCNPhysicsVehicle behavior, I am able to properly set up the car and drive it using the documented methods.
However, I am unable to get the car's position. It seems logical that the SCNPhysicsVehicle would move the SCNNodes that contain the chassis and the wheels as the car moves but the SCNNodes remain at their original position and orientation. Strangely enough, the chassis' SCNPhysicsBody's velocity remains accurate throughout the simulation so I can assume that the car's position is based off of the SCNPhysicsBody and not the SCNNode. Unfortunately, there is no documented method that I have found to get an SCNPhysicsBody's position.
Getting a car's position should be trivial and is essential to create a racing game but I can't seem to find any way of getting it. Any thoughts or suggestions would be appreciated.
Scene Kit automatically updates the position of the node that owns an SCNPhysicsBody based on the physics simulation, so SCNNode.position is the right property to look for.
The catch is that there are actually two versions of that node in play. The one you typically access is called the "model" node. It reflects the target values for properties you set, even if you set those properties through an animation. The presentationNode reflects the state of the node currently being rendered — if an animation is in progress, the node's properties have intermediate values, not the target values of the animation.
Actions, physics, constraints, and any scene graph changes you make inside update/render loop methods directly target the "presentation" version of your scene graph. So, to read node properties that have been set by the physics simulation, get the presentationNode for the node you're interested in (the node that owns the vehicle's chassisBody physics body), then read the presentation node's position (or other properties).
I have the same problem with my player node.
I move it with applyForce (to manage collision detection).
But when i check node position after some movement, the node position has not move (presentation node is the actual position as rickster write in his answer)
I manage to update the scnNode.position with renderer loop
You have to set position of your node with the presentationNode position.
node.position = node.presentationNode.position
Set this into renderer(_: updateAtTime) and your node position will sync with any animation you made to the physicsBody
I have a grid (example below) containing outside walls (marked as W), environment blocks (E), open space (o) and active points (A). Presently, this grid is stored in a [,] with all of the data associated with a given point. I'm trying to determine if an active point is enclosed (defined as being incapable of reaching the top of the grid because it's blocked by environment blocks), but I'm having difficulty finding a simple way of solving this problem. I know that I could implement A* and it would be more-or-less easy with all the sample code out there, but I don't think the performance hit would really be necessary or worth it for such a seemingly trivial operation.
W--Top Of Grid--W
W---------------W
W-EEAEE-----EEE-W
WEEEEEEE-EEEEAEEW
WEEEEEEE--EEEEEEW
WEEEEEEEE-AEEEEEW
WWWWWWWWWWWWWWWWW
The A on the third line down can draw a path to the top of the grid, as can the one on the last line, however the one on the fourth line down cannot. I don't care for the actual paths, I just need to determine if the object is trapped or not. What would be the optimal solution to this project?
For what it's worth, it's a C# project for a turn-based grid game if that helps at all.
Thank you in advance for any help you can offer, it's much appreciated.
I think a floodfill from the top grids will solve all the problem. Flood from the top, then check which 'A' are flooded :)
The algorithm guarantees to visit each node only once during the whole process, which can not be faster in worst case. And it's really easy to be implemented in any language.
Here's the algorithm from Wikipedia:
Flood-fill (node, target-color, replacement-color):
1. If the color of node is not equal to target-color, return.
2. Set the color of node to replacement-color.
3. Perform Flood-fill (one step to the west of node, target-color, replacement-color).
Perform Flood-fill (one step to the east of node, target-color, replacement-color).
Perform Flood-fill (one step to the north of node, target-color, replacement-color).
Perform Flood-fill (one step to the south of node, target-color, replacement-color).
4. Return.
...and it looks like: (from wiki)
In short:
flood from the top grids, with 'W' and 'E' blocking the flood (like the black cells in the picture)
after the flood, check how many places containing 'A' are flooded.
In my web application I work with ExtJS4 and I use an Ext.tree.Panel. For a custom drag and drop implementation I need to find the tree node by its screen coordinates.
Is there a way to find a tree node by its screen coordinate? Or is it possible to find it via its HTML element?
Thanx in advance...
It would be not very efficient to seek node by coordinates as the only way to find the node by coordinates is to walk over all nodes.
Finding node by HTML element seems like more logical approach to me. Extjs4 tree utilizes the view. So you can try the view.getRecord method:
var node = tree.view.getRecord(htmlEl);
I haven't tried this code but it should work provided you passed correct htmlEl.
One part of your question has already been answered.
If you really need to get HTML element (use it only as last resort) by screen coordinates, then you will need document.elementFromPoint.
Extra info and quirks here: http://www.quirksmode.org/blog/archives/2010/06/more_ie9_goodne.html