Jump to content

  • Log In with Google      Sign In   
  • Create Account


Opengl Robot.c


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 riashakkoua   Members   -  Reputation: 106

Like
1Likes
Like

Posted 05 December 2012 - 01:26 AM

Hello everyone!

I have a term project due this week for school, it consists of creating a robot that can move all its limbs (arms, legs, torso, head, etc...), be able to move about a set plane, involve collision detection on three different objects, and be able to toggle between first and third person views.

So far I have everything done except for the collision detection and first person view..

I'm using Opengl and writing the robot in C. If anyone has any tips or some sample code they could show me it would be appreciated more than you know.

Below is the code I have written so far for the Robot.c file, I'm also using a simple Makefile to create an exe of the robot.

#include <GL/glut.h>
#include <math.h>
#define BASE_HEIGHT 4.0/2
#define BASE_RADIUS 1.0/2
#define HEAD_HEIGHT 1.25/2
#define HEAD_RADIUS 0.75/2
#define NECK_HEIGHT 0.5/2
#define EYE_LEVEL 0.75/2
#define NOSE_LENGTH 0.5/2
#define LOWER_ARM_HEIGHT 2.0/2
#define LOWER_ARM_WIDTH 0.5/2
#define UPPER_ARM_HEIGHT 1.25/2
#define UPPER_ARM_WIDTH 0.5/2
#define ARM_TRANSLATION 0.22/2
#define alpha 0.0
#define pi 3.14159265
static GLfloat theta[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
static GLint axis = 0;
GLUquadricObj *p;
GLfloat x = 0.0;
GLfloat y = 0.0;
GLfloat xpos = 0.0;
GLfloat ypos = 0.0;
GLfloat zpos = 0.0;
GLfloat ambient[3];
GLfloat diffuse[3];
GLfloat specular[3];
GLfloat shiness[] = {50.0f};
float width = 500;
float height = 500;
void base(void);
void head(void);
void neck(void);
void upper_rarm(void);
void upper_larm(void);
void lower_rarm(void);
void lower_larm(void);
void init(void);
void display(void);
void reshape (int width, int height);
void keyboard(unsigned char, int, int);
void processSpecialKeys(int, int, int);
void jump (void);
void lsphere (void);
void init1 (void);
void base (void) {
		double angle, angleInc;
		int i;
		angle = pi / 180;
		angleInc = angle;
		glPushMatrix();
	  
		ambient[0] = 1.0; ambient[1] = 0.0; ambient[2] = 0.0;
		diffuse[0] = 1.0; diffuse[1] = 0.0; diffuse[2] = 0.0;
		specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);
	  
		glRotatef (-90.0, 1.0, 0.0, 0.0);
		gluQuadricDrawStyle(p, GLU_FILL);
		gluCylinder (p, BASE_RADIUS, BASE_RADIUS, BASE_HEIGHT, 20, 20);
	  
		glPopMatrix();
	  
		glPushMatrix();
	  
		gluQuadricDrawStyle (p, GLU_FILL);
		glTranslatef (0.0, BASE_HEIGHT, 0.0);
		glRotatef (-90.0, 1.0, 0.0, 0.0);
		gluDisk (p, 0.0, BASE_RADIUS, 20, 20);
		glTranslatef (0.0, 0.0, -BASE_HEIGHT);
		gluDisk (p, 0.0, BASE_RADIUS, 20, 20);
		glPopMatrix();
}

void neck (void) {
		glPushMatrix();
	  
		ambient[0] = 1.0; ambient[1] = 1.0; ambient[2] = 0.0;
		diffuse[0] = 1.0; diffuse[1] = 1.0; diffuse[2] = 0.0;
		specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);
	  
		glTranslatef(0.0, BASE_HEIGHT, 0.0);
		glRotatef (-90.0, 1.0, 0.0, 0.0);
		gluQuadricDrawStyle(p, GLU_FILL);
		gluCylinder (p, HEAD_RADIUS/2, HEAD_RADIUS/2, HEAD_HEIGHT, 8, 6);
		glPopMatrix();
}
void head (void) {
		glPushMatrix();
		ambient[0] = 1.0; ambient[1] = 0.0; ambient[2] = 1.0;
		diffuse[0] = 1.0; diffuse[1] = 0.0; diffuse[2] = 1.0;
		specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);
		glRotatef (-90.0, 1.0, 0.0, 0.0);
		gluQuadricDrawStyle(p, GLU_FILL);
		gluCylinder (p, HEAD_RADIUS, HEAD_RADIUS, HEAD_HEIGHT, 20, 20);
	  
		glPushMatrix();
	  
		gluDisk (p, 0.0, HEAD_RADIUS, 20, 20);
		glTranslatef (0.0, 0.0, HEAD_HEIGHT);
		gluDisk (p, 0.0, HEAD_RADIUS, 20, 20);
		glPopMatrix();
	  
		glPushMatrix();
		glTranslatef (0.25, -HEAD_RADIUS+0.12, EYE_LEVEL);
	  
		ambient[0] = 1.0; ambient[1] = 1.0; ambient[2] = 1.0;
		diffuse[0] = 1.0; diffuse[1] = 1.0; diffuse[2] = 1.0;
		specular[0] = 0.5; specular[1] = 0.5; specular[2] = 0.5;

		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);
	  
		gluQuadricDrawStyle(p, GLU_FILL);
		gluSphere (p, 0.125, 6, 6);
		glPopMatrix();
	  
		glPushMatrix();
		glTranslatef (-0.25, -HEAD_RADIUS+0.12, EYE_LEVEL);
		ambient[0] = 1.0; ambient[1] = 1.0; ambient[2] = 1.0;
		diffuse[0] = 1.0; diffuse[1] = 1.0; diffuse[2] = 1.0;
		specular[0] = 0.5; specular[1] = 0.5; specular[2] = 0.5;

		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);
	  
	  
		gluQuadricDrawStyle(p, GLU_FILL);
		gluSphere (p, 0.125, 6, 6);
		glPopMatrix();
		glPushMatrix();
		ambient[0] = 1.0; ambient[1] = 0.5; ambient[2] = 0.0;
		diffuse[0] = 1.0; diffuse[1] = 0.5; diffuse[2] = 0.0;
		specular[0] = 0.5; specular[1] = 0.5; specular[2] = 0.5;

		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);
		glTranslatef(0.0, -HEAD_RADIUS, NOSE_LENGTH);
		glRotatef(90.0, 1.0, 0.0, 0.0);
		gluQuadricDrawStyle(p, GLU_FILL);
		gluCylinder(p, 0.125, 0, NOSE_LENGTH, 8,6);
		glPopMatrix();
		glPopMatrix();
}
void lower_rarm(void) {
		glPushMatrix();
	  
		ambient[0] = 0.0; ambient[1] = 1.0; ambient[2] = 0.0;
		diffuse[0] = 0.0; diffuse[1] = 1.0; diffuse[2] = 0.0;
		specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;
		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);
	  
		glTranslatef(0.0, 0.5 * LOWER_ARM_HEIGHT, ARM_TRANSLATION);
		glScalef(LOWER_ARM_WIDTH, LOWER_ARM_HEIGHT, LOWER_ARM_WIDTH);
		glutSolidCube(1.0);
		glPopMatrix();
}
void lower_larm(void) {
		glPushMatrix();
	  
		ambient[0] = 0.0; ambient[1] = 1.0; ambient[2] = 0.0;
		diffuse[0] = 0.0; diffuse[1] = 1.0; diffuse[2] = 0.0;
		specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;
		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);
	  
		glTranslatef(0.0, 0.5 * LOWER_ARM_HEIGHT, -ARM_TRANSLATION);
		glScalef(LOWER_ARM_WIDTH, LOWER_ARM_HEIGHT, LOWER_ARM_WIDTH);
		glutSolidCube(1.0);
		glPopMatrix();
}
void upper_rarm(void) {
		glPushMatrix();
	  
		ambient[0] = 0.0; ambient[1] = 0.0; ambient[2] = 1.0;
		diffuse[0] = 0.0; diffuse[1] = 0.0; diffuse[2] = 1.0;
		specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);
		glTranslatef(0.0, 0.5 * UPPER_ARM_HEIGHT, ARM_TRANSLATION);
		glScalef(UPPER_ARM_WIDTH, UPPER_ARM_HEIGHT, UPPER_ARM_WIDTH);
		glutSolidCube(1.0);
		glPopMatrix();
}
void upper_larm(void) {
		glPushMatrix();
	  
		ambient[0] = 0.0; ambient[1] = 0.0; ambient[2] = 1.0;
		diffuse[0] = 0.0; diffuse[1] = 0.0; diffuse[2] = 1.0;
		specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);
		glTranslatef(0.0, 0.5 * UPPER_ARM_HEIGHT, -ARM_TRANSLATION);
		glScalef(UPPER_ARM_WIDTH, UPPER_ARM_HEIGHT, UPPER_ARM_WIDTH);
		glutSolidCube(1.0);
		glPopMatrix();
}

