I've an app that should show a 3D model, at this point all is OK, but this model rotates in all 3D space axis and I need that this model rotate only on X axis (left/right) when user tries rotate the model.
Any idea? I've been stuck here for a while...
Provide your own camera. Don't use the "allows camera control" checkbox in Interface Builder, and leave the view's allowsCameraControl property set to false.
You said "X axis (left/right)". But in SceneKit, the X axis runs left to right, so rotating left/right is a rotation around the Y axis. Add a swipe gesture recognizer to recognize swipes left and right. Use the recognizer's handler to rotate your model around the Y axis as the user's finger slides left and right.
Have a look at SCNTransformConstraint.
You can specify a SCNTransformConstraint as a value in the constraints property of the SCNNode to which the geometry is assigned.
Related
I am rotating an 3D object in three.js on the X and Y axes by click dragging and using the method rotateOnAxis. After I rotate, I want to reset the axes so that when I click drag again, it's as if the axes are in their original directions.
Looks like this can be done using quaternion. I found an example showing what I want to accomplish here: https://github.com/defmech/Three.js-Object-Rotation-with-Quaternion
I'm working on a app that renders a 3D scene that simulates a real space into an iPhone making its screen become a hollow box, as seen in the sketch below:
(note the camera position order down below)
The problem is on how to calculate the camera parameters to make the box look real fixed to the screen edges.
Is this feasible through SceneKit?
In this configuration the camera's zNear plane corresponds to the screen of the iPhone. From that you can can derive a z position from the camera's field of view and the screen's width (see here).
I need to be able to change rotation pivot without changing camera lookAt on THREE.TrackballControls no mater what I tried I could not succeed. Please give me a direction to solve this problem. What I am actually trying to achieve is Revit like mouse controls.
I was able to solve this problem by creating 2 3D objects named orbit and target, then add target and camera into orbit as child objects... camera always looks at target.position, mousemove on x axis rotates the orbit object around Z axis (hence target and camera rotates around the orbit) and mousemove on y axis rotates the camera arm (camera.position vector) around cameraSideways direction.
I'm working app that uses Libgdx engine and decals in 3d space.
Now I need to rotate decals around X,Y,Z axis, but around custom pivot point that stands somewhere in the 3d space.
I found that decals have transformationOffset field, which might work with some calculations, but is Vector2 only. It means that I can move pivot point only over X and Y axis.
And when rotating decals over Y axis, wherever the pivot is, the result is the same.
decal.transformationOffset = new Vector2(0, -5);
decal.rotateX(newValues[0]);
decal.rotateY(newValues[1]);
decal.rotateZ(newValues[2]);
I need to move pivot over Z axis, too.
Is there some workaround for this issue?
Tnx!
EDIT:
I have succeded to rotate decal over pivot point in 3d space, but only if pivot's and decals's Z position is the same. If they are not I don't get what I've expected.
This is the code that works for pivot with same Z value:
decal.transformationOffset = new Vector2(pivotPosition.x - decal.getPosition().x, pivotPosition.y - decal.getPosition().y);
Tween.to(decal, DecalTween.XYZ_ROTATION, 5f).target(0, 360, 0).repeatYoyo(Tween.INFINITY, 0f).start(tweenManager);
And in tween I do this:
target.setRotationX(0);
target.setRotationY(0);
target.setRotationZ(0);
target.rotateX(newValues[0]);
target.rotateY(newValues[1]);
target.rotateZ(newValues[2]);
How to extend this to use and Z value for pivot. I'm trying to add and translation animation beside rotate to achive this, but the results is weird.
Tween.to(decal, DecalTween.MOVE_XYZ, 2.5f).target(decal.getPosition().x, decal.getPosition().y, pivotPosition.z - decal.getPosition().z).repeatYoyo(Tween.INFINITY, 0f).start(tweenManager);
decal.transformationOffset = new Vector2(pivotPosition.x - decal.getPosition().x, pivotPosition.y - decal.getPosition().y);
Tween.to(decal, DecalTween.XYZ_ROTATION, 5f).target(0, 360, 0).repeatYoyo(Tween.INFINITY, 0f).start(tweenManager);
Any idea how to combine translate and rotate animatio to get decal rotation in circle path over the pivot point?
I will answer my own question I guess.
I have extended Decal class, changed transformationOffset to Vector3.
Then in transformVertices I have added tz value, like there already was tx and ty. And add tz in calculation for vertex position.
Simple as that.
If anyone knows why is this left out from native libgdx support, please let me know.
Cheers.
I have a view in interface builder, and then a subview within that view. I place the sub-view visually near the upper left corner within its parent. I would therefore expect the x, y coordinates of the sub-views frame to be something close to (20,20), but instead IB tells me it is something like (230,432). If I then adjust the X, Y coords in the properties window to something like (20,20), the sub-view flies off the screen towards the upper-left... What is the deal? BTW, it is an iPad specific view size, where the top/parent view is sized 768x1004.
In the Size & Position section, in the grid on the left, make sure the top-left corner dot is selected. The dot selected in this grid determines what the X and Y coordinates refer to.
You may have the center dot selected and so the X,Y coordinates indicate the coordinates of the sub-view's center relative to the parent.