Jump to content

Recommended Posts

Posted

Hello, here you are (My version for LE2 so you have to juste change the TVec2...):

 

float getDistance(TVec2 fVector1, TVec2 fVector2)
{
float _X = fVector2.X - fVector1.X;
float _Y = fVector2.Y - fVector1.Y;

return std::sqrt(_X * _X + _Y * _Y);
}

  • Upvote 1
You guys are going to be the death of me. Josh
Posted

Or you just can you two Vector3, with each Z value = 0

and just give X and Y for these two Vector3

 

There's no point using a 3 component vector for 2D calculations because the Z will never be used. It's the same reason we don't usually use 4 component vectors for points in 3D space.

  • Upvote 1

LE Version: 2.50 (Eventually)

Posted

Oh sorry ! Well it is strange that std::sqrt does not work since it is from the c++ standard library.

 

You can use this square root function then it should work if you dont need a very accurate precision smile.png

 

float sqrt(float x)
{
union
{
int i;
float x;
} u;
u.x = x;
u.i = (1<<29) + (u.i >> 1) - (1<<22);

u.x = u.x + x/u.x;
u.x = 0.25f*u.x + x/u.x;

return u.x;
} 

  • Upvote 1
You guys are going to be the death of me. Josh
Posted

No prob at all. I was sure it would work too but I figured there's a reason that Josh provides math functions that probably already exist in C++ and I guess compatibility is it. I'll give your latest function a shot. Thanks very much franck!

Posted

Thanks! Will try this. And thanks, YouGroove, for originally suggesting it.

 

Oh, I see what YouGroove was saying now. I thought he was saying to use Franck's code, but with three component vectors as the parameters.

 

I feel a bit silly now...

LE Version: 2.50 (Eventually)

Posted

Math functions are just provided for consistency.

 

sqrt should work, since Leadwerks calls it internally. Maybe you need to type std::sqrt() or include "Math.h" or <Math.h>?

 

 

Posted

Thanks. As you said, I tested this again in my other thread and it works. Sorry guys. My Android app definitely crashed before but I have no idea why now. I was sure at the time it was just because of adding sqrt (I didn't need to add any headers and it compiled fine on Express).

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...