nutkubpom152 / droidar

Automatically exported from code.google.com/p/droidar
0 stars 0 forks source link

How to add object by angle #12

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello
    From Issues 11 now I want to add textObj on ar world but Vec(...) is hard to me.
In this case.I try to put object to my left hand side. I change x,y,z value but 
it not work.
I look up for some function like 
"world.add(objectFactory.newTextObject("test3", new Vec(distanceToObj,angle,0), 
MainActivity.this,getCamera()));"
     can you help me again. thank...

Original issue reported on code.google.com by ooocoke...@gmail.com on 6 Sep 2011 at 4:39

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago

Ok I found very simple way but I don't sure is it true way.

I use simple math to get x,y position by engle and distance

public float getY(double degree,double distance){

       return (float) (Math.sin(Math.toRadians(degree))*distance);
   }

   public float getX(double degree,double distance){

       return (float) (Math.cos(Math.toRadians(degree))*distance);
   }

and use it

world.add(objectFactory.newTextObject("3", new Vec(getX(47,5),10,getY(47,5)), 
MainActivity.this,getCamera()));

It work for me. Please tell me if have another way.

                                               Thank

Original comment by ooocoke...@gmail.com on 6 Sep 2011 at 8:40

GoogleCodeExporter commented 8 years ago
You can now do it like this:

world.add(objectFactory.newTextObject("3", Vec.rotatedVecInXYPlane(5, 47), 
MainActivity.this,getCamera()));

This is how rotatedVecInXYPlane looks like:

public static Vec rotatedVecInXYPlane(float distanceInMeters,double 
angleInDegree) {        
    Vec v = new Vec(distanceInMeters, 0, 0);
    v.rotateAroundZAxis(angleInDegree);
    return v;
}

And maybe you should change MainActivity.this to myTargetActivity (this might 
avoid bugs with the Android UI later)

Original comment by simon.heinen on 7 Sep 2011 at 11:39

GoogleCodeExporter commented 8 years ago
Thakn it work for me.

Original comment by ooocoke...@gmail.com on 8 Sep 2011 at 2:26