Pages: 1 [2] 3
  Print  
Author Topic: move_towards_point  (Read 10344 times)
Offline (Male) RetroX
Reply #15 Posted on: January 12, 2011, 08:24:59 AM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Nope. :P
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 #16 Posted on: January 12, 2011, 12:34:30 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 809

View Profile
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.
Funny you said that to me when I mentioned it. But then Ism quite rightly pointed out that you were actually the one who used that code first:

I'm actually too tired and lazy right now to do the trivial amount of text insertion required to put that to code. >.<

-sigh-

Code: (C) [Select]
const double dir = ((enigma::object_planar*)enigma::instance_event_iterator->inst)->direction.dval = chosendirs[choices];
((enigma::object_planar*)enigma::instance_event_iterator->inst)->speed.dval = chosendirs[choices] == -1 ? 0 : argspeed;
hspeed.dval = speed.dval * cos(dir), vspeed.dval = speed.dval * sin(dir);

Assuming all the rest of your code is right, and that I'm remembering the name of my own class member correctly.
She doesn't know why the fuck it works either
« Last Edit: January 15, 2011, 07:10:57 AM by polygone » Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Unknown gender) MrGriggs
Reply #17 Posted on: January 14, 2011, 08:10:35 PM

Member
Joined: Dec 2010
Posts: 128

View Profile Email
All of these make it run away from the position rather than move towards as it's supposed to.

Here's a corrected version.
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));
}



"inst->vspeed.rval.d = -newspd * sin(degtorad(newdir));"

making it negative corrects the issue. :)
Logged
Offline (Unknown gender) MrGriggs
Reply #18 Posted on: January 20, 2011, 12:54:02 PM

Member
Joined: Dec 2010
Posts: 128

View Profile Email
Code: [Select]
inline void move_point_stop(double x, double y, double spd) {

    enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
    if (inst->x==x && inst->y==y)
return void;
else
{

  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);

}



}




How do you like these apples? Or are they dysfunctional apples?
Logged
Offline (Female) IsmAvatar
Reply #19 Posted on: January 20, 2011, 02:05:35 PM

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

View Profile Email
When you introduce the inst variable, you shouldn't keep it inline anymore I don't think, and it's redundant to return void to a void returning function. Also, indentation. This would be more likely:

Code: (C) [Select]
void move_point_stop(double x, double y, double spd) {
  enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
  if (inst->x!=x || inst->y!=y)
    motion_set(point_direction(inst->x,inst->y,x,y),spd);
}

Or this:
Code: (C) [Select]
inline void move_point_stop(double x, double y, double spd) {
  if (((enigma::object_planar*)enigma::instance_event_iterator->inst)->x!=x
  ||  ((enigma::object_planar*)enigma::instance_event_iterator->inst)->y!=y)
    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);
}

In addition, this doesn't stop when it has reached the point. It only ceases to set the motion. Recall that an object in motion continues to stay in motion until acted upon.

Append this prior to the last closing curly brace:
Code: (C) [Select]
else ((enigma::object_planar*)enigma::instance_event_iterator->inst)->speed = 0;Or if you already have inst defined:
Code: (C) [Select]
else inst->speed = 0;
« Last Edit: January 20, 2011, 02:08:44 PM by IsmAvatar » Logged
Offline (Unknown gender) MrGriggs
Reply #20 Posted on: January 21, 2011, 06:36:09 AM

Member
Joined: Dec 2010
Posts: 128

View Profile Email
Ah yeah, I forgot hspeed and vspeed doesn't cease until instructed to.
« Last Edit: January 21, 2011, 11:36:57 AM by MrGriggs » Logged
Post made January 21, 2011, 10:44:44 AM was deleted at the author's request.
Offline (Unknown gender) MrGriggs
Reply #22 Posted on: January 24, 2011, 04:21:05 AM

Member
Joined: Dec 2010
Posts: 128

View Profile Email
Ugh.
You've done this in EDL, already?

It needs to be done in C++ so that it can be compiled directly into ENIGMA though, doesn't it?  :v:
Logged
Offline (Unknown gender) MrGriggs
Reply #23 Posted on: January 24, 2011, 04:24:12 AM

Member
Joined: Dec 2010
Posts: 128

View Profile Email
Another thought, isn't it best if the functions don't use other function to complete their tasks, as when the time comes to allow the user to remove particular functions from instances and checks, removing something such as motion_set but not move_towards_point then using the latter, will cause issues for the user, and they probably will have no idea what the issue is...
Logged
Post made January 24, 2011, 09:50:10 AM was deleted at the author's request.
Offline (Unknown gender) MrGriggs
Reply #25 Posted on: January 24, 2011, 11:47:20 AM

Member
Joined: Dec 2010
Posts: 128

View Profile Email
Oh ok, that's good then. Shouldn't your version have been implemented already then?

Also, about my other post, you have any answers for that?  ???
Logged
Offline (Female) IsmAvatar
Reply #26 Posted on: January 24, 2011, 12:13:44 PM

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

View Profile Email
I don't see a reason to disable motion_set while keeping move_towards_point. It seems to me that if you want to disable one, you'll want to disable the other as well (e.g. bulk removal of motion-related functions). That said, if you still wanted to disable motion_set but keep move_towards_point, you might be able to set motion_set to be private access, so that it's not visible to outside files (this might just be Java rubbing off on me)... but there's not much use in that, because the function is still there, it's just not visible anymore - in which case you might as well just keep the function and not use it. Point is, move_towards_point needs motion_set one way or the other, whether it's in a function called motion_set, or unrolled. The benefit of using motion_set is that it eliminates duplicate code.
Logged
Offline (Male) RetroX
Reply #27 Posted on: January 24, 2011, 04:49:03 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
IsmAvatar - C++ doesn't allow setting access to globals.  All globals are public.  Only members of structs and classes can be set with access specifiers.

What could be done is merely not including the code for that header in the game, or just not linking the object.  If the header provides a declaration and no implementation is provided, it will still compile as long as the function isn't being used.  Alternatively, you can add these flags to the GCC:
-fdata-sections -ffunction-sections
which compiles everything into separate sections in the actual object, and:
-Wl,-gc-sections
which will remove unused sections from the program upon linking.

On that matter, for debugging purposes, it would be nice to be able to add -g -O0, which will provide C++ debugging symbols, which GDB can use.  It's extraordinarily useful.
« Last Edit: January 24, 2011, 04:56:08 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? :(
Post made January 25, 2011, 04:54:29 AM was deleted at the author's request.
Offline (Unknown gender) MrGriggs
Reply #29 Posted on: January 25, 2011, 05:26:51 AM

Member
Joined: Dec 2010
Posts: 128

View Profile Email
C# is pretty similar in many ways, but in many ways it also is not. Action Script is compleeeetely different in my opinion, i HATE the syntax of it, it's so backward (my opinion).

Maybe there's justification for the backward syntax, but i haven't looked into it, if you use it, i'm sure it has it's uses.
Logged
Pages: 1 [2] 3
  Print