stop rotation of map through heading - ios6

I have rotated the map through didupdateheading. and setMKUserFollowWithHeading. Now if i move the device the user always points towards north. I want to stop the rotation of map through stop button to the position it had already rotated.
How is that possible?

Take the angle about which the map has rotated by
heading = newHeading.trueHeading;
and transform the map in Stop button by implementing Stop button method as:
[mapView setTransform:CGAffineTransformMakeRotation(heading * M_PI /180.0f);

Related

How do I make the OrbitControls in Three js honor changes to orientation of the OrthographicCamera?

I use OrbitControls to allow the users to rotate and pan the screen. However I want to be able to set the rotation around the Z axis for the OrthographicCamera that the OrbitControls. I am able to change the position and the OrbitControls seem to honor that when I switch to a different view and back. However when I change the rotation around the Z axis for the OrthoGraphic camera, everytime I use the mouse to pan or rotate objects it jumps to 0 rotation and starts from there. How do I fix this?

Smooth Zoom with mouse in Mandelbrot set (C)

I've been working on a C Mandelbrot set program for the past few days and I managed to make it work fine, however, my end goal is to be able to smoothly zoom in the set with my mouse and that's something I haven't yet been able to do yet so I might need a bit of help !
Here's part of my code (well, the full mandelbrot function) :
//removed to free space
Here's a picture of the output :
(Sorry, it's not very pretty, colors were not my priority but I'll be sure to work on them as soon as I figure out the zoom !)
Mandelbrot
What I want to be able to do :
left click -> center of the image becomes mouse_x an mouse_y. Then, it starts zooming in as long as left click is held
right click -> [...] it starts zooming out as long as right click is held
move mouse -> if currently zooming in/out, the center of the image moves to the mouse's coordinates with it. Else nothing happens.
(already have a function that gets mouse's position and button being pressed)
Thanks a lot for your help !
The visible area is a rectangle defined by (Re.min, Im.min) and (Re.max, Im.max). When you click on a particular point, you can map the mouse position to a point (mouseRe, mouseIm) by using the same mapping as you use when rendering:
double mouseRe = (double)mouse_x / (WIN_L / (e->Re.max - e->Re.min)) + e->Re.min;
double mouseIm = (double)mouse_y / (WIN_H / (e->Im.max - e->Im.min)) + e->Im.min;
To zoom in, imagine drawing a line from the (mouseRe, mouseIm) zooming centerpoint to each of the corners of the visible area, forming a lopsided X. Based on the zoom amount, find 4 new points a certain fraction of the distance along these lines, these points will give you your new rectangle. For example, if you are zooming in by a factor of 3, find a point 1/3rd of the way from the centerpoint to the corners. This will produce a new rectangle with sides 1/3rd the size of the original and an area 1/9th the size.
To do this you can define a simple interpolation function:
double interpolate(double start, double end, double interpolation)
{
return start + ((end - start) * interpolation);
}
Then use the function to find your new points:
void applyZoom(t_fractal* e, double mouseRe, double mouseIm, double zoomFactor)
{
double interpolation = 1.0 / zoomFactor;
e->Re.min = interpolate(mouseRe, e->Re.min, interpolation);
e->Im.min = interpolate(mouseIm, e->Im.min, interpolation);
e->Re.max = interpolate(mouseRe, e->Re.max, interpolation);
e->Im.max = interpolate(mouseIm, e->Im.max, interpolation);
}
Based on my description, you might think you need to find 8 values (4 points for the 4 legs of the X with 2 dimension each) but in practise there are only 4 unique values because each of the sides is axis aligned.
For a smooth zoom, call it with a zoom factor of a little over 1.0 e.g. 1.01. To zoom out, pass the inverse e.g. 1.0 / 1.01.
Alternatively, if you want the center of the view to jump to a certain position when you click the mouse, calculate mouseRe and mouseIm as above and then offset the corners of the view rectangle by the difference between these values and the center of the view rectangle. You could store these values at the time the mouse button was first pressed down, and use them to zoom in as long as it is held.

Rotate Camera in the Direction behind object in OpenGL

I'm making a game in OpenGL, using freeglut.
I have a car, which I am able to move back and forward using keys and the camera follows it. Now, when I turn the car(glRotate in xz plane), I want the camera to change the Camera position(using gluLookAt) so it always points to the back of the car.
Any suggestions how do I do that?
For camera follow I use the object transform matrix
get object transform matrix
camera=object
use glGetMatrix or whatever for that
shift rotate the position so Z axis is directing where you want to look
I use object aligned to forward on Z axis, but not all mesh models are like this so rotate by (+/-)90 deg around x,y or z to match this:
Z-axis is forward (or backward depends on your projection matrix and depth function)
X-axis is Right
Y-axis is Up
with respect to your camera/screen coordinate system (projection matrix). Then translate to behind position
apply POV rotation (optional)
if you can slightly rotate camera view from forward direction (mouse look) then do it at this step
camera*=rotation_POV
convert matrix to camera
camera matrix is usually inverse of the coordinate system matrix it represents so:
camera=Inverse(camera)
For more info look here understanding transform matrices the OpenGL inverse matrix computation in C++ is included there.

Deriving a ray from cursor co-ordinates using Ogre3D

I am creating a spaceship game in which you will be able to fire a laser from their ship. Basically I want to create a ray from the players ship to the cursor position. The player can move around but the camera is static. So far I've tried using:
Ray laser = mCamera->getCameraToViewportRay(mMouse->getMouseState().X.abs, mMouse->getMouseState().Y.abs);
and setting:
laser.setOrigin->(mPlayer->getPosition);
However every time I execute the ray scene query, it fires towards the top left corner of my screen. I am using the code here as a reference to how to derive the screen co-ordinates: http://www.ogre3d.org/forums/viewtopic.php?f=5&t=49132
A quick side question for extra credit:
Is there a way of only drawing ManualObject for a small amount of time to simulate a shot from a laser gun? I've already tried to draw a small portion of the ray using the following snippet:
Ogre::ManualObject* lazor = mSceneMgr->createManualObject("lazor");
lazor->begin("HiliteYellow", Ogre::RenderOperation::OT_LINE_LIST);
// define start and end point
for (int i = 0; i< 20000;i++)
{
lazor->position(laser.getPoint(30+i));
lazor->position(laser.getPoint(300+i));
}
lazor->end();
mSceneMgr->getRootSceneNode()->attachObject(lazor);
Thanks!
If you've installed from source, or have the SDK, I'd recommend checking out SdkTrays.h - specifically, screenToScene, sceneToScreen, and getCursorRay.
HTH
The camera to viewport ray starts at your camera's position and goes through the location you clicked in your world.
If one of the three axis coordinates are the same for all your objects (all on a same plain, 2d), you can use the camera to viewport ray to determine the point where the ray intersects the plain. Then you can draw the laser from your ship to that point.
You could also use the ray to get the intersection point of the object you targeted with your cursor. That would work with a 2d and a 3d representation. Again you would draw the laser from your ship to that point.
How to use such a ray query is explained in detail here: http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Intermediate+Tutorial+3

Any way to tell what part of a WPF Ellipse shape a user has clicked on?

This may seem like a silly question, but is there some way to determine what part (say, a quadrant) of an Ellipse that a user clicked on?
Or is the only option to just figure it out based on mouse point coordinates relative to the shape itself?
I'm working on a control that allows the user to click on any part of the ellipse and drag it to resize if that helps.
Figuring out the mouse coordinates in relationship to the shape should be fairly easy. Check the X coordinate and see if it is greater than or equal to Shape.Width / 2. Then do the same with Y and Shape.Height. It should give you the correct quadrant the mouse was clicked in.
You can see in Mathworld that the general equation for an ellipse is:
.
The points within the ellipse are the ones for which the equation yields <= 1.
If the ellipse is circumscribed to a rectangle R, then:
(x0,y0) = center(R)
a = width(R)/2
b = height(R)/2
(x,y) is the clicked point.

Resources