• Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

We're also offering banner ads on our site from just \$5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

Member Since 01 Feb 2004
Offline Last Active Feb 21 2014 12:08 PM

### Rotate to face a direction, by applying angular acceleration?

16 December 2013 - 12:41 PM

This seems like it should be simple, but I've been struggling with it for a while.

I have a starship that has an associated ODE body. I'm trying to get the starship to follow a path. So I calculate the desired heading as a vector.

The problem is I need to find the angular force to apply (as a vector) to rotate the ship from its current heading (forward vector) to face the desired heading.

Could someone explain how to calculate that angular force?

### Using a PID controller for heading, what error value to use?

13 December 2013 - 02:22 AM

I'm working on some basic AI for a fighter game, and I'm trying to get the ships to fly into a formation. To calculate the amount of torque I need to apply to each ship so that it turns towards the desired heading I'm using a PID controller very similar to the one in the first answer here: http://answers.unity3d.com/questions/199055/addtorque-to-rotate-rigidbody-to-look-at-a-point.html

So, I have the current heading of the ship, and the desired heading, and I need to pass an error value into the PID controller so that it can correct the heading.

In the linked example, the poster uses the cross product of the desired heading and current heading. This works perfectly if the angle between the headings is < 90 degrees, if it's greater than 90 degrees then the cross product is flipped and the PID controller starts correcting to the opposite direction than I want!

I'm struggling to figure out what vec3 error value will work in all cases, even if there is a large angle between the desired and actual heading. Any ideas?

### Kazmath, a C math library

14 August 2008 - 02:06 AM

Hi all, For a while now I've been building up a little 3D math library written in C. Recently Carsten (the other NeHe maintainer, and general math genius) has been contributing too. Its NOT FINISHED and hasn't been tested thoroughly (unit tests are next on our list) but if any of you feel inclined I would appreciate feedback, patches, suggestions, feature requests etc. You can find it under browsable GIT version control here: http://github.com/Kazade/kazmath/tree/master Currently there are only build files for Linux using cmake, (that is only because I haven't got round to writing a cmake file for Windows yet, if anyone fancies implementing one, feel free), there are no other dependencies. Any patches should be sent to kazade AT gmail Dot Com with the subject "Kazmath" or "Patch" or something. Let me know what you think [smile] Luke. PS. I am aware that git doesn't easily work on Windows, so when I have time I will migrate to a more Windows-friendly version control system.

### Templates and variable names

14 January 2008 - 07:04 AM

Hi, I've had an idea on the train home for my engine, but before I get too carried away with it I'd like to know if something is possible with C++ templates... Imagine I have a class like this:
```template< typename T, typename U >
class MyClass {
public:
T var1;
U var2;
};
```
When I instantiate it I can do something like this:
```MyClass<House, Car> someInstance;
//here I can access someInstance.var1
```
What I want to do is name the member variables using some kind of ID from the passed in objects. So, for example..
```template<typename T, typename U>
class MyClass {
T  T::someID; //someID here is house when instantiated below
U  U::someID; //someID here is car
};

MyClass<House, Car> someInstance;
//here I can access someInstance.house and someinstance.car
```
Now, I want to use this for something a lot more complicated than that, but that's the simple case that I want to achieve. I could do something using a map<string, boost::any> and do someInstance.m_map["car"] but I want to move the lookup from runtime to compile time. I know this must be possible (or something equivalent) somehow, I just don't know how [smile]

### Function objects, mem_fun, boost::function etc.

04 December 2007 - 10:17 AM

Hi, I'm having some trouble understanding/using mem_fun and bind1st to pass a member function into a function that requires a function pointer as an argument. I have a constructor that looks like this:
```ConsoleCommand(const string& command,
CommandReturn (*handler)(Console*, const vector<string>& args),
const string& usageText = string());
```
Now, if I create a "ConsoleCommand" using a static method for the second arg, it works fine. I have another class which has a function that looks like this:
```CommandReturn Game::showFPS(Console*, const vector<string>& args);
```
I want to pass this as the 2nd parameter to the ConsoleCommand constructor, but bind the Game 'this' pointer as the 'this' instance of the showFPS function. I thought that this is what I needed to do:
```ConsoleCommand(someConsole, bind1st(mem_fun(&Game::showFPS), this))
```
But it gives me a compiler error, I've also had a play with boost::function and boost::bind but I couldn't figure out a combination that worked. Can someone point me in the right direction? and explanation of how this stuff works behind the scenes would be cool. Thanks Luke.

PARTNERS