void init1(void){
GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat mat_shininess[] = {50.0};
GLfloat light_position[] = {1.0, 1.0, 1.0, 1.0};
GLfloat white_light[] = {0.3, 0.3, 0.3, 1.0};
GLfloat lmodel_ambient[] = {1.0, 1.0, 0.0, 1.0};
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
void lsphere(void){
glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
glutSolidSphere(1.0, 20, 16);
glFlush();
}
void display(void) {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glLoadIdentity();
		gluLookAt(0.3, 5.3, 12.0, 0.0, 1.25, 0.0, 0.0, 1.0, 0.0);
glPushMatrix();
ambient[0] = 1.0; ambient[1] = 0.3; ambient[2] = 0.3;
		diffuse[0] = 1.0; diffuse[1] = 1.0; diffuse[2] = 1.0;
		specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glTranslatef(0.0, 5.0, 0.0);
lsphere();
glPopMatrix();
glPushMatrix();
ambient[0] = 0.3; ambient[1] = 0.3; ambient[2] = 0.3;
		diffuse[0] = 0.0; diffuse[1] = 0.0; diffuse[2] = 1.0;
		specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);
glTranslatef(3.0, 0.5, 1.0);
glutSolidCube(1.0);
glPopMatrix();
glPushMatrix();
ambient[0] = 0.3; ambient[1] = 0.3; ambient[2] = 0.3;
		diffuse[0] = 1.0; diffuse[1] = 0.0; diffuse[2] = 1.0;
		specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glTranslatef(-4.0, 0.5, 3.0);
glutSolidCone(0.5, 1.5, 20, 15);
glPopMatrix();
glPushMatrix();
ambient[0] = 0.3; ambient[1] = 0.3; ambient[2] = 0.3;
		diffuse[0] = 1.0; diffuse[1] = 0.0; diffuse[2] = 0.0;
		specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glTranslatef(-3.0, 0.5, -3.0);
glutSolidTeapot(1.0);
glPopMatrix();
glPushMatrix();
ambient[0] = 0.5; ambient[1] = 0.5; ambient[2] = 0.5;
		diffuse[0] = 1.0; diffuse[1] = 1.0; diffuse[2] = 1.0;
		specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

		glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, shiness);
