资源简介

使用marching-cube算法实现的等值面绘制效果

资源截图

代码片段和文件信息

//
// Marching Cubes Example Program 
// by Cory Bloyd (corysama@yahoo.com)
//
// A simple portable and complete implementation of the Marching Cubes
// and Marching Tetrahedrons algorithms in a single source file.
// There are many ways that this code could be made faster but the 
// intent is for the code to be easy to understand.
//
// For a description of the algorithm go to
// http://astronomy.swin.edu.au/pbourke/modelling/polygonise/
//
// This code is public domain.
//

#include “stdio.h“
#include “math.h“
//This program requires the OpenGL and GLUT libraries
// You can obtain them for free from http://www.opengl.org
#include “GL/glut.h“

struct GLvector
{
        GLfloat fX;
        GLfloat fY;
        GLfloat fZ;     
};

//These tables are used so that everything can be done in little loops that you can look at all at once
// rather than in pages and pages of unrolled code.

//a2fVertexOffset lists the positions relative to vertex0 of each of the 8 vertices of a cube
static const GLfloat a2fVertexOffset[8][3] =
{
        {0.0 0.0 0.0}{1.0 0.0 0.0}{1.0 1.0 0.0}{0.0 1.0 0.0}
        {0.0 0.0 1.0}{1.0 0.0 1.0}{1.0 1.0 1.0}{0.0 1.0 1.0}
};

//a2iEdgeConnection lists the index of the endpoint vertices for each of the 12 edges of the cube
static const GLint a2iEdgeConnection[12][2] = 
{
        {01} {12} {23} {30}
        {45} {56} {67} {74}
        {04} {15} {26} {37}
};

//a2fEdgeDirection lists the direction vector (vertex1-vertex0) for each edge in the cube
static const GLfloat a2fEdgeDirection[12][3] =
{
        {1.0 0.0 0.0}{0.0 1.0 0.0}{-1.0 0.0 0.0}{0.0 -1.0 0.0}
        {1.0 0.0 0.0}{0.0 1.0 0.0}{-1.0 0.0 0.0}{0.0 -1.0 0.0}
        {0.0 0.0 1.0}{0.0 0.0 1.0}{ 0.0 0.0 1.0}{0.0  0.0 1.0}
};

//a2iTetrahedronEdgeConnection lists the index of the endpoint vertices for each of the 6 edges of the tetrahedron
static const GLint a2iTetrahedronEdgeConnection[6][2] =
{
        {01}  {12}  {20}  {03}  {13}  {23}
};

//a2iTetrahedronEdgeConnection lists the index of verticies from a cube 
// that made up each of the six tetrahedrons within the cube
static const GLint a2iTetrahedronsInACube[6][4] =
{
        {0516}
        {0126}
        {0236}
        {0376}
        {0746}
        {0456}
};

static const GLfloat afAmbientWhite [] = {0.25 0.25 0.25 1.00}; 
static const GLfloat afAmbientRed   [] = {0.25 0.00 0.00 1.00}; 
static const GLfloat afAmbientGreen [] = {0.00 0.25 0.00 1.00}; 
static const GLfloat afAmbientBlue  [] = {0.00 0.00 0.25 1.00}; 
static const GLfloat afDiffuseWhite [] = {0.75 0.75 0.75 1.00}; 
static const GLfloat afDiffuseRed   [] = {0.75 0.00 0.00 1.00}; 
static const GLfloat afDiffuseGreen [] = {0.00 0.75 0.00 1.00}; 
static const GLfloat afDiffuseBlue  [] = {0.00 0.00 0.75 1.00}; 
static const GLfloat afSpecularWhite[] = {1.00 1.00 1.00 1.00}; 
static const GLfloat afSpecularRed  

评论

共有 条评论