Graphics()->GetDevice()->CreateBuffer(
&descBuffer, &resData, &pMainVertexBuffer);
UINT uiStride = sizeof(cGraphicsLayer::cDefaultVertex);
UINT uiOffset = 0;
Graphics()->GetDevice()->IASetVertexBuffers(
0, 1, &pMainVertexBuffer, &uiStride, &uiOffset);
Graphics()->GetDevice()->IASetIndexBuffer(
pMainIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
Graphics()->GetDevice()->IASetPrimitiveTopology(
D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
if(m_pMainVertexBuffer)
m_pMainVertexBuffer->Release();
if(m_pMainIndexBuffer)
m_pMainIndexBuffer->Release();
m_pMainVertexBuffer = pMainVertexBuffer;
m_pMainIndexBuffer = pMainIndexBuffer;
D3D10_TECHNIQUE_DESC descTechnique;
Graphics()->GetDefaultTechnique()->GetDesc(&descTechnique);
for(UINT uiCurPass = 0; uiCurPass < descTechnique.Passes; uiCurPass++)
{
Graphics()->GetDefaultTechnique()->
GetPassByIndex(uiCurPass)->Apply(0);
Graphics()->GetDevice()->DrawIndexed(
2 * (m_size-1) * (m_size-1) * 3, 0, 0);
}
}
B-Spline Curves
Because there are myriad other types of parametric curves and surfaces,
we could not hope to cover them all. However, we’ll quickly cover one
more type of curve, b-spline, before moving on to subdivision surfaces.
Uniform, rational b-splines are quite different from Bezier curves.
Rather than have a set of distinct curves, each one made up of four control
points, a b-spline is made up of any number of control points (well… any
number greater than four). They are C
2
continuous, but they are not
interpolative (they don’t pass through their control points).
Given a particular control point p
i
, we iterate from t=0 to t=1. The
iteration uses the four control points (p
i
,p
i+1
,p
i+2
,p
i+3
). The curve it steps
out sits between p
i+1
and p
i+2
, but note that the curve itself probably won’t
actually go through those points. Figure 8.20 may help you understand
this.
376 n Chapter 8: Advanced 3D Techniques
Each section of the curve (denoted by s
0
,s
1
, etc.) is traced out by the four
control points around it. Segment s
0
is traced out by p
0
–p
3
,segments
1
by
p
1
–p
4
, and so on. To compute a point along a b-spline, we use the follow-
ing equation:
The main reason I’m including b-spline curves in this chapter is just to
show you that once you’ve learned one style of parametric curve, you’ve
pretty much learned them all. Almost all use the same style of equation;
it’s just a matter of choosing the kind of curve you want and plugging it
into your code.
Application: BSpline
Just for fun, I threw together a simple application to show off b-splines. It
draws a set of six splines whose tails fade off to blackness, spinning around
in space. The code running the splines is pretty rudimentary; it’s just there
to hopefully spark an idea in your head to use them for something more
complex. As simple as the code is, it can be pretty mesmerizing, and I feel
it’s one of the more visually pleasing sample applications in this book.
Chapter 8: Advanced 3D Techniques n 377
Figure 8.20:
Sample b-spline
ú
ú
ú
ú
û
ù
ê
ê
ê
ê
ë
é
ú
ú
ú
ú
û
ù
ê
ê
ê
ê
ë
é
-
-
--
ú
ú
ú
ú
ú
û
ù
ê
ê
ê
ê
ê
ë
é
=
+
+
+
3
2
1
2
3
0141
0303
0363
1331
6
1
1
)(
i
i
i
i
T
t
t
t
t
p
p
p
p
q
Check out the code below, which calculates the points along the curve. You
can see the full code listing in the downloadable files.
/**
* The b-spline basis matrix
*/
matrix4 cBSpline::m_baseMatrix = matrix4(
-1, 3, -3, 1,
3, -6, 3, 0,
-3, 0, 3, 0,
1, 4, 1, 0);
point3 cBSpline::Calc( float t, int i0 )
{
assert(i0+3 < m_ctrlPoints.size() );
assert(t>=0.f && t<=1.f );
point4 tVec( t*t*t, t*t, t, 1 );
point4 xVec(
m_ctrlPoints[i0].x,
m_ctrlPoints[i0+1].x,
m_ctrlPoints[i0+2].x,
m_ctrlPoints[i0+3].x );
point4 yVec(
m_ctrlPoints[i0].y,
m_ctrlPoints[i0+1].y,
m_ctrlPoints[i0+2].y,
m_ctrlPoints[i0+3].y );
point4 zVec(
m_ctrlPoints[i0].z,
m_ctrlPoints[i0+1].z,
378 n Chapter 8: Advanced 3D Techniques
Figure 8.21: TheBSplinesample

Get Advanced 3D Game Programming with DirectX 10.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.