Landscape mode in chipmunk/cocos2D - iphone

I'm trying to create a chipmunk space with a bouncing ball.(Example seen here)
Currently my device is running in Landscape mode. So according to cocos2D everything is all right. When adding Sprites they orient to landscape mode.
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
The only problem is that the device orientation is screwed up when using chipmunk right now. When tilting the ipad towards the upper-left corner, my 'bouncing ball' moves towards the upper-right corner.
Is there a way to rotate a chipmunk space manually?
Or is there some other way to set rotation within a chipmunk space?

It sounds like a simple sign issue. I assume the balls are moved by applying a force to them. So instead of applying a positive force like (10, 0) apply a negative force (-10, 0) when moving the balls in one direction, and do the reverse in the other (eg multiply x coordinate forces by -1). Chipmunk doesn't care or know about device orientation, it just moves objects according to forces and gravity.

Related

Rotating character in relation to First Person camera? (Unity3D, Pictures linked)

I'm having an issue where my character is facing 90 degrees away from the (first person) camera. So when I move the character, the model is turned 90 degrees to the right instead of facing forward. (Pic 1)
Since the camera is a child of the player, if I rotate the character -90 degrees, the camera rotates with it. If I rotate my camera back 90 degrees, the controls get messed up (the W to go forward becomes W to go right, etc.) (Pic 2)
Is there anything I can do to either change the default rotation of the
For reference, I am using this FP Controller torah horse(.)com(/)First-Person-Drifter-Controller-for-Unity3d-1 (that uses a cylinder, so doesn't have the same rotation issue)
I'd advise you to put a script on the Camera instead of making it a child of the player. This gives you more freedom in how the Camera behaves.
Actually, looking at your pictures again... Why not just set the Camera behind the player correctly, instead of rotating the player. When you have the Camera as s child it will be responsive to the parents transform, but it wont mimic. It will follow with the same offset as it starts with. So instead of rotating the player, which messes up the controls, simply put the Camera where you want it from the start.

How to make a perfect pinch zoom (Unity 3D)

I am searching for a solution to how to make a perfect pinch zoom in Unity by moving the camera along the forward:
Set up:
Horizontal plane centred at the origin with all Game objects.
Perspective camera with FOV 10, offset at (10,10,10) looking down at a 45 degrees angle, so that it looks at the origin (there is also a rotation of 45 degrees around the axis pointing up, to achieve this).
What I need:
When I place two fingers on the screen I am touching two GameObjects with them - so the screen coordinates under the fingers correspond to certain world coordinates. When I make a pinch movement (with moving two fingers or only one) I want the new screen coordinates to correspond to the same world coordinates that were under the fingers at the beginning of the whole interaction.
So to simplify even further - whenever I touch the screen with two fingers, I want the world coordinates corresponding to the screen coordinates under my fingers to always stay under the fingers (allowing a very small margin of error).
An example of this perfect zoom for which I am looking for you can see in the mobile game Boom Beach from Supercell.
I already tried to move the camera along its forward vector and to reposition it and I get pretty good results, but pretty much always the GameObjects underneath ‘slip’ away from under my fingers, that is at some points are no longer underneath them. It would be great if there was a mathematical solution to this, but if it’s necessary to compute the answer (through some search for example) then this is totally fine.
If the setup/scenario is not clear, I could provide some sketches to clarify it a bit more.
Hope someone can help me! :)
I would set up a system that detects when the user is zooming in and out if you are using GameObjects to pinpoint where the fingers are that is easy to do with Vector3.distance. After that, I would make a function that moves the camera closer to your desired zoom level with Vector3.MoveTowards(camera position, desired position, the speed of movement) where I would set "speed of movement" as a mathf.sqrt(vector3.distance(Camera position, Desired position));
as for the "desired position" I would set that Vector3(position) as a fraction of a line between two game objects that represent your maximum and minimum zoom level.
EDIT: with that, you should have a very nice camera system

To follow a ball character like monkey kick off game

I am working on a game which has working similar to game monkey kick off. I have one ball bouncing on a place at the left side of screen and depending upon the position of the ball I apply linearImpulse to the ball on user touch so that it appears that the ball is kicked.
But what happens is when i apply impulse the ball goes out of the screen bounds. I dont want the ball to go out of the horizontal screen bounds whereas it can go out of the screen vertically.I tried using CCFollow but it doesn't give the realistic feel to the game flow.
I tried THIS tutorial, but dint help much.I managed to scroll the background,Only this part remains.
Any Ideas on how the ball should not move out of the horizontal screen boundary..? but in case of vertical boundary on the other hand it can go out of the bounds.
If you're not using physics, it's a simple bounds check. Assuming the screen width is 320 points this will keep the ball inside the screen horizontally:
CGPoint ballPos = ball.position;
ball.position.x = fmaxf(0, fminf(320, ballPos.x));
ball.position = ballPos;
UPDATE: I noticed you mentioned linear impulse. So you're using a physics engine. In that case, create a horizontal wall on both sides. See the cocos2d Box2D or Chipmunk templates how to enclose the screen with a collision border, then use only the left and right side borders in your game.

Device roll compensation on augmented reality

I'm working on an app that performs geolocalization over the camera stream of the iPhone. I use the compass to figure out where to put the icons and information onto the the camera layer. If I rotate the device around yaw axis everything works fine.
However, when I roll the iPhone all the information on screen goes away. That's because when you roll the device the compass orientation also changes. However, there are apps like Layar or Wikitude that allow roll rotation without losing focus on the visual items you have onto the camera layer. That way, these apps allow smooth transition between portrait orientation to landscape orientation.
How they achieve that? How can I compensate the roll rotation of the device to keep information on screen?
By the way, the ARKit framework has the same problem as me.
Thanks.
If you are in 2D maybe it is enough to take the point you are calculating from camera field view and offset heading, calculate the distance to the center of the screen, and use that distance as a radius for a circle to do x += r*cos, y += r*sin with -roll as the angle, so the object moves in a circle against the roll. Then you just have to counter rotate the image itself with a transform (CGAffineTransformMakeRotation) to keep it vertical.

Accelerometer detection and sprite rotation

I would like to use the accelerometer to move my player sprite.
If the sprite is going straight and the player tilts a little to the left, the sprite should rotate a little bit to the left, and same for the right.
I also want to detect how much the player has tilted the device and turn the sprite accordingly.
e.g. If the player tilts the device a lot the sprite should rotate 90 degrees rather than 45 for a quick tilt in a direction.
How does one do this. Detect the device movement in any direction, and for a small movement, the sprite should rotate less and for a larger rotation the sprite should rotate more.
I have experimented a little and dont get the results. Some times it works for clockwise rotations to the up, right and down movements, but not for the left movements.
What is the math behind this. An example would be the way a device detects its orientation and rotates the screen.
How does one do this correctly?
For accelerometer only detection chances are bad. You might look look at this question. If you don't need to rely on older iPhone versions (<4) or iPad, you should use the gyroscope instead. Take core motion API and start with teapot example from WWDC 2010 - you can find it here