Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Craazer

calculating this whit difrend way: (y + x * width)

This topic is 5768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I would need to calculate coords of 2D array like this: (y + x * width) The problem is that i need to do this also: (y + x) and after that multiply whit width, hope u know what i mean? obviously ((y + x) * width) doesnt work.

Share this post


Link to post
Share on other sites
Advertisement
It should be the sum of the horizontal offset and the product of the width and the vertical offset.

I don''t really understand the original poster''s question and/or problem, so...

Share this post


Link to post
Share on other sites
I explain better:
I have used
(x * width + y)
i have also used
(y * width + x),(x + y * width)
they ALL give the SAME result (just difrend order)

Ok
What i need to do is calculate (x + y) before anything else becose x and y are floats, u know?

Share this post


Link to post
Share on other sites
Does this have to do with operator precendence? (x * width + y) is NOT the same as (y * width + x), because multiplication takes precedence over addition, i.e the multiplication will happen before the addition. However, (y * width + x) and (x + y * width) are equivalent, for the same reason as above.

While I don''t understand why you''d need to add x and y first, or why they are floats - floating-point numbers make no sense as indices into a 2D array - the way you''d do it is put parenthesis around the addition of x and y, like (x + y). However, you already have that. If you want to truncate x and y first, cast them to integers first. I''m sorry, but I really don''t understand your problem.

Let me ask you a few questions though:
1) Why exactly do you need to add x and y first?
2) Why are x and y floating point if they are 2D array indices? Is this array supposed to be a "rough" lookup table for real-number coordinates?

Share this post


Link to post
Share on other sites
quote:
Original post by Zipster
Does this have to do with operator precendence? (x * width + y) is NOT the same as (y * width + x), because multiplication takes precedence over addition, i.e the multiplication will happen before the addition. However, (y * width + x) and (x + y * width) are equivalent, for the same reason as above.

While I don't understand why you'd need to add x and y first, or why they are floats - floating-point numbers make no sense as indices into a 2D array - the way you'd do it is put parenthesis around the addition of x and y, like (x + y). However, you already have that. If you want to truncate x and y first, cast them to integers first. I'm sorry, but I really don't understand your problem.

Let me ask you a few questions though:
1) Why exactly do you need to add x and y first?
2) Why are x and y floating point if they are 2D array indices? Is this array supposed to be a "rough" lookup table for real-number coordinates?



They need to be floats (or doubles) becose im doing rotation
now whit my current math i have 98% accurate rotation, but if i could first count the floats to gether it should be 100% accurate...

How ever, i allready have 100% accurate rotation, its just kinda slow, so this is my funky optimazation.

And please lets stay in the queston not the reason, i would in any case, like to know is it bossible.



[edited by - Craazer on December 27, 2002 9:54:26 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!