Ejemplo n.º 1
0
void draw_rod(GLUquadricObj* quad, GLfloat *start, GLfloat start_scale, GLfloat *end, GLfloat end_scale) {
	GLfloat scaled_start[] = { start[0] * start_scale, start[1] * start_scale, start[2] * start_scale };
	GLfloat scaled_end[] = { end[0] * end_scale, end[1] * end_scale, end[2] * end_scale };
	GLfloat diff_vector[] = {scaled_end[0] - scaled_start[0], scaled_end[1] - scaled_start[1], scaled_end[2] - scaled_start[2] };

	glPushMatrix();
	GLfloat dist = vector_dis(scaled_start, scaled_end);
	if(diff_vector[2] < 0.0f && diff_vector[0] == 0.0f && diff_vector[1] == 0.0f) {
		glTranslated(scaled_start[0], scaled_start[1], scaled_start[2] - dist);
	} else if (diff_vector[2] > 0.0f) {
		glTranslated(scaled_start[0], scaled_start[1], scaled_start[2]);
	} else {
		glTranslated(scaled_end[0], scaled_end[1], scaled_end[2]);
	}
	

	GLfloat crossX = diff_vector[1]/dist;
	GLfloat crossY = -diff_vector[0]/dist;
	GLfloat angle = asin(sqrt(crossX*crossX + crossY*crossY)) * 180/3.14159265;
	if(diff_vector[2] > 0.0f && !(diff_vector[0] == 0.0f && diff_vector[1] == 0.0f)) {
		angle = -angle;
	}

	glRotatef(angle, crossX, crossY, 0.0f);

	gluCylinder(quad, 0.02f, 0.02f, dist, 20, 1);
	glPopMatrix();
}
Ejemplo n.º 2
0
bool inf_can_mov(struct unt *slf, int *loc){
    /* determine if can move based on map characteristic */
    if(game.MAPS.restrictions[*loc][*(loc+1)][*(loc+2)] == slf->Class){return FALSE;}
    
    /* determine if can move if(board square == empty) */
    if(game.MAPS.maps[*loc][*(loc+1)][*(loc+2)] != 0){return FALSE;}
    
    /* determine if can move using distance */
    //FIX!!!
    float dis = vector_dis(&slf->loc[0], loc);
    
    if(slf->cur_steps - (int)dis < 0){return FALSE;}
    
    return TRUE;
}
Ejemplo n.º 3
0
bool inf_move(struct unt *slf, int *loc){
    
    if(inf_can_mov(slf,loc) == FALSE){return FALSE;}
    
    float dis = vector_dis(&(slf->loc[0]), loc);
    slf->cur_steps -= (int)dis;
    
    slf->loc[0] = *loc;
    slf->loc[1] = *(loc+1);
    slf->loc[2] = *(loc+2);
    
    /* give height range bonus.... */
    
    
    return TRUE;
}
Ejemplo n.º 4
0
bool inf_can_atk(struct unt *slf,struct unt *def){
    
    if (slf->ammo <= 0){return FALSE;}          // need ammo to shoot
    if (slf->did_fire == TRUE){return FALSE;}    // can't fire twice!
    if (slf->team == def->team){return FALSE;} // no friendly fire
    
    // ensure target is within range //FIX DIS
    float dist =  vector_dis(&slf->loc[0], &def->loc[0]);
    if((int)dist < slf->min_range || (int)dist > slf->range){
        return FALSE;
    }
    
    // collision detection!!!
    
    return FALSE;
}