PDA

View Full Version : Preventing zoom of a partcular object.



Muhammad Asif Hussain
02-26-2011, 11:34 PM
:sleeping:
Hi Every one.
In my reservoir rock model project, the color bar at the bottom is zoomed when I apply zoom to the model. Is there any need of SubWindow for color bar? or may it be separated from the model while zooming in or out?

I am placing code so you can understand the problem better.
(key 'i' for zoom in and 'o' for zoom out)

#include <windows.h> //suitable when using Windows 95/98/NT
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#include <gl/glext.h>
#include <gl/glaux.h>
#include <math.h>
#include<stdio.h>
#include <stdlib.h>
#include <dos.h>

// Prototype Decalartion
void myDisplay(void);
void filledCube(GLfloat xLocation, GLfloat yLocation, GLfloat zLocation, GLfloat widthofCube, GLfloat lenghtofCube, GLfloat heightofCube, GLfloat* fillcolor);

// Variable declaration
GLfloat zoom=10.0;
double P[50]; int counter1=0; // global variables
GLfloat rX=0, rY=0;
int oldX=0, oldY=0;

void Mouse(int button, int s, int x, int y)
{
if (s == GLUT_DOWN)
{
oldX = x;
oldY = y;
}
}

void Motion(int x, int y)
{
rY += (x - oldX)/5.0f;
rX += (y - oldY)/5.0f;

oldX = x;
oldY = y;
glutPostRedisplay();
}


/////////////////////////// Axis function ///////////////////////////////
void axis(GLfloat length)
{ // draw a axis, with cone at end
glPushMatrix();
glBegin(GL_LINES);
glVertex3d(0, 0, 0);
glVertex3d(0,0,length); // along the z-axis
glEnd();
glTranslated(0, 0,length -0.2);
glutSolidCone(0.04, 0.2, 12, 9);
glPopMatrix();
}
//////////////////////////// Axis Function end here ////////////////////

///////////////////////////////// bmpfont //////////////////////////////
void
bitmap_output(GLfloat x, GLfloat y, GLfloat z, char *string, void *font)
{
int len, i;

glRasterPos3f(x, y, z);
len = (int) strlen(string);
for (i = 0; i < len; i++) {
glutBitmapCharacter(font, string[i]);
}
}
/////////////////////bmp font end here/////////////////////////////////


//<<<<<<<<<<<<<<<<<<<<<<<<<<<<< displayFunction >>>>>>>>>>>>>>>>>>>>>>
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT); // clear the screen
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);

glMatrixMode(GL_MODELVIEW); // position and aim the camera
glLoadIdentity();
gluLookAt(2.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); /*set camera position*/

glMatrixMode(GL_MODELVIEW);
glLoadIdentity ();
glOrtho(-zoom,zoom, -zoom,zoom, -zoom,zoom); /* The camera cube */

//////// QUAD (GRADUATED_COLOR_BAR) start ////////////

glColor3f(1.0, 1.0, 1.0);
bitmap_output(-2.2, -8.5, 3.5, "MIN", GLUT_BITMAP_9_BY_15);
bitmap_output(2.8, -8.5, 1.3, "MAX", GLUT_BITMAP_9_BY_15);
GLfloat wb=.2, lb=4.8; // bar length and width

glMatrixMode(GL_MODELVIEW);
glPushMatrix ();
glTranslatef(-1, -8.0, -3); //glTranslatef(1.2, 0.0, 3.2);
glRotatef (45, 0.0f, 1.0f, 0.0f);

glBegin (GL_QUADS);
glColor3f (0.0f, 0.0f, 1.0f); // BLUE COLOR LEFT END
glVertex3f (0.0f, wb, 0.0);
glVertex3f (0.0f, 0.0f,0.0);

glColor3f(0,1,0);
glVertex3f (lb/2.0, 0.0,0.0);
glVertex3f (lb/2.0, wb,0.0);

glVertex3f (lb/2.0, 0.0f,0.0);
glVertex3f (lb/2.0, wb,0.0);

glColor3f (1.0f, 0.0f, 0.0f); //RED COLOR RIGHT END
glVertex3f (lb, wb,0.0);
glVertex3f (lb, 0.0f,0.0);
glEnd ();
glPopMatrix();
////////////////// QUAD END///////////////////


glRotatef(rX,1,0,0);
glRotatef(rY,0,1,0);


// DRAW AXES
glColor3d(1,0,0); // red color
axis(5); // x-axis
glPushMatrix();
glRotated(90, 0,1.0, 0);
glColor3d(0,1,0); //green color
axis(5); // y-axis
glRotated(90, 1, 0, 0);
glColor3d(0,0,1); // blue color
axis(5); // z-axis
glPopMatrix();



P[0]=3000; P[1]=2548; P[2]=250; P[3]=2548.9; P[4]=3000;P[5]=500;P[6]=1500;P[7]=2000;P[8]=700;P[9]=2900;
P[10]=2100;P[11]=2400;P[12]=2300;P[13]=1600;P[14]=2500;
GLdouble PMIN=250, PMAX=3000;

