{"id":70,"date":"2013-11-08T15:46:23","date_gmt":"2013-11-08T15:46:23","guid":{"rendered":"\/\/3dbym.ru\/2013\/11\/the-data-frames-and-vertices\/"},"modified":"2013-11-08T15:46:23","modified_gmt":"2013-11-08T15:46:23","slug":"the-data-frames-and-vertices","status":"publish","type":"post","link":"https:\/\/3dbym.ru\/2013\/11\/the-data-frames-and-vertices\/","title":{"rendered":"The Data: Frames and Vertices"},"content":{"rendered":"
To display anything, you first need to get the data out of the file. You can start with the frames. Each frame starts with six floating-point values representing the scale and translation of the vertices on the X, Y, and Z axes. These values are used to decompress the vertices (more on this in a second). Immediately after these values comes a 16-character string that designates the frame\u2019s name. The frame name is not overly useful in the code in this book, but you may be able to find a good use for it.<\/p>\n
<\/p>\n
Immediately following the name comes all the vertex positions for that frame. In every frame, there is exactly the number of vertices indicated by the m_iNumVerts variable in the header.<\/p>\n
My frame structure looks like this:<\/p>\n
struct SMD2Frame {<\/p>\n
float m_fScale[3]; float m_fTrans[3] char m_caName[16];<\/p>\n
SMD2Vert * m_pVertss SMD2Frame()<\/p>\n
{<\/p>\n
m_pVerts = 0;<\/p>\n
}<\/p>\n
~SMD2Frame()<\/p>\n
{<\/p>\n
if(m_pVerts)<\/p>\n
delete [] m_pVerts;<\/p>\n
}<\/p>\n
};<\/p>\n
The first thing you probably notice about the structure is that it has a constructor and a destructor. This is perfectly legal in C++, and allows your frame structures to clean up after themselves so you don\u2019t have to worry about it. Another way to do it is to statically allocate an array to hold the maximum number of vertices allowed by the MD2 format (2048 vertices). However, this method wastes a considerable amount of<\/p>\n
\n <\/p>\n<\/td>\n<\/tr>\n<\/table>\n ~\u0413\u0413^\u042d-<\/p>\n memory if the model is small. It is best to allocate memory for each frame with the C++ keyword new.<\/p>\n You can\u2019t easily use the previous structure if you do not know what the vertex structure looks like. Take a look:<\/p>\n struct SMD2Vert {<\/p>\n float m_fVert[3];<\/p>\n };<\/p>\n That\u2019s pretty simple; m_fVert is an array of three floating-point values representing the X, Y, and Z positions of the vertex.<\/p>\n The vertices are not actually stored as floating point values. They are compressed into one byte for each vertex component. To decompress them, you must multiply each byte component by its respective float\u00ading-point scale value, and add the appropriate translation value. When this is done, the result can be stored in the SMD2Vert structure.<\/p>\n For each vertex, you read four bytes of the file into a temporary array. Following that, you multiply the first byte by the first scaling value, the second value by the second scaling factor, and so on. Then, in the same fashion, add the appropriate translations.<\/p>\n Once you have all this loaded, you can actually draw your model. You simply draw a single point at each vertex and you should see a rough image of the final model, similar to Figure 3.3. Not very exciting perhaps, but more than you had just a few pages ago. To really make it look good, you need to make it solid.<\/p>\n","protected":false},"excerpt":{"rendered":" To display anything, you first need to get the data out of the file. You can start with the frames. Each frame starts with six floating-point values representing the scale and translation of the vertices on the X, Y, and Z axes. These values are used to decompress the vertices (more on this in a […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/posts\/70"}],"collection":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/comments?post=70"}],"version-history":[{"count":0,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/posts\/70\/revisions"}],"wp:attachment":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/media?parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/categories?post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/tags?post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}} |