-
Notifications
You must be signed in to change notification settings - Fork 2
Create the block "GoToCruizCore(x,y)" #13
Comments
Comparing 2 ways to calculate the distance: // Calculate distance to travel:
float distance;
if(y1 != 0)
distance = y1/(float)Math.sin(angle);
else
distance = x1/(float)Math.cos(angle); Atmel NanoVM float dist = Math.sqrt(dx*dx+dy*dy); |
It is necessary to check some cases, example: atan2(50,0); |
Adding a new Atan2 Block implementation based on the ideas from Volkan Salma Adding a TestSuite to test the implementation in relation to MDN Reference for Math.atan2 #17 Adding a Block to convert Radians to Degrees #25 [Core] Finishing GoToCruizCoreXY. It is necessary to debug some Pose update from every Movement. #13
Some notes about to calculate the distance: destinationHeading = atan2((yt-yc), (xt-xc)); //calculate turning angle
destinationHeading = destinationHeading * 180/3.1415; //convert to degrees
turnAngle = destinationHeading - currentHeading;
if (turnAngle > 180) {
turnAngle = turnAngle-360;
}
if (turnAngle < -180) {
turnAngle = turnAngle+360;
} |
https://github.com/Luncher/path-animation/blob/master/lib/soya_core.js |
https://github.com/DragicD/funlearner/blob/develop/literatura/Section%201%20-%20Classic%20Game%20Steps/6-rtsGame/rtsGame-step4/js/Unit.js |
http://www.gamefromscratch.com/post/2012/11/18/GameDev-math-recipes-Rotating-to-face-a-point.aspx var angle = Math.atan2(stage.mouseY - jetSprite.y, stage.mouseX - jetSprite.x );
angle = angle * (180/Math.PI);
// The following if statement is optional and converts our angle from being
// -180 to +180 degrees to 0-360 degrees. It is completely optional
if(angle < 0)
{
angle = 360 - (-angle);
}
// Atan2 results have 0 degrees point down the positive X axis, while our image is pointed up.
// Therefore we simply add 90 degrees to the rotation to orient our image
// If 0 degrees is to the right on your image, you do not need to add 90
rotation =90 + angle; |
http://dev.bennage.com/blog/2013/03/05/game-dev-03/ function getAngle(x,y,orientation){
// alias (and pre-compute) the angle of
// a full circle (360°, but in radians)
var fullCircle = Math.PI * 2;
// what's the different between our orientation
// and the angle we want to face in order to
// move directly at our target
var angle = Math.atan2(y, x);
var delta = angle - orientation;
var delta_abs = Math.abs(delta);
// if the different is more than 180°, convert
// the angle a corresponding negative value
if (delta_abs > Math.PI) {
delta = delta_abs - fullCircle;
}
// if the angle is already correct,
// don't bother adjusting
if (delta !== 0) {
// do we turn left or right?
var direction = delta / delta_abs;
// update our orientation
orientation += (direction * Math.min(delta_abs, delta_abs));
}
// constrain orientation to reasonable bounds
orientation %= fullCircle;
return orientation;
} |
var diffAngle:Number = Math.atan2(Math.sin(angleTo – currentAngle), Math.cos(angleTo – currentAngle)); |
It is necessary to create a Block which it accept a final point as an Input Parameter. Internally, the block use current pose to calculate:
The idea is to execute the following example:
http://www.lejos.org/rcx/tutorial/navigation/index.html
The text was updated successfully, but these errors were encountered: