February 04, 2012, 03:14:15 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Please report any bugs or issues that you might be encountering with the Beta in the Support System so that we can better keep track of any oustanding issues that may come up.

GameCore Support System
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Bezier curve?  (Read 863 times)
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« on: June 20, 2010, 07:10:46 AM »

hi,

i'm still working on my shmup game, i just finished my npc's pathpoint system : once created, they go from one point to another, but in a straight line.

I would like to interpolate this straight line to a curve.  I started to learn about b?zier curves and take a look at some pseudo C code but it's not easy, any help will be welcome. So nobody ever used, or try to implement this algorithm in gamecore?
Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #1 on: June 20, 2010, 07:59:07 AM »

I was just looking through the docs but don't seem to find anything, there was something about PathType but doesn't state what different ones there are
Logged
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« Reply #2 on: June 20, 2010, 08:33:34 AM »

PathType is a reference to the Gamecore's pathfinding system. It's a good one but after some tests i realize that it was not for me.
In terms of level design, it was a nightmare to create different "roads" and I couldn't control when and how much NPCs had to be generated. (take a look at the screenshot, with my path system i just need some boxes)



I know, in space, the location where npcs go to, it should not be that hard to make them move along a curve between 2 points.
Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« Reply #3 on: June 20, 2010, 05:52:45 PM »

OK, I have some ideas after reading a few articles on Wikipedia and a book  (Real-Time rendering by Akenine-Moller, Haines & Hoffman;  an excellent book for anyone interested in game development)

Here an animation from wikipedia to explain what i want to do.


I should have a working code next week.
« Last Edit: June 20, 2010, 05:55:12 PM by LutinMalefique » Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #4 on: June 21, 2010, 04:01:22 AM »

dude, you are on a high level here Smiley good luck with that stuff, curves in pathfinding is a must nad hope it can be done, noone wants path models to be edgy
Logged
gekido
Guest
« Reply #5 on: June 22, 2010, 01:21:43 PM »

The vehicle script & player script have some examples of what you are looking to do.

Instead of simply rotating the plane directly to face the new pathpoint, what you want to do is have a 'maximum turn angle' that the planes can do at once, and a 'desired turn angle'.  

The section of the character script that is relevant is this:

Code:
// find out how far our desired direction is from our current direction
if (!camMove.IsZero())
{
float rotationCos = camMove.DotProduct( mtx.ZAxis);
float rotation = acos( rotationCos);

// let the character rotate so much each turn (so we don't 'pop' to the new direction)
float maxRotation = ROTATION_SPEED * seconds;
if (rotation > maxRotation)
rotation = maxRotation;
// are we turning left or right
bool left = (camMove.CrossProduct( mtx.ZAxis).y < 0);
// apply the rotation
if (left)
mtx.RotateAxis( Vector( 0, 1, 0), -rotation);
else
mtx.RotateAxis( Vector( 0, 1, 0), rotation);
}

The vehicle script handles all movement & turning by basically simulating player input, like this:

Code:
// path finder is in control
if (pathFinder.GetWaypointCount() > 0)
{
   // find a point on our path in front of the car
   float lookAhead = -object.GetBoundingBoxMin().z + PATH_LOOK_AHEAD;

   Vector startPos = object.GetCurMatrix().T;
   startPos.y += object.GetBoundingBoxMin().y; // put the start position at the bottom of the vehicle

   // find a waypoint somewhere in front of us
   WaypointInfo waypointInfo = pathFinder.GetForwardWaypointInfo( startPos, lookAhead, true);

   // get a vector to point us in the direction of our waypoint
   waypointMove = startPos - waypointInfo.destination;
   waypointMove.Normalize();

   // figure out whether we should be turning left or right
   float turnAngle = mtx.XAxis.DotProduct( waypointMove);

   // clamp the angle to a value between -1 and 1 so we can figure out if it's a left or right turn
   turnAngle = clamp( turnAngle * PATH_TURN_SHARPNESS, -1, 1);  

   // simulate the player input by setting the 'left' or 'right' variables to get the car to turn
   if (turnAngle < 0)
      left = -turnAngle;
   else
      right = turnAngle;

}

