Changing nEdge1 and nEdge2 to floats was one of the first things I tried, but it still came out as 0 so I changed back to ints. The conditional checks to see if the number is between 0 and 1, I guess I wasn''t thinkin'' too straight
I''m not sure if the edge 2 (or t) equation is right or not.
I wrote the conditional hastily, but it should be:
if (nEdge1 < 0 || nEdge2 < 0 || (nEdge1 + nEdge2) > 1)
// Not contained
Heightmapping and Tile Selection
Hmm, it shouldn''t be coming out as 0. You''re doing something very wrong then. Have you had a look through with a debugger, to see what values the variables have? Changing the edge variables to floats won''t fix it by the way, you have to make the division floating-point as well. If you leave it as integers, it''ll always do rounding.
Another thing: does it give you something other than 0 if you click outside the tile?
- JQ
Full Speed Games. Period.
Another thing: does it give you something other than 0 if you click outside the tile?
- JQ
Full Speed Games. Period.
I tried putting parenthesis around the whole thing when casting to float, and s and t aren''t always 0 anymore. Just some of the expression was being converted to a float, I guess.
But now, the conditional is failing TOO much I tried clicking on tiles a few dozen times, and only a couple of times the containment check on the first triangle would succeed. The triangle 2 test always failed. I noticed that s is almost always negative. I tried changing the calculation for the vectors in the second check to:
ptVector1.x = ptRightSide.x - ptTopSide.x;
ptVector1.y = ptRightSide.y - ptTopSide.y;
ptVector2.x = ptRightSide.x - ptBottomSide.x;
ptVector2.y = ptRightSide.y - ptBottomSide.y;
Since the coordinates for the right side are greater then the top and bottom (at least for x) the vectors were always negative before. This change caused the second triangle test to succeed a lot more, and the tile clicking was more accurate. I''m going to try changing all vector calculations so the lower number is subtracted from the greater number (resulting in positive vectors) - maybe this will result in more accurate calculations:
Triangle 1:
ptVector1.x = ptTopSide.x - ptLeftSide.x;
ptVector1.y = ptLeftSide.y - ptTopSide.y;
ptVector2.x = ptBottomSide.x - ptLeftSide.x;
ptVector2.y = ptBottomSide.y - ptLeftSide.y;
Triangle 2:
ptVector1.x = ptRightSide.x - ptTopSide.x;
ptVector1.y = ptRightSide.y - ptTopSide.y;
ptVector2.x = ptRightSide.x - ptBottomSide.x;
ptVector2.y = ptBottomSide.y - ptRightSide.y;
I''ll tell you how this works.
But now, the conditional is failing TOO much I tried clicking on tiles a few dozen times, and only a couple of times the containment check on the first triangle would succeed. The triangle 2 test always failed. I noticed that s is almost always negative. I tried changing the calculation for the vectors in the second check to:
ptVector1.x = ptRightSide.x - ptTopSide.x;
ptVector1.y = ptRightSide.y - ptTopSide.y;
ptVector2.x = ptRightSide.x - ptBottomSide.x;
ptVector2.y = ptRightSide.y - ptBottomSide.y;
Since the coordinates for the right side are greater then the top and bottom (at least for x) the vectors were always negative before. This change caused the second triangle test to succeed a lot more, and the tile clicking was more accurate. I''m going to try changing all vector calculations so the lower number is subtracted from the greater number (resulting in positive vectors) - maybe this will result in more accurate calculations:
Triangle 1:
ptVector1.x = ptTopSide.x - ptLeftSide.x;
ptVector1.y = ptLeftSide.y - ptTopSide.y;
ptVector2.x = ptBottomSide.x - ptLeftSide.x;
ptVector2.y = ptBottomSide.y - ptLeftSide.y;
Triangle 2:
ptVector1.x = ptRightSide.x - ptTopSide.x;
ptVector1.y = ptRightSide.y - ptTopSide.y;
ptVector2.x = ptRightSide.x - ptBottomSide.x;
ptVector2.y = ptBottomSide.y - ptRightSide.y;
I''ll tell you how this works.
It took a while for me to get back here... my isp is having trouble.
Unfortunately, my idea didn''t work. I''m still not getting accurate results. Could you check the t calculation for me?
Thanks for hanging with me for so long
Unfortunately, my idea didn''t work. I''m still not getting accurate results. Could you check the t calculation for me?
Thanks for hanging with me for so long
Just a quickie, but:
I think t should be:
t = (v0.y * m.x - v0.x * m.y - v0.y * p0.x + v0.x * p0.y) / (v0.y * v1.x - v0.x * v1.y)
But I''ll check it later on.
Are you getting sensible values for s by the way?
- JQ
Full Speed Games. Period.
I think t should be:
t = (v0.y * m.x - v0.x * m.y - v0.y * p0.x + v0.x * p0.y) / (v0.y * v1.x - v0.x * v1.y)
But I''ll check it later on.
Are you getting sensible values for s by the way?
- JQ
Full Speed Games. Period.
Both s and t appears to be sensible values, although t tends to have more extreme numbers in both directions.
I''ll try you expression tonight.
I''ll try you expression tonight.
Yay! I tried your calc for t - it works like a charm now!
Thanks
[edited by - JonWoyame on September 25, 2002 6:20:53 PM]
Thanks
[edited by - JonWoyame on September 25, 2002 6:20:53 PM]
Glad you could finally get it working.
You know, if you align vector 0 and 1 to map coordinates (i.e. v0 is along map x, v1 is along map y or vice versa) you get sub-tile correct map coordinates. Just add s to the x map coordinate of the tile, and t to the y map coordinate, and you get map coordinates like (13.6, 6.26) - that can be very useful...
- JQ
Full Speed Games. Period.
You know, if you align vector 0 and 1 to map coordinates (i.e. v0 is along map x, v1 is along map y or vice versa) you get sub-tile correct map coordinates. Just add s to the x map coordinate of the tile, and t to the y map coordinate, and you get map coordinates like (13.6, 6.26) - that can be very useful...
- JQ
Full Speed Games. Period.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement