Pages: 1
  Print  
Author Topic: Fede-lasse's functions  (Read 11473 times)
Offline (Male) RetroX
Posted on: March 12, 2011, 10:59:21 am

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Because he didn't post them in their own topic, and I can't move topics:

Code: [Select]
//bool place_snapped(double hsnap,double vsnap)
bool place_snapped(double hsnap,double vsnap) {
  return (bool)(X == X%hsnap) && (Y == Y%vsnap);
}

//int move_random(double hsnap,double vsnap)
int move_random(double hsnap,double vsnap) {
  X = floor(random(room_width)/hsnap)*hsnap;
  Y = floor(random(room_height)/vsnap)*vsnap;
  return (int)0;
}

//int move_snap(double hsnap,double vsnap)
int move_snap(double hsnap,double vsnap) {
  X = floor(X/hsnap)*hsnap;
  Y = floor(Y/vsnap)*vsnap;
  return (int)0;
}

//int move_wrap(double hor,double vert,double margin)
int move_wrap(double hor,double vert,double margin) {
  //not sure whether two IFs are faster than one big calculation in a single IF
  if (hor) {
    if (X < -margin || X > room_width+margin) {
      X = -(X-room_width);
    }
  }
  if (vert) {
    if (Y < -margin || Y > room_height+margin) {
      Y = -(Y-room_height);
    }
  }
  return (int)0;
}

//int move_towards_point(double x,double y,double sp)
int move_towards_point(double x,double y,double sp) {
  DIRECTION = point_direction(X,Y,x,y);
  SPEED = sp;
  return (int)0;
}

Note that these functions have already been committed (in working forms), but I'll post them anyways:
Code: [Select]
//double distance_to_point(double x,double y)
double distance_to_point(double x,double y) {
  return (double)point_distance(median(BBOX_LEFT,x,BBOX_RIGHT),median(BBOX_TOP,y,BBOX_BOTTOM),x,y);
}

//double distance_to_object(int obj)
double distance_to_object(int obj) {
  double _edgeX,_edgeY;
  _edgeX = median(BBOX_LEFT,obj.X,BBOX_RIGHT);
  _edgeY = median(BBOX_TOP,obj.Y,BBOX_BOTTOM);
  if (_edgeX > obj.BBOX_LEFT && _edgeX < obj.BBOX_RIGHT && _edgeY > obj.BBOX_TOP && _edgeY < obj.BBOX_BOTTOM) {
    return (double)0;
  }
  return (double)point_distance(_edgeX,_edgeY,median(obj.BBOX_LEFT,X,obj.BBOX_RIGHT),median(obj.BBOX_TOP,Y,obj.BBOX_BOTTOM));
}
« Last Edit: March 12, 2011, 11:18:50 am by RetroX » Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Post made March 14, 2011, 03:26:20 am was deleted at the author's request.
Offline (Male) RetroX
Reply #2 Posted on: March 14, 2011, 08:34:29 pm

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Yeah, but I figured that I'd let everyone who was viewing the topic know.  I felt like it would have been kind of rude to just omit them altogether.
Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Pages: 1
  Print