Pages: [1] 2 3
  Print  
Author Topic: move_towards_point  (Read 10777 times)
Offline (Female) IsmAvatar
Posted on: January 07, 2011, 04:05:11 PM

LateralGM Developer
LGM Developer
Location: Pennsylvania/USA
Joined: Apr 2008
Posts: 886

View Profile Email
Code: (C) [Select]
void motion_set(double newdir, double newspd) {
  enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
  inst->direction.rval.d = newdir;
  inst->speed.rval.d = newspd;
  inst->hspeed.rval.d = newspd * cos(newdir);
  inst->vspeed.rval.d = newspd * sin(newdir);
}

inline void move_towards_point(double x, double y, double spd) {
  motion_set(point_direction(
    ((enigma::object_planar*)enigma::instance_event_iterator->inst)->x,
    ((enigma::object_planar*)enigma::instance_event_iterator->inst)->y,
    x,y),spd);
}

motion_set was borrowed from action_move. It's just used as a convenience method to set both speed and direction efficiently. There have been some concerns over radians vs. degrees, and I haven't looked into them fully, but oddly enough action_move seemed to work...
« Last Edit: January 08, 2011, 06:09:33 PM by IsmAvatar » Logged
Offline (Male) RetroX
Reply #1 Posted on: January 07, 2011, 04:10:44 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
In addition, motion_add:
Code: (C) [Select]
void motion_add(double newdir, double newspd) {
  enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
  inst->hspeed.rval.d += newspd * cos(newdir);
  inst->vspeed.rval.d += newspd * sin(newdir);
  inst->direction.rval.d = point_direction(0, 0, inst->hspeed.rval.d, inst->vspeed.rval.d);
  inst->speed.rval.d = abs(hypot(inst->hspeed.rval.d, inst->vspeed.rval.d));
}

