Jump to content

  • Log In with Google      Sign In   
  • Create Account

reppinfreedom

Member Since 15 Nov 2012
Offline Last Active Nov 24 2012 05:59 PM

Posts I've Made

In Topic: Angle and speed on an isometric map.

17 November 2012 - 11:50 PM

Aha... Viola! Now this should be correct in converting xyVel into a velocity and an angle... Now I should be able to solve it.
[source lang="java"] public static function xyVelToVelAngle(xyVel:Point):Object { var velAngle:Object = new Object(); var Angle:Number = Math.atan2(xyVel.y,xyVel.x); var Degrees:Number = 360 * (Angle / (2 * Math.PI)); if (Degrees < 0) { Degrees = Degrees + 360; } velAngle.Angle = Degrees-180; velAngle.Vel = Math.sqrt(xyVel.x * xyVel.x + xyVel.y * xyVel.y); return velAngle; }[/source]

Edit: Changed "velAngle.Angle = Degrees" to "velAngle.Angle = Degrees-180"... Now correct!


Those functions were a little funky... This should be more proper and readable.

[source lang="java"] public static function xyVelToVelAngle(xyVel:Point):Object { var velAngle:Object = new Object(); var Angle:Number = Math.atan2(xyVel.y,xyVel.x); var Degrees:Number = radToDeg(Angle); velAngle.Angle = Degrees; velAngle.Vel = Math.sqrt(xyVel.x * xyVel.x + xyVel.y * xyVel.y); return velAngle; } public static function angleBetweenPoints(Location:Point, Target:Point):Number { var dx:Number = Location.x - Target.x; var dy:Number = Location.y - Target.y; var Angle:Number = Math.atan2(dy,dx); var Degrees:Number = radToDeg(Angle); return Degrees; } public static function radToDeg(Radian:Number):Number { return Radian * 180 / Math.PI; } public static function degToRad(Degree:Number):Number { return Degree * Math.PI / 180; }[/source]


Ok, this is what I came up with...

[source lang="java"]public static function animationAndSpeedToNextRowCol(currentRowCol:Object, nextRowCol:Object, tileSizeX:int, tileSizeY:int):Object { var angleSpeed:Object = new Object(); var Angle:int=Math.floor(gameMath.angleBetweenPoints(rowColToPoint(currentRowCol,tileSizeX,tileSizeY),rowColToPoint(nextRowCol,tileSizeX,tileSizeY))); if (Angle == 0) { angleSpeed.Animation="l"; angleSpeed.Speed=1; } else if (Angle == 26) { angleSpeed.Animation="ul"; angleSpeed.Speed=0.707; } else if (Angle == 90) { angleSpeed.Animation="u"; angleSpeed.Speed=0.5; } else if (Angle == 153) { angleSpeed.Animation="ur"; angleSpeed.Speed=0.707; } else if (Angle == 180) { angleSpeed.Animation="r"; angleSpeed.Speed=1; } else if (Angle == -154) { angleSpeed.Animation="dr"; angleSpeed.Speed=0.707; } else if (Angle == -90) { angleSpeed.Animation="d"; angleSpeed.Speed=0.5; } else if (Angle == -27) { angleSpeed.Animation="dl"; angleSpeed.Speed=0.707; } else { angleSpeed=null; } return angleSpeed; }[/source]



Edit: Ok... I finally managed to run a test that generated the numbers for me... These are the final multipliers simplified to four decimals of accuracy.

Sideways: 1.4142
Angle: 1.118
Up/Down: 0.7071

In Topic: Angle and speed on an isometric map.

17 November 2012 - 11:38 PM

Okay... So I created a function to convert a x/y velocity into an angle...

Now, I need to solve for the velocity... It something as simple as Math.sqrt(xVel + yVel)?<br />
[source lang=&amp;amp;quot;java&amp;amp;quot;]<br />public static function xyVelToAngle(xyVel:Point):Number {<br />   var Angle:Number = Math.atan2(xyVel.y,xyVel.x);<br />   var Degrees:Number = 360 * (Angle / (2 * Math.PI));<br />   if (Degrees &amp;amp;lt; 0) {<br />    Degrees = Degrees + 360;<br />   }<br />   return Degrees;<br />  }<br />[/source]

In Topic: Angle and speed on an isometric map.

17 November 2012 - 11:17 PM

The problem is I only have one of the cartesian to polar/polar to cartesian functions I need both functions to solve this...

I need to convert the x/y velocity from the normal to isometric conversion function into speed and angle... Hmmm... *Searching.*

In Topic: Angle and speed on an isometric map.

17 November 2012 - 10:19 PM

I have conversion classes for converting between isometric and normal coordinates... I just want to keep the code lighter and faster.

If I wanted perfect accuracy I would calculate out everything on a non isometric coordinate grid. I would just set a velocity and angle... But, I want things to run faster and not require many conversions and calculations.
[source lang="java"] public static function getXyVelocity(Velocity:Number, Angle:Number):Point { var newPoint = new Point(); newPoint.x = - Velocity * Math.cos(Angle * Math.PI / 180); newPoint.y = - Velocity * Math.sin(Angle * Math.PI / 180); return newPoint; }[/source]

Then I would run a conversion to isometric velocity and angle from normal.

[source lang="java"]package Michael{public class iso3dTransformer { static var Ratio:Number=2; public static function convertToIso(screenPoint:Object):Object { var zPos:Number=screenPoint.z; var yPos:Number=screenPoint.y-screenPoint.x/Ratio+screenPoint.z; var xPos:Number=screenPoint.x/Ratio+screenPoint.y+screenPoint.z; return new Object(x:xPos,y:yPos,z:zPos); } public static function transformForDisplay(displayPoint:Object):Object { var zPos:Number=displayPoint.z; var yPos:Number=(displayPoint.x+displayPoint.y)/Ratio-displayPoint.z; var xPos:Number=displayPoint.x-displayPoint.y; return new Object(x:xPos,y:yPos,z:zPos); }}}[/source]

In Topic: Angle and speed on an isometric map.

17 November 2012 - 10:17 PM

No, that math of mine was definitely not correct... I just checked the math...

Here are the tile distances...
Horizontal:92
Vertical: 46
Angular: 51.5 Rounded, Actually: (51.42956348249516)

According to my calculations angular speed should be... 0.55978260% of Horizontal. So a multiplier of 0.56 would be correct? Hmmm... That doesn't sound right... I think I need to calculate out non isometric tile distances first to solve this easier...

PARTNERS