FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

toVec useless in front of compiler check

 
Post new topic   Reply to topic     Forum Index -> Yage
View previous topic :: View next topic  
Author Message
anarky



Joined: 03 Jul 2010
Posts: 35

PostPosted: Fri Jul 30, 2010 2:53 am    Post subject: toVec useless in front of compiler check Reply with quote

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
View user's profile Send private message
JoeCoder



Joined: 29 Oct 2005
Posts: 294

PostPosted: Mon Aug 09, 2010 9:35 pm    Post subject: Reply with quote

Sorry for the slow response. I've been really busy lately and neglected the forums Sad.

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Yage All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group