int N=4;
GLfloat j=0.0;
GLfloat color[4];
GLfloat avg = (PMAX+PMIN)/2;
GLfloat avg2 = (avg+PMIN)/2;
GLfloat avg3 = (avg+PMAX)/2;

for (GLint i=0;i<=N; i=i+1)

{

if(P[i]>=PMIN &amp;&amp; P[i]<avg){
color[0]=1-(PMIN/P[i]); color[1]=0.0; color[2]=(PMIN/P[i]); color[3]=1;}

if(P[i]>=avg &amp;&amp; P[i]<=PMAX){
color[0]=(P[i]/PMAX); color[1]=0.0; color[2]=1-(P[i]/PMAX); color[3]=1;}

filledCube(j, 0, 0, .3, .3, .3, color); //location (x,y,z), size (length, width, height), color (set by array color[] above)

j=j+0.3; // Translation along X axis
}

glPushMatrix();

//////////////////////////////put some text ///////////////////////////////////////
glColor3f(1.0, 1.0, 1.0);
//bitmap_output(2.2, 1.9, 1.5, "simulation viewer", GLUT_BITMAP_HELVETICA_18);
bitmap_output(2.2, 0.0, 0.0, "X-AXIS", GLUT_BITMAP_9_BY_15);
bitmap_output(0.0, -2.2, 0.0, "Y-AXIS", GLUT_BITMAP_9_BY_15);
bitmap_output(0.0, 0.0, 2.2, "Z-AXIS", GLUT_BITMAP_9_BY_15);
glPopMatrix();
glFlush();

glutSwapBuffers();
}
//<<<<<<<<<<<<<< display function end >>>>>>>>>>>>>>>



/////////////////////////////////// filledcube function /////////////////////////////////////////
void filledCube(GLfloat xLocation, GLfloat yLocation, GLfloat zLocation, GLfloat widthofCube, GLfloat lenghtofCube, GLfloat heightofCube, GLfloat* fillcolor) {
GLfloat hWidth = widthofCube*0.5;
GLfloat hLength = lenghtofCube*0.5;
GLfloat hHeight = heightofCube*0.5;

glPushMatrix();


glTranslatef(xLocation, yLocation, zLocation);

glBegin(GL_QUADS);
glColor4fv(fillcolor);

//face 1
glVertex3f(hWidth, hHeight, -hLength);
glVertex3f(-hWidth, hHeight, -hLength);
glVertex3f(-hWidth, hHeight, hLength);
glVertex3f(hWidth, hHeight, hLength);
//face 2
glVertex3f(hWidth, hHeight, -hLength);
glVertex3f(hWidth, hHeight, hLength);
glVertex3f(hWidth , -hHeight, hLength);
glVertex3f(hWidth, -hHeight, -hLength);
//face 3
glVertex3f(hWidth, hHeight, hLength);
glVertex3f(hWidth, hHeight, hLength);
glVertex3f(hWidth, -hHeight, hLength);
glVertex3f(hWidth, -hHeight, hLength);
//face 4
glVertex3f(hWidth, hHeight, -hLength);
glVertex3f(-hWidth, hHeight, -hLength);
glVertex3f(-hWidth, -hHeight, -hLength);
glVertex3f(hWidth, -hHeight, -hLength);
//face 5
glVertex3f(-hWidth , hHeight, -hLength);
glVertex3f(-hWidth, hHeight, hLength);
glVertex3f(-hWidth, -hHeight, hLength);
glVertex3f(-hWidth, -hHeight, -hLength);
//face 6
glVertex3f(hWidth, -hHeight, -hLength);
glVertex3f(-hWidth, -hHeight, -hLength);
glVertex3f(-hWidth, -hHeight, hLength);
glVertex3f(hWidth, -hHeight, hLength);

glEnd();
glPopMatrix();
}


void keyboard (unsigned char key, int x, int y) {
/* Called when a key is pressed */
if (key == 27) exit (0); /* 27 is the Escape key */
//i
if (key==105) zoom=zoom-.1;
//o
if (key==111) zoom=zoom+.1;

printf ("Key pressed %c\n", key);
glutPostRedisplay();
}



//<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
int main(int argc, char** argv){
//printf("Message in Main\n-press i for zoom in\n-o for zoom out\n-'W' indicates a well block");
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize(640,480);//glutInitWindowSize(640,480);
glutInitWindowPosition(100, 100);
glutCreateWindow("Reservoir Rock Model");
glutDisplayFunc (myDisplay);
glutKeyboardFunc (keyboard); /* Register the "keyboard" function */
glutMouseFunc (Mouse); // register the mouse action function
glutMotionFunc (Motion); // register the mouse action function
glClearColor(0.0f, 0.0f, 0.0f,0.0f); // background is white Reinitialize the screen
glViewport(0, 0, 700, 600);
glutMainLoop();
return 0;

}