void frame_box_move_rotate(frame_box *src, int16_t angle, int16_t x_c, int16_t y_c, frame_box *dst1, frame_box *dst2) { float sin_ = sin_deg(angle); float cos_ = cos_deg(angle); if ( sin_ < 0.0 ) { if ( cos_ < 0.0 ) { dst1->x1 = x_c + ((src->x2 - x_c) * cos_) - ((src->y1 - y_c) * sin_); dst1->y1 = y_c + ((src->x2 - x_c) * sin_) + ((src->y1 - y_c) * cos_); dst1->x2 = x_c + ((src->x1 - x_c) * cos_) - ((src->y2 - y_c) * sin_); dst1->y2 = y_c + ((src->x1 - x_c) * sin_) + ((src->y2 - y_c) * cos_); dst2->x1 = -((src->y2 - src->y1) * sin_); dst2->y1 = (src->y2 - src->y1) * cos_; dst2->x2 = -(cos_ * (src->x2 - src->x1)); dst2->y2 = -(sin_ * (src->x2 - src->x1)); } else { dst1->x1 = x_c + ((src->x1 - x_c) * cos_) - ((src->y1 - y_c) * sin_); dst1->y1 = y_c + ((src->x1 - x_c) * sin_) + ((src->y1 - y_c) * cos_); dst1->x2 = x_c + ((src->x2 - x_c) * cos_) - ((src->y2 - y_c) * sin_); dst1->y2 = y_c + ((src->x2 - x_c) * sin_) + ((src->y2 - y_c) * cos_); dst2->x1 = (src->x2 - src->x1) * cos_; dst2->y1 = (src->x2 - src->x1) * sin_; dst2->x2 = -(sin_ * (src->y2 - src->y1)); dst2->y2 = cos_ * (src->y2 - src->y1); } } else { if ( cos_ < 0.0 ) { dst1->x1 = x_c + ((src->x2 - x_c) * cos_) - ((src->y2 - y_c) * sin_); dst1->y1 = y_c + ((src->y2 - y_c) * cos_) + ((src->x2 - x_c) * sin_); dst1->x2 = x_c + ((src->x1 - x_c) * cos_) - ((src->y1 - y_c) * sin_); dst1->y2 = y_c + ((src->y1 - y_c) * cos_) + ((src->x1 - x_c) * sin_); dst2->x1 = -((src->x2 - src->x1) * cos_); dst2->y1 = -((src->x2 - src->x1) * sin_); dst2->x2 = sin_ * (src->y2 - src->y1); dst2->y2 = -(cos_ * (src->y2 - src->y1)); } else { dst1->x1 = x_c + ((src->x1 - x_c) * cos_) - ((src->y2 - y_c) * sin_); dst1->y1 = y_c + ((src->y2 - y_c) * cos_) + ((src->x1 - x_c) * sin_); dst1->x2 = x_c + ((src->x2 - x_c) * cos_) - ((src->y1 - y_c) * sin_); dst1->y2 = y_c + ((src->y1 - y_c) * cos_) + ((src->x2 - x_c) * sin_); dst2->x1 = (src->y2 - src->y1) * sin_; dst2->y1 = -((src->y2 - src->y1) * cos_); dst2->x2 = cos_ * (src->x2 - src->x1); dst2->y2 = sin_ * (src->x2 - src->x1); } } }
/***************************************************************************** * Draw a faceted latitude band of the Boing ball. * * Parms: long_lo, long_hi * Low and high longitudes of slice, resp. *****************************************************************************/ void DrawBoingBallBand( GLfloat long_lo, GLfloat long_hi ) { vertex_t vert_ne; /* "ne" means south-east, so on */ vertex_t vert_nw; vertex_t vert_sw; vertex_t vert_se; vertex_t vert_norm; GLfloat lat_deg; static int colorToggle = 0; /* * Iterate thru the points of a latitude circle. * A latitude circle is a 2D set of X,Z points. */ for ( lat_deg = 0; lat_deg <= (360 - STEP_LATITUDE); lat_deg += STEP_LATITUDE ) { /* * Color this polygon with red or white. */ if ( colorToggle ) glColor3f( 0.8f, 0.1f, 0.1f ); else glColor3f( 0.95f, 0.95f, 0.95f ); #if 0 if ( lat_deg >= 180 ) if ( colorToggle ) glColor3f( 0.1f, 0.8f, 0.1f ); else glColor3f( 0.5f, 0.5f, 0.95f ); #endif colorToggle = ! colorToggle; /* * Change color if drawing shadow. */ if ( drawBallHow == DRAW_BALL_SHADOW ) glColor3f( 0.35f, 0.35f, 0.35f ); /* * Assign each Y. */ vert_ne.y = vert_nw.y = (float) cos_deg(long_hi) * RADIUS; vert_sw.y = vert_se.y = (float) cos_deg(long_lo) * RADIUS; /* * Assign each X,Z with sin,cos values scaled by latitude radius indexed by longitude. * Eg, long=0 and long=180 are at the poles, so zero scale is sin(longitude), * while long=90 (sin(90)=1) is at equator. */ vert_ne.x = (float) cos_deg( lat_deg ) * (RADIUS * (float) sin_deg( long_lo + STEP_LONGITUDE )); vert_se.x = (float) cos_deg( lat_deg ) * (RADIUS * (float) sin_deg( long_lo )); vert_nw.x = (float) cos_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * (float) sin_deg( long_lo + STEP_LONGITUDE )); vert_sw.x = (float) cos_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * (float) sin_deg( long_lo )); vert_ne.z = (float) sin_deg( lat_deg ) * (RADIUS * (float) sin_deg( long_lo + STEP_LONGITUDE )); vert_se.z = (float) sin_deg( lat_deg ) * (RADIUS * (float) sin_deg( long_lo )); vert_nw.z = (float) sin_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * (float) sin_deg( long_lo + STEP_LONGITUDE )); vert_sw.z = (float) sin_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * (float) sin_deg( long_lo )); /* * Draw the facet. */ glBegin( GL_POLYGON ); CrossProduct( vert_ne, vert_nw, vert_sw, &vert_norm ); glNormal3f( vert_norm.x, vert_norm.y, vert_norm.z ); glVertex3f( vert_ne.x, vert_ne.y, vert_ne.z ); glVertex3f( vert_nw.x, vert_nw.y, vert_nw.z ); glVertex3f( vert_sw.x, vert_sw.y, vert_sw.z ); glVertex3f( vert_se.x, vert_se.y, vert_se.z ); glEnd(); #if BOING_DEBUG printf( "----------------------------------------------------------- \n" ); printf( "lat = %f long_lo = %f long_hi = %f \n", lat_deg, long_lo, long_hi ); printf( "vert_ne x = %.8f y = %.8f z = %.8f \n", vert_ne.x, vert_ne.y, vert_ne.z ); printf( "vert_nw x = %.8f y = %.8f z = %.8f \n", vert_nw.x, vert_nw.y, vert_nw.z ); printf( "vert_se x = %.8f y = %.8f z = %.8f \n", vert_se.x, vert_se.y, vert_se.z ); printf( "vert_sw x = %.8f y = %.8f z = %.8f \n", vert_sw.x, vert_sw.y, vert_sw.z ); #endif } /* * Toggle color so that next band will opposite red/white colors than this one. */ colorToggle = ! colorToggle; /* * This circular band is done. */ return; }
void ball::calculateNewDeltasByAngle() { //angle = atan(tan(angle)); dx = speed_mult * cos_deg(angle); dy = speed_mult * sin_deg(angle); }