Move coordinate system in wpf - c#

The coordinate system in viewport3D in wpf is fixed at the center of the screen with positive X-axis being rightward, positive Y-axis upwards and Z-axis pointing outwards. All the calculations in transform are being made with respect to this transform. My question is, how can I change the position and orientation of this coordinate system in my code dynamically.
The requirement is, I have two wheels rolling on the ground. But when the wheels take a 90 degree turn, the axes get interchanged. So, If I could shift and orient this coordinate system, I can tackle this problem.

Related

Does Unity move object by the magnitude(length) of vector value?

Most of you may know that moving object diagonally is faster than moving object horizontally or vertically. You can watch a short youtube tutorial here. If an object is set at (0,0) then using this code.transformation.postition += new Vector3(x, y, 0f).Assume moving object on 2D plane. When looking the object position at 2D grid(cartesian plane), for value x=1, y=0, it move one position right, for value x=0, y=1, it move one position up and for value x=1, y=1 it move one right and one up. When look at the following image, the line drawing diagonally is obviously longer than others. I read about vector, the magnitude of vector, Pythagorean theorem. Assume an object move one unit every frame. Then after 1 frame passed all objects will be moved 1 unit exactly. But when calculate in magnitude[length] of vector the units are different. I mean 1 in X or Y and around 1.4 in diagonal. Aren't object moving from point to point? Does Unity move object in vector's magnitude value and set the point on X and Y plane? How do object actually move?
Unity is a frame-based engine. So Unity calculates the positions where objects are in a frame, and when it comes to calculating the next frame, the positions are calculated there as well. One could assume that the object has moved between these frames and conclude that, for example, a projectile must have hit a thin object between the two frames.
If you want to move an object consistently in any direction, first clamp the direction with normalized and then add a custom magnitude.

ARCore 1.4.1 Align rectangle pararell to floor

How can I set rotation of the placed on vertical plane object to make its bottom side pararell to floor? At the moment vertically placed objects are sticky to the wall but have random rotation. I have been trying to set object on horizontal plane and then adjust vetical objects vector forward to horizontal objects vector up. That seems to work somehow but multiple objects apart of being pararell to each other are rotated in christmas tree shape. Important thing - I want to rotate it relative to real world, not to bottom of the screen.
What I want:
What I get:
VerticallyPlacedObject.transform.forward = HorizontallyPlacedObject.transform.up;
Screenshot:

Adjust Camera Z Position Depending on the Canvas Size (Resolution)

I need some advice regarding the UI Menu in my game. So, I've created several canvases on a scene and set it all to world space. The idea is that the camera should move around the scene with several canvases representing different menu sections (main, options, new game, etc.). Now I've started to adjust the elements according to the resolution set in settings.
Now it does the following: when the game starts it looks for the current resolution and scales all objects according to this resolution by scale ratio (currentResolution/defaultResolution). And it scales fine and looks fine as well.
The problem is with the camera. The idea is to set the camera to focus on the centre of a canvas and hold a certain distance by Z. What I did is I've taken the canvas height (i.e. 720 as in currentResolution (1280x720)) and devided it by two and set Z position to be 1280/2 as well it as Y position of the mainCamera.
The problem is with Z position. It works well with 16:9 aspect ratio but when I change it to, say, 5:4 this Screen.width/2 thing doesn't work correctly. The camera gets too close to the canvas and cuts out some elements and other parts of the UI. How do I set the camera Z position right for every resolution? Or is my approach entirely incorrect?
P.S. I've watched this Unity video on adjustung UI menu to all resolutions but this technique doesn't apply in my case since I have a wrold space menu which is a bit different. The only problem now is this Z position of the camera.

Relation between bounds.extents and trasform.localScale

I am using the bounds.extents to represent the radius of a sprite in Unity. In my simulation I am changing the size of the sprite using transform.localScale. When I want to spawn new sprites I want to spawn them so that the radius won't exceed my ground (represented as a plane). Thus I am making sure that the new sprite is not spawned within a range of bounds.extents to the edge of the plane. But when the sprites reaches their maximum radius they exceed the edge of the plane. So my question is, what is the relation between bounds.extents and transform.localScale?
You have to make sure that the radius you allow the sprites to be placed in is less than the extents of the plane and the half the size of the sprite. because when you place the sprite on the edge of the radius, the center of it is on the borders of the plane, so half of it is outside it. Did I understand the problem correctly?
As for the relation, the bounds.extents describes half the size of the sprite in units, while transform.localscale is the scale relative to the object's parent's scale. It is also an indication of the current size compared to the original size of the sprite, it doesn't indicate the size in units.
So assuming the parent's scale is 1:
bounds.extents = (original bounds.extents) * transform.localScale

How to convert a 3D acceleration into a rotation?

I have a program which utilizes an accelerometer in the Windows Phone 7, and I need to detect what the rotation of the device is. I have X, Y, Z accelerations, and need to somehow figure out the orientation of the phone based off of that. How can this be accomplished? (Rotation values should be in Degrees)
Although I am working on iPhone it should basically the same problem. Your hardware needs a gyroscope sensor to describe rotations, especially those in parallel to gravity (let's call this z, x is right and y is up). If the device lays flat on the table and you rotate around this z-axis, there are only tiny accelerations measured resulting from centrifugal forces. So you can get some information about rotation, but you are limited in:
1) Users have to hold the device in specific manner for you to detect the rotation properly
2) Even if you got the best case of 45 degree to ground, it is very hard to get all 3 dimensions. You are better off, if you can limit detection on 2 rotational directions only.
3) You are limited to either rotations or translations, but combining detection of rotations with linear motions simultaneously is pretty hard.
Conclusion: For a racing game force users to hold the device in certain angle, limit on z-Rotation for steering wheel and some other direction for e.g. power slides or whatever.
Use of axis can be quite confusing. I stay with the orientation of X for horizontal axis (left and right), Y for vertical axis (up and down) and Z axis is the depth(far and near).
Using the accelerometer, you can only detect rotation about the X axis and Z axis, but not the Y axis.
Suppose your phone is place flat at rest position, the force of gravity will result in the Y acceleration to be around -9.8, and the X and Z acceleration will be around 0.
Assume that phone remains flat in the position. When you rotate the phone about the Y axis (assuming there is no translation to the phone or change in position to the phone as you rotate), there is no significant change to the value of X, Y and Z acceleration. Therefore, you can't detect any rotation about the Y axis.
When you rotate about X and Z axis (assuming no change in position of the phone while rotating), all the 3 acceleration values changes, but vectors will have the characteristic of x^2 + y^2 + z^2 = 9.8^2.
You can use simple trigonometrical formula to determine the rotation about the Z and Z axis.
As pointed out by Kay, you will still need the gyroscope to output the angular velocity of the rotation about each axis to compute the rotation about the y axis.
If you want to get the rotation angle of the phone held in your hands (ie rotated in one plane) let's say held facing your chest...
atan2(y accel., x accel.)
You'll get rotational values :) It's likely to be jittery so you'll probably want to average the results over a sample period to smooth it out.

Categories

Resources