• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
AvengerDr

B-Spline sampling

2 posts in this topic

Hi all,

I've built an algorithm that displays a B-Spline. I'm not sure if it is working correctly. For example, take this picture:

 

C5RNkwd.png

 

the red points are the control points and the blue points are the various points on the curve. Each blue point is calculated through a fixed timestep. The Knot vector of this (clamped) curve is [0 0 0 0 0.5 1 1 1 1] and it is calculated using DeBoor's function in the interval [alpha, 1-alpha]. In this clamped case the first and last control points are added back at the end (though there might be some issues with the control points being drawn at their top left corner instead of their center, but it shouldn't matter).

 

As you can notice, the points towards the first and last control point appear to be more "sparse". I would explain this by it being due to the other control points concentrating the curve in the upper part as the number of points to calculate is constant (100, with alpha incrementing by 0.01).

 

Are there better ways to sample the curve in order to have a constant displacement between curve segments?

Edited by AvengerDr
0

Share this post


Link to post
Share on other sites

What you want is "constant arc length" or "constant speed and acceleration". On a spline (in general), points are not spaced equidistantly in respect to the parameter, and the arc length in relation to the parameter is not easily calculated (or guessed). Not in a closed form anyway, you can sum up line segments and subdivide recursively until you're below a chosen threshold, but it's not a nice and easy thing.

 

However, since the spacing depends on the second derivative (points are closer together the higher the curvature), you can get the desired result "backwards" by making the spline C2-continuous (which is possible and relatively easy with a B-Spline, other than with most other spline types). Your sample points will then automatically be equally spaced. The curve that you show is C1 but not C2 continuous (it interpolates or rather approximates "smoothly" (tangents fit together) but the tangents change "non smoothly" in a very obvious manner).

 

Of course the resulting curve will look radically different from the one you have now. If that is non-agreeable, you can do an estimate on local curvature and modify the step of the t-parameter accordingly. Which is kind of a hack, but may work just good enough.

0

Share this post


Link to post
Share on other sites

Thanks for the reply. So how would I go about ensuring C2 continuity? I implemented this algorithm to compute the derivative. However at the moment I haven't Matlab handy so I need to check whether it really works. Assuming that it does, I should be able to recursively obtain the second derivative. How can I use this information to obtain C2 continuity?

I googled a bit using the terms you suggested, but so far I've only landed on research papers suggesting ways to calculate this arc length using integration. Maybe there are more real-time friendly alternatives?

public BSpline Derivative()
{
   Vector2[] newCPs = new Vector2[Count - 1];

   BSpline derivative = new BSpline(Degree - 1);

   for (int i = 0; i < newCPs.Length; i++)
   {
      newCPs[i] = (this[i + 1] - this[i])*(Degree/(knotVector[i + Degree + 1] - knotVector[i + 1]));
   }

   derivative.AddPoints(newCPs);

   float[] newKnotVector = new float[knotVector.Count - 2];
   for (int i = 0; i < newKnotVector.Length; i++)
   {
      newKnotVector[i] = knotVector[i + 1];
   }
   derivative.knotVector.AddRange(newKnotVector);

   return derivative;
}

public BSpline Derivative(int iTh)
{
   BSpline bs = this;
   while (iTh > 0)
   {
      iTh--;
      bs = bs.Derivative();
   }

   return bs;
}
Edited by AvengerDr
0

Share this post


Link to post
Share on other sites

The best book that will give you everything you need on B-splines and NURBS is "The NURBS Book" by Piegl and Tiller. It contains code snippets that can be directly implemented. As well, it does fun computational tricks, like only computing the non-zero basis functions for B-spline point evaluation, and so on. If you're doing any serious work with B-splines, do yourself a favor and pick it up.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0