Jump to content
  • Advertisement
Sign in to follow this  

How to achieve an easier-to-see smoothing effect?

This topic is 879 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In this test program, the line does not curve very much, how do I make it curve more?


#include <Windows.h>
#include <tchar.h>
#include <vector>
#include "D3DApp.h"
#include "D3DUtil.h"

struct VertexPositionColor
    VertexPositionColor() { }
    VertexPositionColor(float _x, float _y, float _z, D3DCOLOR c)
        x = _x; y = _y; z = _z; color = c;
    float x, y, z;  // position
    D3DCOLOR color; // color
    static const DWORD FVF;


const DWORD VertexPositionColor::FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
class TestApp : public D3DApp
    // Constructor
    TestApp(HINSTANCE hInstance);

    // Destructor

    // Methods
    bool Init() override;
    void Update(float dt) override;
    void Render() override;
    // Render the path as point list

IDirect3DVertexBuffer9* VB; // unique vertexes
IDirect3DIndexBuffer9* IB;    // more indices than vertex buffer

std::vector<VertexPositionColor> outVertsColored;

TestApp::TestApp(HINSTANCE hInstance) : D3DApp(hInstance)


bool TestApp::Init()
    if (!D3DApp::Init())
        return false;

    D3DXVECTOR3 verts[8] = {
        D3DXVECTOR3(0.0, 0.0, 0.0),
        D3DXVECTOR3(10.0, 0.0, 10.0),
        D3DXVECTOR3(40.0, 0.0, 40.0),
        D3DXVECTOR3(50.0, 0.0, 50.0),

        D3DXVECTOR3(50.0, 0.0, 50.0),
        D3DXVECTOR3(55.0, 0.0, 55.0),
        D3DXVECTOR3(65.0, 0.0, 65.0),
        D3DXVECTOR3(70.0, 0.0, 70.0),

    m_pDevice3D->CreateVertexBuffer(20 * sizeof(VertexPositionColor), 0,
        VertexPositionColor::FVF, D3DPOOL_MANAGED, &VB, NULL);

    std::vector<D3DXVECTOR3> outVerts;

    for (int i = 0; i < 2; i++) {
        for (float s = 0.0; s <= 1.0f; s += 0.1) {
            D3DXVECTOR3 outVec3;
            D3DXVec3CatmullRom(&outVec3, &verts[i * 4 + 0], &verts[i * 4 + 1], &verts[i * 4 + 2], &verts[i * 4+3], s);


    for (int i = 0; i < outVerts.size(); i++) {
        VertexPositionColor outVertColored(outVerts[i].x, outVerts[i].y, outVerts[i].z, D3DColors::RED);

    VOID* pVerts;
    // put stuff into vertex buffer
    VB->Lock(0, sizeof(outVertsColored), (void**)&pVerts, 0);
    memcpy(pVerts, &outVertsColored[0], sizeof(outVertsColored));

    D3DXMATRIX view;
    D3DXMATRIX proj;

    D3DXVECTOR3 position = D3DXVECTOR3(0.0f, 30.0f, 0.0f);
    D3DXVECTOR3 target = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
    D3DXVECTOR3 up = D3DXVECTOR3(0.0f, 0.0f, 1.0f);

    D3DXMatrixLookAtLH(&view, &position, &target, &up);
    m_pDevice3D->SetTransform(D3DTS_VIEW, &view);
    // Set projection
    D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI/4, static_cast<float>(m_uiClientWidth/m_uiClientHeight), 1.0f, 1000.f);
    m_pDevice3D->SetTransform(D3DTS_PROJECTION, &proj);

    m_pDevice3D->SetRenderState(D3DRS_LIGHTING, true);
    m_pDevice3D->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);    

    return true;

void TestApp::Update(float dt)

void TestApp::Render()
    m_pDevice3D->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
        D3DColors::CORNFLOWERBLUE, 1.0f, 0);


    m_pDevice3D->SetStreamSource(0, VB, 0, sizeof(VertexPositionColor));
    m_pDevice3D->DrawPrimitive(D3DPT_LINELIST, 0, outVertsColored.size());



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)

    TestApp *tApp = new TestApp(hInstance);

    if (!tApp->Init())
        return 1;

    return tApp->Run();
Edited by lucky6969b

Share this post

Link to post
Share on other sites


I am wondering how can you link the turn radius of the agent to the catmull rom's control points

and also when there is not enough clearance for the turn, it will make a left/right hand turn etc



Edited by lucky6969b

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!