In this case, the variable 'left' and 'right' are the equivalent of the player pressing the left or right turning buttons - and the vehicle will turn appropriately as a result.

The vehicle script also adjusts the speed of the vehicle based on the sharpness of the turn and some other details, but the relevant parts are above.

Hope this helps.
Logged
gekido
Guest
« Reply #6 on: June 22, 2010, 01:28:16 PM »

Ah, just re-read your post and realized that you are implementing your own pathfinding system instead of using the native one.

The basic principles are the same though.

1) get start position & destination position
2) figure out vector between them
3) figure out the 'desired rotation' that the object would need to do to face that direction and whether it exceeds the 'max rotation' that the object is allowed to do in a single step
4) figure out if it's a left or right turn
5) apply the rotation

repeat until object 'desired rotation' is within reasonable limits to point them in the direction of their new destination.

The only real difference is that instead of using the pathfinding waypoint system to determine the destination x,y,z coordinate you have to figure out the new destination yourself (by looking up your custom waypoint location).

The rest of the code should be hopefully enough to point you in the right direction.
Logged
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« Reply #7 on: June 25, 2010, 05:27:03 PM »

Here some news, everything is far from being fully fonctional but i made some progress (thanks to this article http://www.gamedev.net/reference/programming/features/curvessurfaces/ )

The NPC began to follow a curved path between points, but they stop before the end  Undecided
I haven't found where i'm wrong but i'm working on it.

Bezier Curves for a SHMUP
« Last Edit: June 25, 2010, 05:30:15 PM by LutinMalefique » Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« Reply #8 on: June 28, 2010, 01:50:39 PM »

i've found where i was wrong  Grin

With the code I used, NPC only read the first point of the curve, so i created an array to stock all the curve points calculated.
 Right now, the code needs some "polish" and i must do some stress test to be sure that kind of pathfinding will work for my game.
« Last Edit: June 28, 2010, 01:52:57 PM by LutinMalefique » Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
gekido
Guest
« Reply #9 on: July 01, 2010, 10:39:48 AM »

Sweet - can't wait to see how it turns out!
Logged
flim
Newbie
*
Posts: 15


View Profile
« Reply #10 on: July 01, 2010, 10:45:35 AM »

Is that similar to the "FlightControl" game on iPhone?
Logged
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« Reply #11 on: July 01, 2010, 12:27:49 PM »

@ flim
no, it will be a shoot'em up, like 1942 or DoDonpachi
History of shooting games
Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« Reply #12 on: July 18, 2010, 09:25:21 AM »

Just a short update with a video showing a working script.

Gamecore SHMUP, working B?zier spline

All boxes have a purpose : one spawn point (what NPC load, how many..), one start point (first point of the path), a final point and one or two mid points.
So to calculate the B?zier curve, three or four points are used and by moving boxes in the editor i can change the curve.
I'm not fully satisfy, it's just for showing you my progress  Wink
Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #13 on: July 18, 2010, 12:05:03 PM »

cool stuff, you are scripting champ Smiley
Logged
Jim
Jr. Member
**
Posts: 85



View Profile WWW
« Reply #14 on: July 30, 2010, 11:06:44 PM »

Looks really cool, great progress... I'm planning on beginning a Space Shooter pretty soon... Working on the details of how I want to set it up (story, characters, gameplay elements) etc...
Logged

www.gamecreation.ca - gamecore stuff.
Pages: [1]
  Print  
 
Jump to:  

 
Powered by MySQL Powered by PHP bluBlur Skin © 2006, hbSkins
Powered by SMF 1.1.14 | SMF © 2006-2011, Simple Machines LLC
Valid XHTML 1.0! Valid CSS!