1

私はマンデルブロー集合を行ってズームしようとしていますが、パターンのズームは非常に面倒です。ズームすると完全にズームしますが、画像サイズは元の半分に縮小されます。次回ズームすると、写真のサイズが大きくなり、表示ウィンドウをスキップしようとします。コードは c++/opengl です。ここに投稿する前に、コードを少しきれいにしようとしました。

#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

double dividecubesby  = 700;
double left = -2.0;
double right = 2.0;
double bottom = -2.0;
double top = 2.0;
int maxiteration = 128;
int zoomlevel = 3;
double baseSize = 4.0;
double SizeReal;
double SizeImage;
double xco=0.0;
double yco=0.0;

void whatcoordinate(int x,int y)
{
    int xp=x;
    int yp=y;
    double delta1 = (right-left);
    double tempx;   
    double tempy;
    double delta=0.0;   
    double l = dividecubesby/2;

    delta = delta1/dividecubesby;

    if((xp > l) && (yp < l))
    {
        tempx = xp*delta;
        tempy = yp*delta;

        xco = right - tempx;
        yco = top - tempy;

        if(xco <0)xco=xco*-1;
        if(yco <0)yco=yco*-1;
    }
    else if( (x < l) && (y < l))
    {
        tempx = xp*delta;
        tempy = yp*delta;

        xco = right - tempx;
        yco = top - tempy;

        if(xco >0)xco=xco*-1;
        if(yco <0) yco =yco*-1;
    }
    else if((x < l) && (y > l))
    {
        tempx = xp*delta;
        tempy = yp*delta;

        xco = right - tempx;
        yco = top - tempy;

        if(xco >0)xco=xco*-1;
        if(yco >0)yco=yco*-1;
    }
    else if((x > l) && (y > l))
    {
        tempx = xp*delta;
        tempy = yp*delta;

        xco = right - tempx;
        yco = right - tempy;

        if(xco <0)xco=xco*-1;
        if(yco >0)yco=yco*-1;
    }
}

void keyPressed(unsigned char key, int x, int y)
{
    switch(key)
    {
    case 'z':
        printf("z pressed  x= %d, y= %d \n",x,y);

        whatcoordinate(x,y);

        SizeReal = (pow(2.0, (-zoomlevel)))*baseSize;
        SizeImage = (pow(2.0, (-zoomlevel)))*baseSize;

        baseSize = right-left;

        left   =  xco- (SizeReal/2);
        right  =  xco + (SizeReal/2);
        bottom = yco - (SizeReal/2);
        top    = yco + (SizeReal/2);    
        dividecubesby = dividecubesby+500;      
        maxiteration  = maxiteration+500; 
        zoomlevel=zoomlevel+1;

        glutPostRedisplay();

        break;
    }
}

int mandtest(double Cr, double Ci)
{
    double Zr = 0.0;
    double Zi = 0.0;
    int times = 0;
    double temp;
    Zr = Zr+Cr;
    Zi = Zi+Ci;

    while ((((Zr*Zr)+(Zi*Zi))<=4) && (times < maxiteration))
    {
        temp = (Zr*Zr)-(Zi*Zi);
        Zi = 2*Zr*Zi;

        Zr = temp+Cr;
        Zi = Zi+Ci;                

        times = times+1;  

    }

    return times;
}

void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0f,1.0f,1.0f);
    double deltax = ((right - left)/(dividecubesby-1));//this means length/700 
    double deltay = ((top- bottom)/(dividecubesby-1));// this means length/700

    gluOrtho2D(left,right,bottom,top);
    glBegin(GL_POINTS);

    for(double x= left;x<=right;x += deltax )
    {
        for(double y= bottom; y<=top;y +=  deltay )
        {
            if((mandtest(x,y))==maxiteration)
            {
                glColor3f(1.0f,1.0f,1.0f); 
                glVertex2f(x,y);
            }
            else 
            {
                glColor3f((float)mandtest(x,y)/10,0.0f,(float)mandtest(x,y)/30);
                glVertex2f(x,y);
            }
        }
    }
    glEnd();

    glFlush();
}

void init()
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
}

int main(int argc, char ** argv)
{   
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(dividecubesby,dividecubesby);
    glutCreateWindow("A Simple OpenGL Windows Application with GLUT");
    init();
    glutDisplayFunc(display);
    glutKeyboardFunc(keyPressed);
    glutMainLoop();

    return 0;
}

実行時

1)ここに画像の説明を入力

2)ここに画像の説明を入力

3)ここに画像の説明を入力

4

2 に答える 2

2

再レンダリングごとに gluOrtho2D(left,right,bottom,top) を使用してビューの変換を変更するべきではないと思います。それらに(初期)固定値を与えるだけです。ビューは、画像 1 と同じままです)。マンデルブロ関数に渡す座標を変換するだけです。

@genpfault が言及しているように、テクスチャの使用を検討してください。その方が効率的です。

于 2012-10-30T20:14:48.570 に答える
2

問題は配置することで修正されました

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

gluOrtho2D(左、右、下、上)のすぐ上; これは初期化用です。これは、opengl スーパーバイブルブックの第 2 章でよく説明されています。

1)ここに画像の説明を入力

2)ここに画像の説明を入力

3)ここに画像の説明を入力

于 2012-11-06T15:45:39.543 に答える