A couple of possible issues come to my mind: * Did you make sure that your compass is calibrated? (figure 8 in the air with the phone several times in various directions) * Are you far enough away from computers, steel, loudspeakers, or other objects that may deflect magnetic field lines (and thus alter the compass readings)? * For a change portrait -> landscape, it would make more sense to remap x and y coordinates by 90 degrees, rather than swap x and z coordinates, like SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X,
If all of these don't help, it is more efficient to print out (logcat) the sensor values, and try to solve one problem at a time (like, first get the correct orientation values from the compass, and if that works, then look into your projection routine), rather than solving the whole stack of possible error sources at once. Good luck :-) Peli On Aug 20, 7:02 pm, mscwd01 <[email protected]> wrote: > I should add I am holding the phone horizontally (as you would when > taking a photo). > > As such I modify the sensor values like: > > SensorManager.getRotationMatrix(R, I, accels, mags); > SensorManager.remapCoordinateSystem(R,SensorManager.AXIS_X, > SensorManager.AXIS_Z, outR); > SensorManager.getOrientation(outR, values); > > I'm assuming thats the correct way to do it. > > On Aug 20, 6:00 pm, mscwd01 <[email protected]> wrote: > > > The main problem is when I use the values returned by the sensor > > manager "as is" i.e. not modifying them in any way, the points are no > > where near where they should be. For example, say the point I wish to > > project is due north of my current location and at the same elevation. > > I shouldn't need to tilt (pitch) the phone up or down and when I hold > > the phone in the direction of north it should appear somewhere near > > the center of the phone screen. However, this is not the case, in > > reality for the point to appear on the center of the screen I need to > > do something like tilt the phone at the ground and orient it in a > > easterly direction for example. > > > I have made a nasty fix which means I subtract 90 from the roll or add > > 45 degrees to the pitch etc. However while this now projects the point > > on the center of the screen it ruins the projections of any other > > points (as I have fundamentally altered the sensor values). In my > > current implementation a point north of me may work but any points to > > the south do not work. > > > My problem is probably something to do with the coordinates of the > > phone differing from my projected coordinates, but making the two > > "work" together is causing me some serious headaches. > > > I can send you my projection code if it helps, I have really exhausted > > all ideas to solve my issue! > > > Thanks for the reply > > > On Aug 20, 5:15 pm, Peli <[email protected]> wrote: > > > > > however, I can never seem to get accurate screen coordinates > > > > of the points. > > > > Could you specify what exactly your problem is? > > > Does it not work *at all*, or does it work basically, but points are > > > off by a few degrees? Or does it only work in one orientation of the > > > device (like in landscape mode), and fails in other orientations? > > > > Peliwww.openintents.orghttp://code.google.com/p/openintents/wiki/SensorSi... > > > > On Aug 20, 4:55 pm, mscwd01 <[email protected]> wrote: > > > > > Hi, > > > > > I want to find the screen coordinates (X,Y) where a point represented > > > > by a latitude/longitude value would appear on the screen if you > > > > pointed your phone at it (much in the same way as Wikitude does). > > > > > Here is my code from my onSensorChanged() method: > > > > > public void onSensorChanged(SensorEvent event) { > > > > Sensor sensor = event.sensor; > > > > int type = sensor.getType(); > > > > > switch (type) { > > > > case Sensor.TYPE_MAGNETIC_FIELD: > > > > mags = event.values.clone(); > > > > isReady = true; > > > > break; > > > > case Sensor.TYPE_ACCELEROMETER: > > > > accels = event.values.clone(); > > > > break; > > > > case Sensor.TYPE_ORIENTATION: > > > > orients = event.values.clone(); > > > > break; > > > > } > > > > > if (mags != null && accels != null && isReady) { > > > > isReady = false; > > > > > SensorManager.getRotationMatrix(R, I, accels, mags); > > > > SensorManager.remapCoordinateSystem(R, > > > > SensorManager.AXIS_X, SensorManager.AXIS_Z, outR); > > > > SensorManager.getOrientation(outR, values); > > > > > azimuth = convert.radToDeg(values[0]); > > > > pitch= convert.radToDeg(values[1]); > > > > roll = convert.radToDeg(values[2]); > > > > > } > > > > > } > > > > > I convert the points I wish to project from their lat/lon spherical > > > > coordinates to Cartesian coordinates and perform a perspective > > > > projection using the roll, pitch and azimuth values returned by the > > > > sensor, however, I can never seem to get accurate screen coordinates > > > > of the points. > > > > > The matrices for roll, pitch and azimuth I use are: > > > > > // pan > > > > double[][] azimuthMat = { > > > > {Math.cos(azimuthValue), -Math.sin(azimuthValue), 0}, > > > > {Math.sin(azimuthValue), Math.cos(azimuthValue), 0}, > > > > {0, 0, 1},}; > > > > > // tilt > > > > double[][] pitchMat = { > > > > {Math.cos(pitchValue), 0, Math.sin(pitchValue)}, > > > > {0, 1, 0}, > > > > {-Math.sin(pitchValue), 0, Math.cos(pitchValue)}, > > > > }; > > > > // roll > > > > double[][] rollMat = { > > > > {1, 0, 0}, > > > > {0, Math.cos(rollValue), -Math.sin(rollValue)}, > > > > {0, Math.sin(rollValue), Math.cos(rollValue)}, > > > > }; > > > > > I also perform the necessary translation of the projection cener and > > > > the point to project e.g: > > > > > // Translate the point > > > > subtract(pointToProject, projectionCenter); > > > > ... where 'pointToProject' and 'projectionCenter' are double arrays > > > > holding the Cartesian coordinates of each location (i.e. camera lat/ > > > > lon and the point to project lat/lon) > > > > > I realise this is quite a complicated question to ask and I haven't > > > > provided all my projection code etc, however if someone feels they can > > > > help me out and may know how to achieve what i'm after - i'll post the > > > > whole code. > > > > > Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

