How to Use ogre to render physx cloth (with source code download)

Source: Internet
Author: User

The results of physx fabric simulation are stored in two important buffers: vertex buffer and index buffer, rendering can be easily implemented in the graphics library, both DirectX and OpenGL are relatively easy. Here we will introduce the implementation methods in the open-source graphics engine ogre.

Manualobject can be used to manually specify the vertex and index buffer of the rendered object. This is exactly what we want. The specific code is as follows.

 

Void testcloth: render ()
{
Static nxu32 numvertices = mnumvertices;
Nxu32 numelements = mnumindices;
Numvertices = mnumvertices;

// Clears the last buffer before rendering.
Mmanualobj-> clear ();
Mmanualobj-> begin ("clothmaterial", ogre: renderoperation: ot_triangle_list );

// Copy vertex data first
For (nxu32 I = 0; I <numvertices; I ++)
{
Ogre: vector3 Pos = ogre: vector3 (mvertexrenderbuffer [I]. position. X,
Mvertexrenderbuffer [I]. position. y,
Mvertexrenderbuffer [I]. position. z );
Mmanualobj-> position (POS );

Ogre: vector3 normal = ogre: vector3 (mvertexrenderbuffer [I]. Normal. X,
Mvertexrenderbuffer [I]. Normal. y,
Mvertexrenderbuffer [I]. Normal. z );
Mmanualobj-> normal (normal );

Mmanualobj-> texturecoord (mvertexrenderbuffer [I]. texcoord [0],

Mvertexrenderbuffer [I]. texcoord [1]);
}

// Then copy the index data
For (nxu32 J = 0; j <mtricount; j ++)
{
Mmanualobj-> triangle (mindexrenderbuffer [J * 3],

Mindexrenderbuffer [J * 3 + 1], mindexrenderbuffer [J * 3 + 2]);
}

Mmanualobj-> end ();
}

 

Testcloth class, modified from the sample code of physx SDK, but replaced the OpenGL rendering code, the other is basically not dynamic.

In the code, mvertexrenderbuffer and mindexrenderbuffer are the vertex and index results returned by the physx SDK after each simulation.

 

Below is

 

 

 

Source code can be downloaded here

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.