IsmAvatar
|
|
Posted on: January 07, 2011, 04:05:11 pm |
|
|
LateralGM Developer
Location: Pennsylvania/USA Joined: Apr 2008
Posts: 877
|
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
|
|
|
|
RetroX
|
|
Reply #1 Posted on: January 07, 2011, 04:10:44 pm |
|
|
Master of all things Linux
Location: US Joined: Apr 2008
Posts: 1055
|
In addition, motion_add:
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)Why do all the pro-Microsoft people have troll avatars?
|
|
|
RetroX
|
|
Reply #2 Posted on: January 07, 2011, 10:11:30 pm |
|
|
Master of all things Linux
Location: US Joined: Apr 2008
Posts: 1055
|
Also, random thing to mention, but:
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)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.
|
|
Post made January 10, 2011, 02:57:58 am was deleted at the author's request.
|
MrGriggs
|
|
Reply #8 Posted on: January 11, 2011, 03:44:14 am |
|
|
Joined: Dec 2010
Posts: 128
|
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
|
|
|
|
|
RetroX
|
|
Reply #10 Posted on: January 11, 2011, 04:14:14 pm |
|
|
Master of all things Linux
Location: US Joined: Apr 2008
Posts: 1055
|
Yeah, it is. Updated:
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)Why do all the pro-Microsoft people have troll avatars?
|
|
|
polygone
|
|
Reply #11 Posted on: January 11, 2011, 04:18:44 pm |
|
|
Location: England Joined: Mar 2009
Posts: 794
|
Quoting Ism: 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.
|
|
|
|
Josh @ Dreamland
|
|
Reply #13 Posted on: January 11, 2011, 07:16:55 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
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
|
|
|
|
|