Skip to content

Commit

Permalink
[metaballs]: Testing cube construction algorithm.
Browse files Browse the repository at this point in the history
git-svn-id: https://euler.es/svn/aleiva/metaballs/trunk@16 e8494bbb-81f8-4217-a32d-3071ae8498ff
  • Loading branch information
gloob committed Oct 23, 2007
1 parent 8d7a6e2 commit 1dd7f61
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 20 deletions.
42 changes: 41 additions & 1 deletion cube.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "cube.h"
#include "mcdef.h"

void initCube(cube* cube0, float x, float y, float z)
void initCube2(cube* cube0, float x, float y, float z)
{
int i;

Expand Down Expand Up @@ -42,6 +42,46 @@ void initCube(cube* cube0, float x, float y, float z)
cube0->edges[10].a = &cube0->vertexs[2]; cube0->edges[10].b = &cube0->vertexs[6];
cube0->edges[11].a = &cube0->vertexs[3]; cube0->edges[11].b = &cube0->vertexs[7];

for (i = 0; i < NUM_CUBE_VERTEX; i++) {
printf("cube0: (%f,%f,%f)\n", cube0->vertexs[i].x,cube0->vertexs[i].y,cube0->vertexs[i].z);
}

}

void initCube(cube* cube0, float x, float y, float z)
{
int i;

for(i=0;i<NUM_CUBE_VERTEX;i++) {
cube0->vertexs[i].sel = FALSE;
}

cube0->vertexs[0].x = -x; cube0->vertexs[0].y = -y; cube0->vertexs[0].z = -z;
cube0->vertexs[1].x = -x; cube0->vertexs[1].y = -y; cube0->vertexs[1].z = z;
cube0->vertexs[2].x = -x; cube0->vertexs[2].y = y; cube0->vertexs[2].z = -z;
cube0->vertexs[3].x = -x; cube0->vertexs[3].y = y; cube0->vertexs[3].z = z;
cube0->vertexs[4].x = x; cube0->vertexs[4].y = -y; cube0->vertexs[4].z = -z;
cube0->vertexs[5].x = x; cube0->vertexs[5].y = -y; cube0->vertexs[5].z = z;
cube0->vertexs[6].x = x; cube0->vertexs[6].y = y; cube0->vertexs[6].z = -z;
cube0->vertexs[7].x = x; cube0->vertexs[7].y = y; cube0->vertexs[7].z = z;

cube0->edges[0].a = &cube0->vertexs[0]; cube0->edges[0].b = &cube0->vertexs[1];
cube0->edges[1].a = &cube0->vertexs[1]; cube0->edges[1].b = &cube0->vertexs[2];
cube0->edges[2].a = &cube0->vertexs[2]; cube0->edges[2].b = &cube0->vertexs[3];
cube0->edges[3].a = &cube0->vertexs[3]; cube0->edges[3].b = &cube0->vertexs[0];
cube0->edges[4].a = &cube0->vertexs[4]; cube0->edges[4].b = &cube0->vertexs[5];
cube0->edges[5].a = &cube0->vertexs[5]; cube0->edges[5].b = &cube0->vertexs[6];
cube0->edges[6].a = &cube0->vertexs[6]; cube0->edges[6].b = &cube0->vertexs[7];
cube0->edges[7].a = &cube0->vertexs[7]; cube0->edges[7].b = &cube0->vertexs[4];
cube0->edges[8].a = &cube0->vertexs[0]; cube0->edges[8].b = &cube0->vertexs[4];
cube0->edges[9].a = &cube0->vertexs[1]; cube0->edges[9].b = &cube0->vertexs[5];
cube0->edges[10].a = &cube0->vertexs[2]; cube0->edges[10].b = &cube0->vertexs[6];
cube0->edges[11].a = &cube0->vertexs[3]; cube0->edges[11].b = &cube0->vertexs[7];

for (i = 0; i < NUM_CUBE_VERTEX; i++) {
printf("cube0: (%f,%f,%f)\n", cube0->vertexs[i].x,cube0->vertexs[i].y,cube0->vertexs[i].z);
}

}

void printCube(cube cube0, unsigned char index)
Expand Down
6 changes: 3 additions & 3 deletions metaballs.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static void display2() {
}

/* Rotate. */
glRotatef( xRot, 1.0f, 0.0f, 0.0f );
glRotatef( xRot, 1.0f, 0.0f, 0.0f );
glRotatef( yRot, 0.0f, 1.0f, 0.0f );
glRotatef( zRot, 0.0f, 0.0f, 1.0f ); /* Rotate. */