glBegin(GL_POLYGON);
glVertex3f(5.0, 0.0, 5.0);
glVertex3f(5.0, 0.0, -5.0);
glVertex3f(-5.0, 0.0, -5.0);
glVertex3f(-5.0, 0.0, 5.0);
glVertex3f(5.0, 0.0, 5.0);
glEnd();
glPopMatrix();
		glTranslatef (xpos, ypos, zpos);
		glRotatef(theta[0], 0.0, 1.0, 0.0);
		base();
		neck();
	  
		glPushMatrix();
		glTranslatef(0.0, BASE_HEIGHT + HEAD_HEIGHT/2, 0.0);
		glRotatef(theta[2], 1.0, 0.0, 0.0);
		glRotatef(theta[1], 0.0, 1.0, 0.0);
		head();
		glPopMatrix();

		glPushMatrix();
		glTranslatef(BASE_RADIUS, BASE_HEIGHT - BASE_RADIUS / 2, 0.0);
		glRotatef(180.0, 0.0, 0.0, 1.0);
		glRotatef(270.0, 0.0, 1.0, 0.0);
		glRotatef(theta[4], 0.0, 0.0, 1.0);
		lower_rarm();
		glTranslatef(0.0, LOWER_ARM_HEIGHT, 0.0);
		glRotatef(0.0, 0.0, 0.0, 180.0);
		glRotatef(theta[6], 0.0, 0.0, 1.0);
		upper_rarm();
		glPopMatrix();
		glPushMatrix();
		glTranslatef(-BASE_RADIUS, BASE_HEIGHT - BASE_RADIUS / 2, 0.0);
		glRotatef(180.0, 0.0, 0.0, 1.0);
		glRotatef(270.0, 0.0, 1.0, 0.0);
		glRotatef(theta[3], 0.0, 0.0, 1.0);
		lower_larm();
		glTranslatef(0.0, LOWER_ARM_HEIGHT, 0.0);
		glRotatef(0.0, 0.0, 0.0, 180.0);
		glRotatef(theta[5], 0.0, 0.0, 1.0);
		upper_larm();
		glPopMatrix();
		glFlush();
		glutSwapBuffers();
}
void keyboard (unsigned char key, int x, int y) {
		switch (key) {
				case 'a': theta[1] += 5.0;
				if (theta[1] > 90.0)
						theta[1] = 90.0;
				break;
			  
				case 'z': theta[1] -= 5.0;
				if (theta[1] < -90.0)
						theta[1] = -90.0;
				break;
			  
				case 'o': theta[2] += 5.0;
				if (theta[2] > 45.0)
						theta[2] = 45.0;
				break;
			  
				case 'p': theta[2] -= 5.0;
				if (theta[2] < -45.0)
						theta[2] = -45.0;
				break;
				case 'k': theta[3] -= 5.0; break;
				case 'l': theta[3] += 5.0; break;
				case 'h': theta[4] -= 5.0; break;
				case 'j': theta[4] += 5.0; break;
				case 'n': theta[5] -= 5.0; break;
				case 'm': theta[5] += 5.0; break;
				case 'v': theta[6] -= 5.0; break;
				case 'b': theta[6] += 5.0; break;
				case 'e': theta[0] = theta[1] = theta[2] = theta[3] = theta[4] = theta[5] = theta[6] = xpos = ypos = zpos = 0.0;
				break;
			  
				case 'r': theta[0] = theta[1] = theta[2] = theta[3] = theta[4] = theta[5] = theta[6] = 0.0;
				break;
			  
				case 'q': exit(0); break;
		}
		glutPostRedisplay();
}

