• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
riashakkoua

Opengl Robot.c

3 posts in this topic

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.

[CODE]#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;
}[/CODE] Edited by jbadams
Added code tags to post to improve the display of your code sample.
1

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0