PDA

View Full Version : Can anybody help me?



kemal ACIKGOZ
06-06-2009, 07:01 AM
Hey i got a problem.

I wrote a program just do basic manipulation animations on robot arm puma 560.

I can send my code to seeing problem.

Please help me with hurry. My msn address is that: promachine@windowslive.com

Problem is that: i call some objects on my screen and i can't do depth testing on screen. I use glCallList to call objects. Please help me, this is my school project. I will try to advanced manipulations when i figured out this problem. Thanx

kemal ACIKGOZ
06-06-2009, 07:47 AM
it is simply read a xml(for SolidWorks object)...
and manipulate the object

this is the code:
#include "Read3DXML.h"
#include "StringTokenizer.h"

#include <windows.h>
#include <gl\glu.h>
#include <gl\glut.h>

//mouse <1>
static GLfloat yrotation;
static GLfloat xrotation;

GLfloat mouseX;
GLfloat mouseY;
GLfloat zvalue = 0.0f;
int mouseState;
int mouseButton;
//mouse </1>

GLfloat rxV=0;
GLfloat ryV=0;
GLfloat rzV=0;

GLuint m_co(){
GLuint list = glGenLists(1);
glNewList(list, GL_COMPILE_AND_EXECUTE);
glColor3f(0.0f,1.0f,0.0f);
glBegin(GL_LINES);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(100.0f,0.0f,0.0f);
glEnd();
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_LINES);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,100.0f,0.0f);
glEnd();
glColor3f(0.0f,0.0f,1.0f);
glBegin(GL_LINES);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,100.0f);
glEnd();
glEndList();
return list;
}

GLuint makeShape(const char* name,GLfloat color){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
static int i=0;
int stack=0;
int control=0;
vector<int>::const_iterator iter;
i++;
Read3DXML* shape = new Read3DXML(name,name);
GLuint list = glGenLists(1)+i;
glNewList(list, GL_COMPILE);
glColor3f(color,color,color);

for(iter = shape->faces_Tokenizer.begin();iter != shape->faces_Tokenizer.end();++iter){
if(*iter == *(shape->faces_Tokenizer.end()-1)) break;
glBegin(GL_TRIANGLES);
for(int i=*iter;i<=(*(iter+1)-2);i=i+3){
glNormal3f(shape->getN1().at(stack+shape->faceMap_.at(i)),shape->getN1().at(stack+shape->faceMap_.at(i+1)),shape->getN1().at(stack+shape->faceMap_.at(i+2)));
glVertex3f(shape->getX().at(stack+shape->faceMap_.at(i)),shape->getY().at(stack+shape->faceMap_.at(i)),shape->getZ().at(stack+shape->faceMap_.at(i)));
glVertex3f(shape->getX().at(stack+shape->faceMap_.at(i+1)),shape->getY().at(stack+shape->faceMap_.at(i+1)),shape->getZ().at(stack+shape->faceMap_.at(i+1)));
glVertex3f(shape->getX().at(stack+shape->faceMap_.at(i+2)),shape->getY().at(stack+shape->faceMap_.at(i+2)),shape->getZ().at(stack+shape->faceMap_.at(i+2)));
}
glEnd();

stack = stack + shape->posMap_.at(control);
control++;
}
glEndList();
return list;
}

void timer(int val){
rxV=rxV+1;
glutTimerFunc(1,timer,1);
glutPostRedisplay();
}

void setup(){
GLfloat ambientLight[] = {0.3f,0.3f,0.3f,1.0f};
GLfloat diffuseLight[] = {0.7f,0.7f,0.7f,1.0f};
GLfloat lightPos[] = {-400.0,0.0f,100.0f,1.0f};
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
glEnable(GL_DEPTH_TEST);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glClear(GL_DEPTH_BUFFER_BIT);
glLineWidth(4.0f);
glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
glClearColor(0.0f,0.2f,0.5f,1.0f);
}



void drawShape(GLuint shapeName,GLfloat dx,GLfloat dy,GLfloat dz,GLfloat anglex,GLfloat angley,GLfloat anglez){
glPushMatrix();
glTranslatef(dx,dy,dz);
glRotatef(anglex,1.0f,0.0f,0.0f);
glRotatef(angley,0.0f,1.0f,0.0f);
glRotatef(anglez,0.0f,0.0f,1.0f);
glCallList(shapeName);
glPopMatrix();
glLoadIdentity();
}