Expand All @@ -178,7 +178,7 @@ void keydown (unsigned char key, int x, int y)
rotateZ = !rotateZ;
break;
case 'x': /* cross button */
index += 1;
isovalue += 10.0f;
break;
case 's': // select
break;
Expand Down Expand Up @@ -219,7 +219,7 @@ int main(int argc, char *argv[]) {

initCube(&cube0, 30.0f, 30.0f, 30.0f);

setParticle(particles, 50.0f);
setParticle(particles, isovalue);

glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); // TODO: test on psp
Expand Down
29 changes: 18 additions & 11 deletions particle.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ int setParticle( particle *particles, float isovalue )
incY = initY = particles[p].y - (( stepY * DIV_Y ) / 2) + (stepY / 2);
incZ = initZ = particles[p].z - (( stepZ * DIV_Z ) / 2) + (stepZ / 2);

//printf("* InitX = %f\n", initX);
//printf("* InitY = %f\n", initY);
//printf("* InitZ = %f\n", initZ);
printf("* InitX = %f\n", initX);
printf("* InitY = %f\n", initY);
printf("* InitZ = %f\n", initZ);

for(k = 0; k < DIV_Z; k++) {
incY = initY;
Expand All @@ -50,12 +50,12 @@ int setParticle( particle *particles, float isovalue )
particles[p].vertexs[(j*DIV_X)+(k*offset2)+i].x = incX;
particles[p].vertexs[(j*DIV_X)+(k*offset2)+i].y = incY;
particles[p].vertexs[(j*DIV_X)+(k*offset2)+i].z = incZ;
//printf("[%d][%d][%d] (%d) X = %f Y = %f Z = %f\n", i, j, k, (j*DIV_X)+(k*DIV_Y*DIV_X)+i, incX, incY, incZ);
printf("[%d][%d][%d] (%d) X = %f Y = %f Z = %f\n", i, j, k, (j*DIV_X)+(k*DIV_Y*DIV_X)+i, incX, incY, incZ);

total = (particles[p].x - incX) * (particles[p].x - incX) +
(particles[p].y - incY) * (particles[p].y - incY) +
(particles[p].z - incZ) * (particles[p].z - incZ);
//printf("[%d][%d][%d] = %f\n", i, j, k, total);
printf("[%d][%d][%d] = %f\n", i, j, k, total);
media += total;
if( total <= isovalue )
particles[p].vertexs[(j*DIV_X)+(k*offset2)+i].sel = GL_TRUE;
Expand All @@ -76,21 +76,28 @@ int setParticle( particle *particles, float isovalue )

//start cubes
int idx = 0;
incX = initX = particles[p].x + (( stepX * DIV_X ) / 2) + (stepX / 2);
incY = initY = particles[p].y + (( stepY * DIV_Y ) / 2) + (stepY / 2);
incZ = initZ = particles[p].z + (( stepZ * DIV_Z ) / 2) + (stepZ / 2);
incX = initX = particles[p].x - (( stepX * DIV_X ) / 2) + (stepX / 2);
incY = initY = particles[p].y - (( stepY * DIV_Y ) / 2) + (stepY / 2);
incZ = initZ = particles[p].z - (( stepZ * DIV_Z ) / 2) + (stepZ / 2);

printf("* InitX = %f\n", initX);
printf("* InitY = %f\n", initY);
printf("* InitZ = %f\n", initZ);
printf("* stepX = %f\n", stepX);


for (k = 0; k < DIV_Z-1; k++) {
incY = initY;
for (j = 0; j < DIV_Y-1; j++) {
incZ = initZ;
for (i = 0; i < DIV_X-1; i++) {
initCube(&particles[p].cubes[idx++], incX, incY, incZ);
printf("x: %f, y: %f, z:%f\n", incX, incY, incZ);
incZ -= stepZ;
incZ += stepZ;
}
incY -= stepY;
incY += stepY;
}
incX -= stepX;
incX += stepX;
}
return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions particle.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "cube.h"

#define DIV 3
#define DIV 2
#define DIV_X DIV
#define DIV_Y DIV
#define DIV_Z DIV
Expand Down Expand Up @@ -38,4 +38,4 @@ typedef struct {
} particle;

int setParticle(particle *p, float isovalue);
void printParticle(particle *p, float isovalue);
void printParticle(particle *p, float isovalue);
8 changes: 5 additions & 3 deletions vertex.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
class Vertex {

public:
float x, y, z;
int sel;
float x;
float y;
float z;
int sel;

Vertex(): x(0.0f), y(0.0f), z(0.0f) {};
Vertex(float vx, float vy, float vz): x(vx), y(vy), z(vz) {};
~Vertex();
void display();
};
};

0 comments on commit 1dd7f61

Please sign in to comment.