Untested, but it's mathematically sound.
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? :(
Offline (Male) RetroX
Reply #2 Posted on: January 07, 2011, 10:11:30 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Also, random thing to mention, but:
Code: (C) [Select]
void motion_set(double newdir, double newspd) {
  enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
  inst->direction.rval.d = newdir;
  inst->speed.rval.d = newspd;
  inst->hspeed.rval.d = newspd * cos(newdir);
  inst->vspeed.rval.d = newspd * sin(newdir);
}

inline void move_towards_point(double x, double y, double spd) {
  motion_set(point_direction(
    ((enigma::object_planar*)enigma::instance_event_iterator->inst)->x,
    ((enigma::object_planar*)enigma::instance_event_iterator->inst)->y,
    x,y),spd);
}

void motion_add(double newdir, double newspd) {
  enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
  inst->hspeed.rval.d += newspd * cos(newdir);
  inst->vspeed.rval.d += newspd * sin(newdir);
  inst->direction.rval.d = point_direction(0, 0, inst->hspeed.rval.d, inst->vspeed.rval.d);
  inst->speed.rval.d = abs(hypot(inst->hspeed.rval.d, inst->vspeed.rval.d));
}
« Last Edit: January 08, 2011, 05:34:24 PM 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? :(
Offline (Female) serprex
Reply #3 Posted on: January 08, 2011, 02:55:22 PM
Smooth ER
Developer
Joined: Apr 2008
Posts: 106

View Profile WWW
No, they shouldn't
Logged
Offline (Male) RetroX
Reply #4 Posted on: January 08, 2011, 05:34:03 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
move_towards_point should be inline, at least. :V
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 January 09, 2011, 09:41:40 AM was deleted at the author's request.
Offline (Male) RetroX
Reply #6 Posted on: January 09, 2011, 06:22:56 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
I think also did this one (move_towards_point). Is anyone actually reading this?
In GML, not C++.
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 January 10, 2011, 02:57:58 AM was deleted at the author's request.
Offline (Unknown gender) MrGriggs
Reply #8 Posted on: January 11, 2011, 03:44:14 AM

Member
Joined: Dec 2010
Posts: 128

View Profile Email
Also, random thing to mention, but:
Code: (C++) [Select]
void motion_set(double newdir, double newspd) {
  enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
  inst->direction.rval.d = newdir;
  inst->speed.rval.d = newspd;
  inst->hspeed.rval.d = newspd * cos(newdir);
  inst->vspeed.rval.d = newspd * sin(newdir);
}

inline void move_towards_point(double x, double y, double spd) {
  motion_set(point_direction(
    ((enigma::object_planar*)enigma::instance_event_iterator->inst)->x,
    ((enigma::object_planar*)enigma::instance_event_iterator->inst)->y,
    x,y),spd);
}

void motion_add(double newdir, double newspd) {
  enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
  inst->hspeed.rval.d += newspd * cos(newdir);
  inst->vspeed.rval.d += newspd * sin(newdir);
  inst->direction.rval.d = point_direction(0, 0, inst->hspeed.rval.d, inst->vspeed.rval.d);
  inst->speed.rval.d = abs(hypot(inst->hspeed.rval.d, inst->vspeed.rval.d));
}

Tried to use move towards point from this, and my word it's CRAAAAAAAZZZZZZYYYY, have you tested it?
Logged
Offline (Unknown gender) r9k
Reply #9 Posted on: January 11, 2011, 08:43:15 AM
Member
Joined: Aug 2010
Posts: 25

View Profile
Probably because hes giving a non radian angle to sin and cos.
Logged
Offline (Male) RetroX
Reply #10 Posted on: January 11, 2011, 04:14:14 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Yeah, it is.  Updated:
Code: [Select]
void motion_set(double newdir, double newspd) {
  enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
  inst->direction.rval.d = newdir;
  inst->speed.rval.d = newspd;
  inst->hspeed.rval.d = newspd * cos(degtorad(newdir));
  inst->vspeed.rval.d = newspd * sin(degtorad(newdir));
}

inline void move_towards_point(double x, double y, double spd) {
  motion_set(point_direction(
    ((enigma::object_planar*)enigma::instance_event_iterator->inst)->x,
    ((enigma::object_planar*)enigma::instance_event_iterator->inst)->y,
    x,y),spd);
}

void motion_add(double newdir, double newspd) {
  enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
  inst->hspeed.rval.d += newspd * cos(degtorad(newdir));
  inst->vspeed.rval.d += newspd * sin(degtorad(newdir));
  inst->direction.rval.d = point_direction(0, 0, inst->hspeed.rval.d, inst->vspeed.rval.d);
  inst->speed.rval.d = abs(hypot(inst->hspeed.rval.d, inst->vspeed.rval.d));
}

Suggestion: point_direction_radians
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? :(
Offline (Male) polygone
Reply #11 Posted on: January 11, 2011, 04:18:44 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 803

View Profile
Quoting Ism:
Quote
There have been some concerns over radians vs. degrees, and I haven't looked into them fully, but oddly enough action_move seemed to work...

Because of the way rval.d works, the code is correct without degtorad. This got me too.
« Last Edit: January 11, 2011, 04:23:43 PM by polygone » Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Male) RetroX
Reply #12 Posted on: January 11, 2011, 04:49:46 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
oh, well, ignore what I posted, then
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? :(
Offline (Male) Josh @ Dreamland
Reply #13 Posted on: January 11, 2011, 07:16:55 PM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2934

View Profile Email
Actually, I have no idea why the fuck Ism's implementation works. direction.rval.d is in degrees. Or at least it's supposed to be. There is the possibility that it is only in degrees when it is the last variable set.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) MrGriggs
Reply #14 Posted on: January 12, 2011, 04:22:36 AM

Member
Joined: Dec 2010
Posts: 128

View Profile Email
Have any of these been tested and found to function as desired?
Logged
Pages: [1] 2 3
  Print