...
- To demonstrate an object launch to a target point
Descriptions:
...
- To move your object towards a location,provided targeted location and current location, you can suppose your current location origin and then get the relative position of the target location in polar coordinate.
- This will give you the direction you need to travel.
- Given the speed you want the object to travel,
Stepped example : (Click mouse to step)
Processing Height 600 Width 600 final int appwidth = 600; final int appheight = 600; final float stepsize = 10; boolean demostep = false; targetedobject myobject; class targetedobject{ // This is the object to move int mcurrentx, mcurrenty; // This will store the current location of the object int mtargetx, mtargety; // This will store the target location of the object float mrotation; // This is the current orientation of this object targetedobject( int x, int y, int r ){ // Initialize with coordinate and orientation mcurrentx = x; mtargetx = x; mcurrenty = y; mtargety = y; mrotation = r; } void updatedraw(){ //Draws the shape pushMatrix(); translate( mcurrentx, mcurrenty ); rotate( mrotation ); fill( 255,0,0 ); ellipse(0, 0, 40, 40); noFill(); stroke(255); strokeWeight(5); line( -10, 0, 10, 0 ); line( 10, 0, 5, -5 ); line( 10, 0, 5, 5 ); popMatrix(); } } void setup(){ size(appwidth , appheight); background(0); myobject = new targetedobject( width / 2, height / 2, 0 ); myobject.updatedraw(); } void draw(){ }