Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 12 years, 1 month ago.
Active 2 years, 11 months ago. Viewed 2k times. Improve this question. Kromster 6, 7 7 gold badges 56 56 silver badges bronze badges. Dr Deo Dr Deo 4, 11 11 gold badges 40 40 silver badges 68 68 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. Matthew Scharley Matthew Scharley k 51 51 gold badges silver badges bronze badges. Do you happen to have any literature i can go through on this?
No, sorry, this is just off the top of my head and my understanding of the math involved. Most higher level math books that cover 3d geometry should probably cover it though. That's what I've heard. The table covers a finite subset of the unit sphere. So, instead of storing normals in. It's been answered already but I want to shed some more light on it.
Daniel Yankowsky Daniel Yankowsky 6, 1 1 gold badge 32 32 silver badges 39 39 bronze badges. The array is static so it's declared only once.
It's better for performance improvement than creating a new array at each call of this function. The size of the array is constant and is the maximum number of vertices that a model can hold. The second variable is ptricmds.
It is the pointer which will read OpenGL commands. Then we save polygon attributes, reverse orientation of front-facing polygons because of the GL commands and enable backface culling. We process all calculus needed for the lighting, interpolate vertices and scale them, and bind the model texture.
All the rendering is done in the while statement. First we get the triangle type and the number of vertices to draw. In the for statement we parse each vertex. Because each vertex has 3 values stored in the gl command list, we increment the pointer by 3 when all vertices of the group are processed.
For each vertex, we set the lighting color using the pointer on the dot product result table for the light angle and the final lighting color calculated by the ProcessLighting function.
Textures coordinates are casted from int to float. We obtain the normal vector from the anorms table and render the vertex from the array initialized just before. Notice that if you don't use OpenGL lighting, the call to glNormal3fv don't do anything and if you use it, the call to glColor3f doesn't affect anything.
Remember the static animlist array. It has been designed to store all minimal animation data, that is to say the index of the first and last frame, and the fps count for running the animation.
Here is the initialisation:. We'll use an index to access to animation data, but it is better to define a macro for each index for readability of the source code:. So to set an animation we must retrieve animation data and initialize current animation data with it. It's the SetAnim function's job:. You can pass to type any macro defined just before. We'll now see a new function: Animate.
This function will be called in the DrawModel function, so we must rewrite it:. Here we animate only if time is greater than 0. Otherwise there is no animation, the model is static.
Look at the Animate function source code:. In a first time, the function calculate the first and next frames using the fps count specified to the current animation. In a second time, it check these values and verify that they are correct they must not be greater than the total number of frames that holds the model.
Finaly, the interpolation percent is calculated from the animation fps count and the time. We must now review our Interpolate function, this time to really interpolate vertices. Otherwise, we would have a very poor animation because of the number of frames the model can holds. The formula is quite simple:. So let's interpolate all vertices of the current and the next frames.
The new Interpolate function looks like this:. By the way, we scale interpolated vertices And that's all! You just need to call once SetAnim and ScaleModel functions with the parameter of your choice, and DrawModel with the current time in seconds in parameter during the rendering loop. That's not so bad! Just before ending, I would show you how to render a simple frame in case you'll need for example: drawing a statue :.
This function adjust animation variables before calling DrawModel which will render the specified frame of the model. This article is far from being perfect and can be widely improved like including multiple skin support or separating model file data vertex list, normal list, It is difficult to create a perfect CMD2Model class which would work in any program with a simple cut and paste I hope this article helped you to learn about the MD2 model file format and more generally about 3D Model files!
Also I hope it was not too confusing. Please don't spam my mailbox about my English, it is not my native language. Source code of this article is free and is provided without warranty expressed or implied. Use at your own risk! You can download the latest version: md2loader. Diese Site durchsuchen. MD2 fileformat very basic. MD2 basics. So what? DrawFrame is the function we'll use to draw the model at a specific frame. Ok, we're ready to start really! Let's move to the next section: loading a MD2 model file!
This is all for this section. We have loaded all data we need. Drawing the model It's time to render the model we've loaded!
Animating 3D models look nicer when they are animated! So let's animate all that. Conclusion Here we are, it is finally finished! The next variables are quite similar. Divide the short value by the texture size: RealST[i].
Other vertices of this frame are stored just after the first vertex, so we can access to them like that: frame. This is all about data structures! We read the first value. The two first are s, t texture coordinates and the third is the vertex index to draw.
Once all vertices of this group are processed, we read a new value to get a new group If the read value is 0, it is done! It is not very simple the first time but with some practice you'll see that in reality it is quite simple ;- Look at figure 6 for a representation of OpenGL command list each rectangle represent one command which is one integer value : Ok I've finished with theory.
Hawkins, D. Focus on 3D Models , Ch. MD2 Viewer source code, Mete Ciragan. On top of the original format and its non-integer variation, Quake tools notably TrenchBroom and ericw-tools support Valve format. Major difference between both stems from how texture coordinates are represented. Quake standard format for plane definition:. Cookies help us deliver our services. By using our services, you agree to our use of cookies.
More information. Skip to Content Skip to Navigation. Log in Create account. Page Discussion Edit this page History. From Quake Wiki The Quake. Improve Quake Wiki by editing this page. Thulsa made an edit on 28 July Related changes. Permanent link. What links here. Quake Wiki. Search Quake Wiki. History Related changes Permanent link What links here View random page.
0コメント