There has been a discussion going around on just how do you create a 3D object in code using AGK2. There is the CreateObjectFromMeshMemblock() command, but the MemBlock layout can be a bit confusing. Hopefully, I can shed some light on the format to make it easier to code.
For our first example, I am going to create a simple colored triangle. Then I am going to expand from there.
To understand how CreateObjectFromMeshMemblock() works, we need to first understand how an object is represented in AGK2. An object is a 3D entity in space. For example, a car. The object is made up of meshes. For example, you might have one mesh for the body of the car, and 4 meshes for the wheels. Each mesh is created from a series of triangles. Two triangles make a square, eight triangles make a cube, several triangles can make a sphere. Each triangle is defined with three vertices. Each vertex is defined with an x, y, and z position in space.
Let's begin by creating a new project. Click File->New Project. Name your project and choose the directory to save it to. Once the project is created, you should see this in your main window:
// Project: tutorial // Created: 2018-03-06 // show all errors SetErrorMode(2) // set window properties SetWindowTitle( "tutorial" ) SetWindowSize( 1024, 768, 0 ) SetWindowAllowResize( 1 ) // allow the user to resize the window // set display properties SetVirtualResolution( 1024, 768 ) // doesn't have to match the window SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts do Print( ScreenFPS() ) Sync() loop
Created with Tutorial Markup (c)2018 James Chamblin