void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLuint shape1 = makeShape("A.xml",0.1);
GLuint shape2 = makeShape("B.xml",0.4);
GLuint shape3 = makeShape("C.xml",0.5);
GLuint shape4 = makeShape("D.xml",0.6);
GLuint shape5 = makeShape("masa.xml",0.7);
GLuint shape6 = makeShape("masa2.xml",0.8);
GLuint co = m_co();
glPushMatrix();
glTranslatef(0.0f,0.0f,zvalue);
glRotatef(xrotation,1.0f,0.0f,0.0f);
glRotatef(yrotation,0.0f,1.0f,0.0f);
glTranslatef(0.0f,0.0f,-2400.0f);
glRotatef(135.0f,1.0f,0.0f,0.0f);
glRotatef(-30.0f,0.0f,0.0f,1.0f);
/*
glTranslatef(0.0f,1400.0f,0.0f);*/
glPushMatrix();
glCallList(co);
drawShape(shape6,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f);
glDeleteLists(shape6,1);
drawShape(shape5,1200.0f,0.0f,200.0f,0.0f,0.0f,0.0 f);
glTranslatef(300.0f,0.0f,-600.0f);
glRotatef(rxV,0.0f,0.0f,1.0f);
glDeleteLists(shape2,1);
drawShape(shape2,0.0f,0.0f,0.0f,180.0f,0.0f,0.0f);
glTranslatef(380.0f,-700.0f,-300.0f);
glPushMatrix();
glRotatef(rxV,1.0f,0.0f,0.0f);
drawShape(shape4,0.0f,0.0f,0.0f,0.0f,90.0f,0.0f);
glPopMatrix();
glTranslatef(0.0f,700.0f,0.0f);
drawShape(shape3,0.0f,0.0f,0.0f,0.0f,90.0f,-90.0f);
/*


glTranslatef(380.0f,-700.0f,-300.0f);
drawShape(shape4,0.0f,0.0f,0.0f,rxV,90.0f,0.0f);
drawShape(shape3,680.0f,0.0f,-900.0f,0.0f,90.0f,-90.0f);
drawShape(shape1,300.0f,0.0f,0.0f,180.0f,0.0f,0.0f );
drawShape(shape6,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f);
drawShape(shape5,1200.0f,0.0f,200.0f,0.0f,0.0f,0.0 f);
*/
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
glutTimerFunc(1,timer,1);
}

void Reshape(GLsizei w,GLsizei h){
GLfloat fAspect;
fAspect = (GLfloat)w/(GLfloat)h;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
/*glOrtho(-2180,2180,-2180,2180,-2180,2180);*/
gluPerspective(60.0f,fAspect,-1600.0f,0.0f);
/*glFrustum(-1.0,1.0,-1.0,1.0,0.0,1600);*/
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void mouse(int btn, int state, int x, int y)
{
if (state == GLUT_DOWN){
mouseState = state;
mouseButton = btn;
mouseX = x;
mouseY = y;
}else{
mouseState = 0;
}
}

void motion(int x, int y)
{
if (mouseState == GLUT_DOWN){
if (mouseButton == GLUT_LEFT_BUTTON){
yrotation -= (mouseX - x)*0.1; //about y-axis
xrotation -= (mouseY - y)*0.1; //about x-axis
}else if (mouseButton == GLUT_RIGHT_BUTTON){
zvalue -= (mouseX - x)*10;
}
}
mouseX = x;
mouseY = y;
glutPostRedisplay();
}

int main(){
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(800,600);
glutCreateWindow("puma");
glutMouseFunc(mouse);
glutMotionFunc(motion);
setup();
glutDisplayFunc(display);
glutReshapeFunc(Reshape);
/*glutTimerFunc(10,timer,1);*/
glutMainLoop();
}

kemal ACIKGOZ
06-06-2009, 10:45 AM
i describe my problem:

i call something to display but the first thing i called has displayed before the others and this is not good. Can i do depth testing for display lists...is glCallList support DOUBLE BUFFERING.

Dark Photon
06-06-2009, 11:30 AM
i call something to display but the first thing i called has displayed before the others and this is not good. Can i do depth testing for display lists...is glCallList support DOUBLE BUFFERING.
Yes, there is nothing about display lists that precludes using depth testing or double buffering. Think of them as just a function call with a bunch of OpenGL calls in it.

Dark Photon
06-06-2009, 11:36 AM
Your display() function is calling and executing m_co() every frame. This function creates, generates, and executes that display list every time it is called. I suspect this is related to your problem.

You should generate your display list during init (COMPILE). Then simply execute it as desired when inside your display() function (CallList).

kemal ACIKGOZ
06-06-2009, 11:44 AM
http://img197.imageshack.us/img197/6659/problembex.th.png (http://img197.imageshack.us/my.php?image=problembex.png)

so, how can i handle this problemmm. I try to use depth testing but this is happen everytime... i will disconnect from internet. If you know answer send me e-mail please.



_______________________

yooyo
06-06-2009, 05:46 PM
gluPerspective(60.0f,fAspect,-1600.0f,0.0f) is wrong...
zNear and zFar must be greater than 0.0 and zFar must be greater than zNear.

http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/perspective.html


Also, code is really bad.

kemal ACIKGOZ
06-07-2009, 01:13 PM
hey dude(Dark Photon). Thank you very much. Only person who helped me is you. ThanX. If you need help for anything just send me e-mail. For everything ... I am professional in Electronics.