C++C++11C++14C++17Language FeatureLearn C++

Learn To Quickly Create Specific 3D Objects In Modern C++ Applications For Windows

3D Objects are like wrapped papers in 3D form. They consist of points which shape a polygon. It’s very rare to use anything other than triangles, and more complex shapes are decomposed into multiple triangles. Our 3D objects are stored with these points, data that which points are shaping polygons. In modern application development most of these objects are generated by a 3D Designer Software with their own 3d Object standards and these are displayed or animated in mechanics by a 3D Engine. In C++ Builder you can directly create your own 3D objects, you can animate them on runtime.

In C++ Builder, Viewport3D (TViewportd3D) component in C++ Builder FireMonkey projects is good to display many basic 3D Objects like Plane, Cube, Sphere, Cone, Plane, Ellipse3D etc. You can also easily load your 3D objects into Viewport3D by using Model3D (TModel3D).

How to create specific 3D objects in modern C++?

To create a 3D object to be used in Viewport3D we need to use TMesh classes.  TMesh is a custom 3D shape that can be customized by drawing 3D shapes.  It is a class publishes a set of properties from its ancestor, TCustomMesh, in order to let you design new 3D shapes at design time from within the IDE, through the Object Inspector. Use the Data property to specify the points, normals and textures for each point, and the order in which the resulting triangles are drawn. The designed shape is filled with the material specified through MaterialSource property. If no material is specified, then the shape is filled with red color.

1.Create a new Multi-Device C++ Builder Firemonkey project, Save all unit and project files into a folder.

2. Drag a Viewport3D from Tool Palette on to Form. We will use this to display our 3D Mesh object. Add Light, Dummy Object, Color Material.

3. Add a Button to generate mesh when button is pressed.

3. Go to Unit1.h, lets define our TMesh pointer in public section of Form as below;

4. Back to Form design, and double click to Button1, add these variables.

5. And add these lines (Step 5,6,7) to setup our new mesh. Note that Parent object must be defined to be displayed. Here our parent object will be Dummy1. You can set to ViewPort3D1 too.

Here above, we used 4 and 6 magic numbers to create VertexBuffer and IndexBuffer,

Mesh Data has 4 parameters, these are P0, P1, P2, P3 nodes;

and Index Buffer has 6 params, because 4 nodes creates 2 faces and we can define each of them by 3 poins

maybe this gives more help to understand, https://vulkan-tutorial.com/Vertex_buffers/Index_buffer

6. Now let’s add our Points and Polygons to Mesh Data

7. Finally let’s setup our mesh Material and some other specifics.

8. Don’t forget to free mesh from the memory when user close your application.

Learn C++ Optimization With A Genetic Algorithms Example

C++ Builder is the easiest and fastest C and C++ compiler and IDE for building simple or professional applications on the Windows operating system. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++Syntax

Learn Default Constructors Of Classes In Modern C++

Artificial Intelligence TechC++C++11C++14C++17Learn C++

How To Develop Special AI Activation Functions In C++?

Artificial Intelligence TechC++C++11C++14C++17Language FeatureLearn C++

Learn How To Read The WAV Waveform Audio File Format In C++

C++C++11Learn C++

What Is Assignment Operator Overloading?