void processSpecialKeys(int key, int x, int y) {
		switch(key) {
				case GLUT_KEY_UP:
						xpos -= cos(90 * pi/180 + theta[0] * pi/180);
						zpos += sin(90 * pi/180 + theta[0] * pi/180);
  if (xpos > 5)
   xpos = 5;
  if (zpos > 5)
   zpos = 5;
  if (xpos < -5)
   xpos = -5;
  if (zpos < -5)
   zpos = -5;
				break;
				case GLUT_KEY_DOWN:
						xpos += cos(90 * pi/180 + theta[0] * pi/180);
						zpos -= sin(90 * pi/180 + theta[0] * pi/180);
  if (xpos > 5)
   xpos = 5;
  if (zpos > 5)
   zpos = 5;
  if (xpos < -5)
   xpos = -5;
  if (zpos < -5)
   zpos = -5;
				break;
				case GLUT_KEY_LEFT: theta[0] -= 5.0; break;
				case GLUT_KEY_RIGHT: theta[0] += 5.0; break;
				case GLUT_KEY_PAGE_UP: ypos += 1.0; break;
				case GLUT_KEY_PAGE_DOWN: ypos -= 1.0; break;
		}
	glutPostRedisplay();
}
void reshape(int w, int h) {
  glViewport(0, 0, w, h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(100.0, (GLfloat) w / (GLfloat) h, 0.5, 100.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}
void init (void) {
  GLfloat lightIntensity[] = {0.7f, 0.7f, 0.7f, 1.0f};
  GLfloat light_position[] = {2.0f, 6.0f, 3.0f, 0.0f};

  glEnable(GL_LIGHTING);  
  glEnable(GL_LIGHT0);
  glShadeModel(GL_SMOOTH);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);
  glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightIntensity);
  glClearColor(0.0, 0.0, 0.0, 0.0);
  glColor3f(1.0, 0.0, 0.0);
  p = gluNewQuadric();
}
int main(int argc, char **argv) {
		glutInit(&argc, argv);
		glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
		glutInitWindowSize(width, height);
		glutCreateWindow("Robot");
		init();
init1();
		glutReshapeFunc(reshape);
		glutDisplayFunc(display);
		glutKeyboardFunc(keyboard);
		glutSpecialFunc (processSpecialKeys);
		glutMainLoop();
		return 0;
}

Edited by jbadams, 05 December 2012 - 02:21 AM.
Added code tags to post to improve the display of your code sample.


Sponsor:

#2 Erik Rufelt   Crossbones+   -  Reputation: 3041

Like
1Likes
Like

Posted 05 December 2012 - 04:35 AM

Do you have any specific questions you need help with?
As for making a first-person camera, you should be able to modify the parameters for your gluLookAt to place the camera at the robots head looking in the direction the robot is facing.
To do collisions with objects you need to modify your logic (xpos < 5) etc. to keep the robot outside of objects. Probably enough to let each object be a rectangle.

I would also try to move more things into their own functions, like make a drawRobot(float x, float y, float z) that draws the robot at that position and similar for other things. That makes everything easier to read and avoids losing track of small mistakes somewhere in a long function.

For movement, make a function moveRobot(float startX, float startY, float distanceX, float distanceY) to move a robot from a certain point a certain distance, and then from there do collision detection to avoid the rectangles you need to avoid, and make it return the result position. Try to make a function that does collision to one object, and make it so you can call the same function 3 times with different parameters to avoid all 3 objects.

#3 riashakkoua   Members   -  Reputation: 106

Like
0Likes
Like

Posted 05 December 2012 - 09:27 PM

Thanks for the help above,

As for specific questions, the only thing I would require help in is making the collision detection function. What I have is basically three objects, two of which are rectangular prisms and a tea pot. I want the robot to know that when it comes next to any object that it must stop and not go through it.

#4 blewisjr   Members   -  Reputation: 616

Like
2Likes
Like

Posted 06 December 2012 - 08:45 PM

As far as collision detection goes I won't go into the detail of an implementation but I can give you a basic idea. The quickest and easiest way to do collision detection here would be a technique call bounding box collision. Esentially it involves rectangles or in 3d they would be more 3d box structures. You would surround your objects with these structures (note they are not rendered it could be nothing more then an array of verticies around your object) Then every frame you check to see if these vertices of the robots bounding box intersects with one of the obstacle bounding boxes. This would allow you to know when they are near enough to stop movement in that direction.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS