Jump to content
  • Advertisement
Sign in to follow this  
RyukZilla

OpenGL 3D OpenGL C#

This topic is 2591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

Well this is something that got me a migraine and it must be quite easy to solve but I'm just blocked.
I'm working on a program for my university (8th Semester), to be more precise, Robotics. Project is about a robot that has a manipulator and goes from one point to another in a defined map.
The tricky part is that the robot must evade auto-generated obstacles (for example, a set of cubes randomly placed in the map/world) and from the initial point, draw the shortest trajectory and actually draw it on the 3D OpenGL control, along with the rest of the lines.

To explain my self better, the trajectory must be something like, initial point -> detect of a cube/obstacle > compare the distances of and see which one is the shortest > draw the one that is the shortest and keep the trajectory, if it finds another obstacle, do the same process and finish.

So what I'm having trouble with is with that and...:

* Dunno why my initial coords are like X = -1.47, Y= 1.1, they should be like 0,0
* When I send the coords in a loop/cycle to reach the final position (X = 8, Y = -11), program just freezes and stops working, curious enough, the parts do move, like the tires and manipulator but the robot itself, doesnt.
* When I actually succeeded in moving the robot, it just recreates it in multiple positions across the map and on random spots (the trajectory function is not included) :/

So yeh... im actually burnt with this, I see no end to this misery and im quite stressed.
Please do apologize me if this is the wrong forum, tho I think since its OpenGL related, it should be fine.

To sum this all:

* Why is my initial coords X!=0 and Y! = 0? (!= as in different, just to shorten things up)
* Im looking for some help to make the function for it to move across the map, with a defined trajectory and the obstacle detection.

Functions:

So I create the grid this way

Grid


void Dibujar_Grid(Single GridScale, Single XSteps, Single ZSteps){
Single zExtent, xExtent;
Single xLocal, zLocal;
float loopX, loopZ;

Gl.glPushMatrix();
Gl.glRotated(77, 1, 0, 0);
Gl.glBegin(Gl.GL_LINES);
zExtent = GridScale*ZSteps;
for(loopX = -XSteps; loopX <=XSteps; loopX++ )
{
xLocal = GridScale*loopX;
Gl.glVertex3d( xLocal, 0.0, -zExtent );
Gl.glVertex3d( xLocal, 0.0, zExtent );
}
xExtent = GridScale * XSteps ;
for(loopZ = -ZSteps; loopZ <= ZSteps; loopZ++ )
{
zLocal = GridScale * loopZ;
Gl.glVertex3d( -xExtent, 0.0, zLocal );
Gl.glVertex3d( xExtent, 0.0, zLocal );
}
Gl.glEnd();
Gl.glPopMatrix();


Robot function


private void Robot(double X, double Y, double Z, double RotRueda1, double RotRueda2, double RotRueda3, double RotRueda4, double RotEje, double RotMotor1, double RotMotor2, double RotMotor3, double RotMotor4)
{
Gl.glScalef(10.0f, 10.0f, 10.0f);
Gl.glTranslated(X, Y, Z); // Posicion del Cuerpo en el Espacio

// Rueda1
Gl.glPushMatrix();
Gl.glTranslated(-4.4, 4.8, 0.1);
Gl.glScalef(0.06f, 0.06f, 0.06f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(90, 0, 1, 0); // Gira 90 grados con respecto a Y
Gl.glRotated(RotRueda1, 0, 0, 1); // Gira RotRueda grados con respecto a Z
Piñon.dibujar();
Gl.glPopMatrix();

// Rueda 2
Gl.glPushMatrix();
Gl.glTranslated(-4.4, 4.6, 0.1);
Gl.glScalef(0.06f, 0.06f, 0.06f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(90, 0, 1, 0); // Gira 90 grados con respecto a Y
Gl.glRotated(RotRueda2, 0, 0, 1); // Gira RotRueda grados con respecto a Z
Rueda.dibujar();
Gl.glPopMatrix();

// Rueda 3
Gl.glPushMatrix();
Gl.glTranslated(-4.2, 4.8, 0.1);
Gl.glScalef(0.06f, 0.06f, 0.06f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(90, 0, 1, 0); // Gira 90 grados con respecto a Y
Gl.glRotated(RotRueda3, 0, 0, 1); // Gira RotRueda grados con respecto a Z
Piñon.dibujar();
Gl.glPopMatrix();

// Rueda 4
Gl.glPushMatrix();
Gl.glTranslated(-4.2, 4.6, 0.1);
Gl.glScalef(0.06f, 0.06f, 0.06f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(90, 0, 1, 0); // Gira 90 grados con respecto a Y
Gl.glRotated(RotRueda4, 0, 0, 1); // Gira RotRueda grados con respecto a Z
Rueda.dibujar();
Gl.glPopMatrix();

// Eje
Gl.glPushMatrix();
Gl.glTranslated(-4.3, 4.6, 0.1);
Gl.glScalef(0.2f, 0.8f, 0.8f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(90, 0, 1, 0); // Gira 90 grados con respecto a X
Gl.glRotated(RotEje, 0, 0, 1); // Gira RotEje grados con respecto a Z
Eje.dibujar();
Gl.glPopMatrix();

// Motor 1
Gl.glPushMatrix();
Gl.glTranslated(-4.376, 4.8, 0.1);
Gl.glScalef(0.06f, 0.06f, 0.06f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(-90, 0, 1, 0); // Gira 90 grados con respecto a Y
Motor.dibujar();
Gl.glPopMatrix();

// Motor 2
Gl.glPushMatrix();
Gl.glTranslated(-4.228, 4.8, 0.1);
Gl.glScalef(0.06f, 0.06f, 0.06f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(90, 0, 1, 0); // Gira 90 grados con respecto a X
Motor.dibujar();
Gl.glPopMatrix();

// Lado Grande 1
Gl.glPushMatrix();
Gl.glTranslated(-4.364, 4.7, 0.1168);
Gl.glScalef(0.12f, 0.3f, 0.12f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(90, 0, 1, 0); // Gira 90 grados con respecto a Y
Gl.glRotated(-90, 0, 1, 0); // Gira 90 grados con respecto a Y
LadoGrande.dibujar();
Gl.glPopMatrix();

// Lado Grande 2
Gl.glPushMatrix();
Gl.glTranslated(-4.24, 4.7, 0.1168);
Gl.glScalef(0.12f, 0.3f, 0.12f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(180, 0, 1, 0); // Gira 90 grados con respecto a Y
//Gl.glRotated(zz, 0, 0, 1); // Gira 90 grados con respecto a Z
LadoGrande.dibujar();
Gl.glPopMatrix();

// Lado Pequeño 1
Gl.glPushMatrix();
Gl.glTranslated(-4.302, 4.56, 0.116);
Gl.glScalef(0.148f, 0.12f, 0.12f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(90, 0, 1, 0); // Gira 90 grados con respecto a Y
LadoPequeño.dibujar();
Gl.glPopMatrix();

// Lado Pequeño 2
Gl.glPushMatrix();
Gl.glTranslated(-4.302, 4.84, 0.116);
Gl.glScalef(0.148f, 0.12f, 0.12f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(-90, 0, 1, 0); // Gira 90 grados con respecto a Y
LadoPequeño.dibujar();
Gl.glPopMatrix();

// Acrilico Inferior
Gl.glPushMatrix();
Gl.glTranslated(-4.3, 4.7, 0.11);
Gl.glScalef(0.14f, 0.28f, 0.2f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(90, 0, 1, 0); // Gira 90 grados con respecto a Y
AcrilicoInferior.dibujar();
Gl.glPopMatrix();

// Angulo 1
Gl.glPushMatrix();
Gl.glTranslated(-4.368, 4.64, 0.128);
Gl.glScalef(0.02f, 0.02f, 0.02f);
Gl.glRotated(-90, 1, 0, 0); // Gira 90 grados con respecto a X
Angulos.dibujar();
Gl.glPopMatrix();

// Angulo 2
Gl.glPushMatrix();
Gl.glTranslated(-4.368, 4.764, 0.128);
Gl.glScalef(0.02f, 0.02f, 0.02f);
Gl.glRotated(-90, 1, 0, 0); // Gira 90 grados con respecto a X
Angulos.dibujar();
Gl.glPopMatrix();

// Angulo 3
Gl.glPushMatrix();
Gl.glTranslated(-4.236, 4.64, 0.128);
Gl.glScalef(0.02f, 0.02f, 0.02f);
Gl.glRotated(-90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(180, 0, 1, 0); // Gira 90 grados con respecto a Y
Angulos.dibujar();
Gl.glPopMatrix();

// Angulo 4
Gl.glPushMatrix();
Gl.glTranslated(-4.236, 4.764, 0.128);
Gl.glScalef(0.02f, 0.02f, 0.02f);
Gl.glRotated(-90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(180, 0, 1, 0); // Gira 90 grados con respecto a Y
Angulos.dibujar();
Gl.glPopMatrix();

// Piso Superior
Gl.glPushMatrix();
Gl.glTranslated(-4.302, 4.699, 0.14);
Gl.glScalef(0.3f, 0.4f, 0.2f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
PisoSuperior.dibujar();
Gl.glPopMatrix();

// Angulo Brazo
Gl.glPushMatrix();
Gl.glTranslated(-4.27, 4.7, 0.152);
Gl.glScalef(0.02f, 0.02f, 0.02f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Angulos.dibujar();
Gl.glPopMatrix();

// Barra Brazo
Gl.glPushMatrix();
Gl.glTranslated(-4.289, 4.7, 0.192);
Gl.glScalef(0.15f, 0.1f, 0.1f);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a Y
BarraBrazo.dibujar();
Gl.glPopMatrix();

// Funcion que contiene el movimiento de todo el brazo
Gl.glPushMatrix();
// Servomotor 1
Gl.glTranslated(-4.289, 4.7, 0.24);
Gl.glScaled(0.012, 0.012, 0.012);
Gl.glRotated(90, 1, 0, 0); // Gira 90 grados con respecto a X
Gl.glRotated(RotMotor1, 0, 1, 0); // Gira RotMotor1 grados con respecto a Y
Servomotor.dibujar();
Gl.glTranslated(0, 1, 4.40);
Gl.glScaled(10, 10, 10);
BarraBrazo.dibujar();
// Servomotor 2
Gl.glTranslated(0, 0.036, 0.45);
Gl.glScaled(0.12, 0.12, 0.12);
Gl.glRotated(RotMotor2, 0, 1, 0); // Gira RotMotor2 grados con respecto a Y
Servomotor.dibujar();
Gl.glTranslated(0, 1, 4.40);
Gl.glScaled(10, 10, 10);
BarraBrazo.dibujar();
// Servomotor 3
Gl.glTranslated(-0.038, 0, 0.424);
Gl.glScaled(0.12, 0.12, 0.12);
Gl.glRotated(90, 0, 0, 1); // Gira 90 grados con respecto a X
Servomotor.dibujar();
Gl.glRotated(90, 1, 0, 0);
Gl.glTranslated(0, 0, -0.44);
Gl.glScaled(2, 2, 1);
Piñon.dibujar();
Gl.glTranslated(0, 0.49, 0);
Gl.glTranslated(RotMotor3, 0, 0);
Gl.glScaled(2, 2, 2);
Gl.glRotated(90, 1, 0, 0);
Gl.glRotated(-90, 0, 0, 1);
Cremallera.dibujar();
Gl.glTranslated(0, 0, -0.112);
Gl.glScaled(1.2, 1.2, 1.2);
Gl.glRotated(90, 1, 0, 0);
BarraBrazo.dibujar();
Gl.glTranslated(0, 0, 0.56);
Gl.glScaled(1.0, 1.0, 1.0);
Gl.glRotated(90, 1, 0, 0);
Gl.glRotated(90, 0, 1, 0);
BarraBrazo.dibujar();
Gl.glPopMatrix();
}


Obstacle random generation (upon clicking a button)

Button Function


private void button1_Click(object sender, EventArgs e)
{
cubos = Convert.ToDouble(textBox6.Text);

draw_cubos = 1;
for (int k = 0; k < cubos; k++)
{
coord_cubos[k, 0] = randomx.Next(-50, 50);
coord_cubos[k, 0] += 2;
}
for (int k = 0; k < cubos; k++)
{
coord_cubos[k, 1] = randomx.Next(-50, 50);
coord_cubos[k, 1] += 2;
}
}


Loop that generates them


// Cubos
if(draw_cubos==1)
{
for (int i = 0; i < cubos; i++)
{
if (coord_cubos[i, 0] != 0 && coord_cubos[i, 1] != 0)
{
Gl.glBegin(Gl.GL_QUADS);
Gl.glColor3f(1.0f, 1.0f, 1.0f); // color

Gl.glVertex3d(coord_cubos[i, 0], coord_cubos[i, 1], altura);
Gl.glVertex3d(coord_cubos[i, 0] + lado, coord_cubos[i, 1], altura);
Gl.glVertex3d(coord_cubos[i, 0] + lado, coord_cubos[i, 1] + lado, altura);
Gl.glVertex3d(coord_cubos[i, 0], coord_cubos[i, 1] + lado, altura);

Gl.glVertex3d(coord_cubos[i, 0], coord_cubos[i, 1], altura+lado);
Gl.glVertex3d(coord_cubos[i, 0] + lado, coord_cubos[i, 1], altura + lado);
Gl.glVertex3d(coord_cubos[i, 0] + lado, coord_cubos[i, 1] + lado, altura + lado);
Gl.glVertex3d(coord_cubos[i, 0], coord_cubos[i, 1] + lado, altura + lado);

Gl.glVertex3d(coord_cubos[i, 0], coord_cubos[i, 1], altura);
Gl.glVertex3d(coord_cubos[i, 0], coord_cubos[i, 1], altura+lado);
Gl.glVertex3d(coord_cubos[i, 0], coord_cubos[i, 1] + lado, altura+lado);
Gl.glVertex3d(coord_cubos[i, 0], coord_cubos[i, 1] + lado, altura);

Gl.glVertex3d(coord_cubos[i, 0], coord_cubos[i, 1], altura + lado);
Gl.glVertex3d(coord_cubos[i, 0] + lado, coord_cubos[i, 1], altura + lado);
Gl.glVertex3d(coord_cubos[i, 0] + lado, coord_cubos[i, 1], altura);
Gl.glVertex3d(coord_cubos[i, 0], coord_cubos[i, 1], altura );

Gl.glVertex3d(coord_cubos[i, 0], coord_cubos[i, 1]+lado, altura + lado);
Gl.glVertex3d(coord_cubos[i, 0] + lado, coord_cubos[i, 1]+lado, altura + lado);
Gl.glVertex3d(coord_cubos[i, 0] + lado, coord_cubos[i, 1]+lado, altura);
Gl.glVertex3d(coord_cubos[i, 0], coord_cubos[i, 1]+lado, altura);

Gl.glVertex3d(coord_cubos[i, 0]+lado, coord_cubos[i, 1], altura);
Gl.glVertex3d(coord_cubos[i, 0]+lado, coord_cubos[i, 1], altura + lado);
Gl.glVertex3d(coord_cubos[i, 0]+lado, coord_cubos[i, 1] + lado, altura + lado);
Gl.glVertex3d(coord_cubos[i, 0]+lado, coord_cubos[i, 1] + lado, altura);

Gl.glEnd();
}
}
}


Any help would be gladly appreciated as im really stressed and I know it must be something really dumb im failing to do so :/

Share this post


Link to post
Share on other sites
Advertisement

Well, I've come to know that this forum does sucks, no help whatsoever


Great attitude after not even waiting a day...

Have you also considered that knowing nil about the actual robot makes it a tad bit hard to help? I don't know how relevant this is to OpenGL either... surely the coordinates are derived from elsewhere and it is there the logic fails? OpenGL doesn't automagically define coordinates to be any different than what you tell them to be.

Your #2 question belongs in AI, for example, as it relates to pathfinding. This verges on homework, but since you asked for general help we can provide that. Not me though, since I haven't touched robotics in far too long to be useful -- someone else will chime in if you give it some time (and btw, we're not your paid mentors; insulting the site won't earn you any karma around here...)

Share this post


Link to post
Share on other sites
I'm not insulting the site but common, a lot of views and no one cared to say anything?
I'm not saying or asking for someone to do it, just to guide me thats it.

Share this post


Link to post
Share on other sites
Even if i would visit your post isnt there any garante that i either understand the problem or
could solve a solution to you. Learn to be social bevor posting!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!