私は7600700点で構成された3Dマトリクスを表示しようとしていますが、表面の黒色と内部の赤色の平行六面体を得たいと思います。それぞれのポイントは異なるエネルギー値に対応し、私はそれを行うために異なる色の濃淡だけを使用します。私は平行六面体を持っていて、それは表面が黒く、内部が赤ですが、私は赤の色合いは1つだけで、色合いは異なります。そうと異なる点については同じ色を見てくださいOpenGL
私はfloat型の値を持っている#define MATRIX_FILE "dose_file.dat"
struct Point
{
GLfloat x, y, z;
GLfloat r, g, b, a;
};
static vector<Point> points; //Vettore points di elementi Point
void fill_data() {
g_vertex_buffer_data = new GLfloat[3*p_mat_size_tot];
int i=0;
int k=0;
for(int z=0; z<263; z++)
for(int y=0; y<170; y++)
for(int x=0; x<170; x++) {
g_vertex_buffer_data[i]=(GLfloat)x+0.5;
g_vertex_buffer_data[i+1]=(GLfloat)y+0.5;
g_vertex_buffer_data[i+2]=(GLfloat)z+0.5;
i+=3;
}
g_color_buffer_data=new GLfloat[3*p_mat_size_tot];
for(int j=0;j<(3*p_mat_size_tot);j+=3) {
if(p_val[k]!=0.0) {
g_color_buffer_data[j]=(GLfloat)(255-13*fabs(logf(p_val[k])));//g_color_buffer_data[j]=(GLfloat)(255-30*fabs(log10f(p_val[k])));
} else {
g_color_buffer_data[j]=0.0;}
g_color_buffer_data[j+1]=0.0;
g_color_buffer_data[j+2]=0.0;
k++;
}
for(size_t i = 0; i < (3*p_mat_size_tot); i+=3)
{
Point pt;
pt.x = g_vertex_buffer_data[i];
pt.y = g_vertex_buffer_data[i+1];
pt.z = g_vertex_buffer_data[i+2];
pt.r = g_color_buffer_data[i];
pt.g = g_color_buffer_data[i+1];
pt.b = g_color_buffer_data[i+2];
pt.a = 255.0;
points.push_back(pt);
}
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt (85.0, 85.0, 526.0, 85.0, 85.0, 131.5, 0.0, 1.0, 0.0);
glPushMatrix();
glRotatef(step1, 1.0f, 0.0f, 0.0f);//Rotazione attorno all'asse x
glRotatef(step2, 0.0f, 1.0f, 0.0f);//Rotazione attorno all'asse y
glScalef(step3, step3, step3);//Zoom
glTranslatef(0.0f, 0.0f, step4);//Traslazione lungo z
glTranslatef(step5, 0.0f, 0.0f);//Traslazione lungo x
glTranslatef(0.0f, step6, 0.0f);//Traslazione lungo y
glMatrixMode(GL_MODELVIEW); //Lavoriamo sulla matrice del modello
// draw
//glColor3ub(255, 255, 255); //Setta il colore corrente
glEnableClientState(GL_VERTEX_ARRAY); //Abilita il l'array di vertici
glEnableClientState(GL_COLOR_ARRAY); //Abilita l'array di colori
glVertexPointer(3, GL_FLOAT, sizeof(Point), &points[0].x); //Definisce un array di dati di vertici (numero di coordinate, tipo, offset nelle coordinate tra punti consecutivi, puntatore alla prima coordinata del primo vertice nell'array)
glColorPointer(4, GL_FLOAT, sizeof(Point), &points[0].r); //Come sopra, ma con i colori
glPointSize(3.0);
glDrawArrays(GL_POINTS, 0, points.size()); //Disegna points.size() punti partendo dal primo
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glFlush(); //Forza l'esecuzione dei comandi GL in un tempo finito
glPopMatrix();
glutSwapBuffers(); //Swap dei buffers front e back della finestra (riserva memoria per inserire i comandi dati dall'utente)
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glFrustum (-0.5, 0.5, -0.5, 0.5, 1.0, 1000.0); //glFrustum (-0.5, 0.5, -0.5, 0.5, 1.0, 264.0);
glMatrixMode (GL_MODELVIEW);
}
void keyPressed(unsigned char key, int x, int y)
{
switch(key)
{
.
.
.
glutPostRedisplay();
}
int main(int argc, char** argv)
{
.
.
.
glutInit(&argc, argv); //Inizializza glut
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); //Display mode iniziale
glutInitWindowSize(800,800);
glutInitWindowPosition (100, 100);
glutCreateWindow("Test");
glClearColor (255.0, 255.0, 255.0, 0.0);
glEnable(GL_DEPTH_TEST);
fill_data();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyPressed);
glutMainLoop();
return 0;
}
(1) - 7)、10 ^( - - 6)、...、10 ^(10 ^(のようなもの): ここに私のコードの一部です私はそれらの小さい値をもっと大きなものに変換するために対数を使い、私のR値の適切な値を得るために255からそれらの新しい値を引いた(私はG = 0とB = 0に設定するように赤い色合いをしたい)。
法線を追加する必要がありますか? ありがとうございます。
コードを最小限に抑えた完全な例に減らしてください。 – Rotem
ありがとう、ありがとう、ありがとう、ありがとう、私はそれをした –
まだ、申し訳ありません... - : – user3078414