View previous topic :: View next topic |
Author |
Message |
anarky
Joined: 03 Jul 2010 Posts: 35
|
Posted: Fri Jul 30, 2010 2:53 am Post subject: toVec useless in front of compiler check |
|
|
Hi,
I try the following:
Code: | private int getRepeatHeightValue(Vec2f gridCoordinate)
{
int height;
gridCoordinate.vec2i; /////LINE A
with(gridCoordinate)
{
//deal with negative grid coordinates
if(x < 0)
x = -x;
if(y < 0)
y = -y;
//repeat the heightmap
x = x % heightmap.getWidth();
y = y % heightmap.getHeight();
height = cast(int)(heightmap[x, y][0]); /////LINE B
|
Problem: normally gridCoordinate get converted from Vec2f to Vec2i, and his values are integers LINE A. But LINE B the compiler fails with:
Quote: | yage/scene/terrain.d(308): Error: function yage.resource.image.Image.opIndex (int) does not match parameter types (float,float)
yage/scene/terrain.d(308): Error: cannot implicitly convert expression ((*__withSym).x) of type float to int
yage/scene/terrain.d(308): Error: cannot implicitly convert expression ((*__withSym).y) of type float to int |
which means that the conversion done line A is not taken into account line B. I have to recast again x and y to integer to make it work. Any idea to make it work more nicely? |
|
Back to top |
|
|
JoeCoder
Joined: 29 Oct 2005 Posts: 294
|
Posted: Mon Aug 09, 2010 9:35 pm Post subject: |
|
|
Sorry for the slow response. I've been really busy lately and neglected the forums .
vec2i() is not an in-place conversion, but returns the value. So you should do something like
gridCoordinateInt = gridCoordinate.vec2i
and then use gridCoordinateInt on LINE B. |
|
Back to top |
|
|
|