void updateDayAndNightInfo() { static char sunrise_text[] = "00:00"; static char sunset_text[] = "00:00"; PblTm pblTime; get_time(&pblTime); if(currentData != pblTime.tm_hour) { char *time_format; if (clock_is_24h_style()) { time_format = "%R"; } else { time_format = "%I:%M"; } float sunriseTime = calcSunRise(pblTime.tm_year, pblTime.tm_mon+1, pblTime.tm_mday, LATITUDE, LONGITUDE, 91.0f); float sunsetTime = calcSunSet(pblTime.tm_year, pblTime.tm_mon+1, pblTime.tm_mday, LATITUDE, LONGITUDE, 91.0f); adjustTimezone(&sunriseTime); adjustTimezone(&sunsetTime); if (!pblTime.tm_isdst) { sunriseTime+=1; sunsetTime+=1; } pblTime.tm_min = (int)(60*(sunriseTime-((int)(sunriseTime)))); pblTime.tm_hour = (int)sunriseTime; string_format_time(sunrise_text, sizeof(sunrise_text), time_format, &pblTime); text_layer_set_text(&text_sunrise_layer, sunrise_text); pblTime.tm_min = (int)(60*(sunsetTime-((int)(sunsetTime)))); pblTime.tm_hour = (int)sunsetTime; string_format_time(sunset_text, sizeof(sunset_text), time_format, &pblTime); text_layer_set_text(&text_sunset_layer, sunset_text); text_layer_set_text_alignment(&text_sunset_layer, GTextAlignmentRight); sunriseTime+=12.0f; sun_path_info.points[1].x = (int16_t)(my_sin(sunriseTime/24 * M_PI * 2) * 120); sun_path_info.points[1].y = -(int16_t)(my_cos(sunriseTime/24 * M_PI * 2) * 120); sunsetTime+=12.0f; sun_path_info.points[4].x = (int16_t)(my_sin(sunsetTime/24 * M_PI * 2) * 120); sun_path_info.points[4].y = -(int16_t)(my_cos(sunsetTime/24 * M_PI * 2) * 120); currentData = pblTime.tm_hour; } }
void inter_plan(t_all *all, t_object *plan) { double k; translate1(plan, &all->eye); rotate(all, plan); if (all->eye.vz != 0) k = -all->eye.z / all->eye.vz; else k = -1; if (k > 0.00001) { plan->k = k; my_cos(all, k, 2, plan); translate2(plan, &all->eye); unrotate(all); calc_lum_vector(all, plan); } else { printf("inside plan\n"); plan->k = -1; unrotate(all); translate2(plan, &all->eye); } }
void twilight_path_compute_current(TwilightPath *pTwilightPath, struct tm * localTime) { ///BUGBUG: This is 12 hours, or 1/2 day. Why is this value needed? const float timeFudge = 12.0f; // Find time of day for dawn and dusk times. Results are expressed // as local hour-of-day, with minutes as fraction of an hour. float fDawnTime; float fDuskTime; calcRiseAndSet(&fDawnTime, &fDuskTime, localTime, pTwilightPath->fZenith); // save true dawn / dusk times pTwilightPath->fDawnTime = fDawnTime; pTwilightPath->fDuskTime = fDuskTime; // Update dawn / dusk points to reflect zenith at present location / date. fDawnTime += timeFudge; GPoint dawnPoint = GPoint((int16_t)(my_sin(fDawnTime / 24 * M_PI * 2) * 120), 9 - (int16_t)(my_cos(fDawnTime / 24 * M_PI * 2) * 120)); fDuskTime += timeFudge; GPoint duskPoint = GPoint((int16_t)(my_sin(fDuskTime / 24 * M_PI * 2) * 120), 9 - (int16_t)(my_cos(fDuskTime / 24 * M_PI * 2) * 120)); // do the point init which twilight_path_create() couldn't. if (pTwilightPath->toEnclose == ENCLOSE_SCREEN_TOP) { pTwilightPath->aPathPoints[1] = dawnPoint; pTwilightPath->aPathPoints[4] = duskPoint; } else { pTwilightPath->aPathPoints[1] = duskPoint; pTwilightPath->aPathPoints[4] = dawnPoint; } // (Actual GPath creation is done in twilight_path_draw_filled().) return; } /* end of twilight_path_compute_current */
void inter_cyl(t_all *all, t_object *cyl) { t_inter i; translate1(cyl, &all->eye); rotate(all, cyl); i.a = pow(all->eye.vx, 2) + pow(all->eye.vy, 2); i.b = 2 * (all->eye.x * all->eye.vx + all->eye.y * all->eye.vy); i.c = pow(all->eye.x, 2) + pow(all->eye.y, 2) - pow(cyl->ray, 2); i.delta = i.b * i.b - 4 * i.a * i.c; i.k = (-i.b - sqrt(i.delta)) / (2 * i.a); i.k2 = (-i.b + sqrt(i.delta)) / (2 * i.a); if (i.k < i.k2 && i.k > 0.00001) { cyl->k = i.k; my_cos(all, i.k, 3, cyl); unrotate(all); translate2(cyl, &all->eye); calc_lum_vector(all, cyl); } else if (i.k2 < i.k && i.k2 > 0.00001) { cyl->k = i.k2; my_cos(all, i.k2, 3, cyl); unrotate(all); translate2(cyl, &all->eye); calc_lum_vector(all, cyl); } else { unrotate(all); translate2(cyl, &all->eye); } if (i.delta <= 0) cyl->k = -1; }
void set_camera_mtx(double *m, t_vector *dir, t_vector *pos, double roll) { t_vector a[4]; a[0].x = my_sin(roll); a[0].y = -my_cos(roll); a[0].z = 0; normalize(a); normalize(dir); a[3].x = -dir->x; a[3].y = -dir->y; a[3].z = -dir->z; a[1].x = a[3].z * a[0].y - a[3].y * a[0].z; a[1].y = a[3].x * a[0].z - a[3].z * a[0].x; a[1].z = a[3].y * a[0].x - a[3].x * a[0].y; a[2].x = a[1].y * a[3].z - a[1].z * a[3].y; a[2].y = a[1].z * a[3].x - a[1].x * a[3].z; a[2].z = a[1].x * a[3].y - a[1].y * a[3].x; set_camera_mtx_(m, a, pos); }
int main() { int action = 0; char exitFlag = 0; while(exitFlag == 0){ printf("1) Add\n"); printf("2) Sub\n"); printf("3) Mul\n"); printf("4) Div\n"); printf("5) Mod\n"); printf("6) AddMod2\n"); printf("7) Sin\n"); printf("8) Cos\n"); printf("9) Tan\n"); printf("10) ArcTan\n"); printf("11) Factorial\n"); printf("12) Exit\n" ); printf("Action: "); scanf("%d", &action); getchar(); fflush(stdin); sync(); switch(action) { case(1): add(); break; case(2): sub_func(); break; case(3): multiplication(); break; case(4): Div(); break; case(5): mod(); break; case(6): modul2(); break; case(7): sinus(); break; case(8): my_cos(); break; case(9): tang(); break; case(10): arctg(); break; case(11): factorial(); break; case(12): exitFlag = 1; break; default: printf("Wrong index\n"); } } return 0; }
/*Draw the circles which reflects the beat*/ void drawWaveformCircles(struct winampVisModule *this_mod, int numSamples) { double istep = groundRad/numSamples; double jstep = 0.05; double beatFactor = (((double)winampDetectBass(this_mod, 0,100)/100.0)*0.2)+0.8; double color = (double)winampDetectBass(this_mod, 0, 100)/100.0 + .01; for (double i = groundRad; i > 0; i -= istep) { glColor3d(color,1,color); glLineWidth(2.0); glBegin(GL_LINE_LOOP); double steps=1; for(double x = 1; x > 0; x -= .02) { glVertex3d(beatFactor*i*my_cos(x), 0.0, beatFactor*i*my_sin(x) ); } glEnd(); } }
float my_tan(float x) { return my_sin(x) / my_cos(x); }
float calcSun(int year, int month, int day, float latitude, float longitude, int sunset, float zenith) { int N1 = my_floor(275 * month / 9); int N2 = my_floor((month + 9) / 12); int N3 = (1 + my_floor((year - 4 * my_floor(year / 4) + 2) / 3)); int N = N1 - (N2 * N3) + day - 30; float lngHour = longitude / 15; float t; if (!sunset) { //if rising time is desired: t = N + ((6 - lngHour) / 24); } else { //if setting time is desired: t = N + ((18 - lngHour) / 24); } float M = (0.9856 * t) - 3.289; //calculate the Sun's true longitude //L = M + (1.916 * sin(M)) + (0.020 * sin(2 * M)) + 282.634 float L = M + (1.916 * my_sin((M_PI/180.0f) * M)) + (0.020 * my_sin((M_PI/180.0f) * 2 * M)) + 282.634; if (L<0) L+=360.0f; if (L>360) L-=360.0f; //5a. calculate the Sun's right ascension //RA = atan(0.91764 * tan(L)) float RA = (180.0f/M_PI) * my_atan(0.91764 * my_tan((M_PI/180.0f) * L)); if (RA<0) RA+=360; if (RA>360) RA-=360; //5b. right ascension value needs to be in the same quadrant as L float Lquadrant = (my_floor( L/90)) * 90; float RAquadrant = (my_floor(RA/90)) * 90; RA = RA + (Lquadrant - RAquadrant); //5c. right ascension value needs to be converted into hours RA = RA / 15; //6. calculate the Sun's declination float sinDec = 0.39782 * my_sin((M_PI/180.0f) * L); float cosDec = my_cos(my_asin(sinDec)); //7a. calculate the Sun's local hour angle //cosH = (cos(zenith) - (sinDec * sin(latitude))) / (cosDec * cos(latitude)) float cosH = (my_cos((M_PI/180.0f) * zenith) - (sinDec * my_sin((M_PI/180.0f) * latitude))) / (cosDec * my_cos((M_PI/180.0f) * latitude)); if (cosH > 1) { return 0; } else if (cosH < -1) { return 0; } //7b. finish calculating H and convert into hours float H; if (!sunset) { //if rising time is desired: H = 360 - (180.0f/M_PI) * my_acos(cosH); } else { //if setting time is desired: H = (180.0f/M_PI) * my_acos(cosH); } H = H / 15; //8. calculate local mean time of rising/setting float T = H + RA - (0.06571 * t) - 6.622; //9. adjust back to UTC float UT = T - lngHour; if (UT<0) {UT+=24;} if (UT>24) {UT-=24;} time_t now = time(NULL); struct tm *tick_time = localtime(&now); struct tm *gm_time = gmtime(&now); int timezoneoffset = 60 * (60 * (24 * (tick_time->tm_wday - gm_time->tm_wday) + tick_time->tm_hour - gm_time->tm_hour) + tick_time->tm_min - gm_time->tm_min); // Correct for transitions at the end of the week. int SECONDS_IN_WEEK=604800; if (timezoneoffset > SECONDS_IN_WEEK/2) timezoneoffset -= SECONDS_IN_WEEK; if (timezoneoffset < -SECONDS_IN_WEEK/2) timezoneoffset += SECONDS_IN_WEEK; timezoneoffset /= 3600; APP_LOG(APP_LOG_LEVEL_DEBUG, "timezone offset %d", timezoneoffset); APP_LOG(APP_LOG_LEVEL_DEBUG, "other timezone offset %d", (tick_time-gm_time)); // return UT+(tick_time-gm_time); return UT; }
float calcSun(int year, int month, int day, float latitude, float longitude, int sunset, float zenith) { int N1 = my_floor(275 * month / 9); int N2 = my_floor((month + 9) / 12); int N3 = (1 + my_floor((year - 4 * my_floor(year / 4) + 2) / 3)); int N = N1 - (N2 * N3) + day - 30; float lngHour = longitude / 15; float t; if (!sunset) { //if rising time is desired: t = N + ((6 - lngHour) / 24); } else { //if setting time is desired: t = N + ((18 - lngHour) / 24); } float M = (0.9856 * t) - 3.289; //calculate the Sun's true longitude //L = M + (1.916 * sin(M)) + (0.020 * sin(2 * M)) + 282.634 float L = M + (1.916 * my_sin((M_PI/180.0f) * M)) + (0.020 * my_sin((M_PI/180.0f) * 2 * M)) + 282.634; if (L<0) L+=360.0f; if (L>360) L-=360.0f; //5a. calculate the Sun's right ascension //RA = atan(0.91764 * tan(L)) float RA = (180.0f/M_PI) * my_atan(0.91764 * my_tan((M_PI/180.0f) * L)); if (RA<0) RA+=360; if (RA>360) RA-=360; //5b. right ascension value needs to be in the same quadrant as L float Lquadrant = (my_floor( L/90)) * 90; float RAquadrant = (my_floor(RA/90)) * 90; RA = RA + (Lquadrant - RAquadrant); //5c. right ascension value needs to be converted into hours RA = RA / 15; //6. calculate the Sun's declination float sinDec = 0.39782 * my_sin((M_PI/180.0f) * L); float cosDec = my_cos(my_asin(sinDec)); //7a. calculate the Sun's local hour angle //cosH = (cos(zenith) - (sinDec * sin(latitude))) / (cosDec * cos(latitude)) float cosH = (my_cos((M_PI/180.0f) * zenith) - (sinDec * my_sin((M_PI/180.0f) * latitude))) / (cosDec * my_cos((M_PI/180.0f) * latitude)); if (cosH > 1) { // no sunrise here on this day return 100; // watchface won't draw indicator if this value is found } else if (cosH < -1){ // no sunset here on this day return 100; // watchface won't draw indicator if this value is found } //7b. finish calculating H and convert into hours float H; if (!sunset) { //if rising time is desired: H = 360 - (180.0f/M_PI) * my_acos(cosH); } else { //if setting time is desired: H = (180.0f/M_PI) * my_acos(cosH); } H = H / 15; //8. calculate local mean time of rising/setting float T = H + RA - (0.06571 * t) - 6.622; //9. adjust back to UTC float UT = T - lngHour; if (UT<0) {UT+=24;} if (UT>24) {UT-=24;} return UT; }
void displayScene (struct winampVisModule *this_mod) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GLfloat lcolor = (GLfloat)winampDetectBass(this_mod,0,100)/100.0; rotateFactor += rotateRate; if (rotateFactor >= 1.0) rotateFactor = 0.0; /*Draw circle surface*/ if(SURFACE) { glColor3d(0.86,0.86,0.86); glBegin(GL_POLYGON); glVertex3d(0.0,0.0,0.0); for(double x = 1.02; x >=0; x -= .02) { glVertex3d(groundRad*my_cos(x), 0.0, groundRad*my_sin(x) ); } glEnd(); } if (WAVEFORMCIRCLES) { drawWaveformCircles(this_mod, NUM_CIRCLES); } /*Draw spheres and belonging cones to bump them*/ for(int o=0; o<NUMSPHERES; o++) { glPushMatrix(); //store the origin //get the next sphere from the ordered list by index i int i=order[o][0]; //Draw cones if(CONES) { glColor3d(0.9,0.9,0.9); glTranslatef(sphere[i].x,0.0,sphere[i].z); glRotatef(-90.0,1.0,0.0,0.0); //The cone is always 1/10 high as the height of its sphere if(sphere[i].firstUp) { glutSolidCone(sphere[i].r/1.5, sphere[i].height/10, 20.0+sphere[i].height/10, 10.0+sphere[i].height/8); } //if ball is bouncing draw the cone pretty small else { glutSolidCone(sphere[i].r/1.5, 0.1, 20.0+(int)((1-NUMSPHERES/MAXSPHERES)*(sphere[i].r/10)), 3.0); } glPopMatrix(); glPushMatrix(); } //-------->>>>> //Sound input for the balls goes here for sphere with size sphere[i].r //Input ranges from 0-MAXSTRENGTH, so now from 0-100 //the input is only computed if the ball is not in the air if (!sphere[i].inAir) input=computeSoundInput(i, NUMSPHERES, this_mod, BT_BEAT); //this function bumps the ball up and is called each time, it actually just bumps the ball up, //when it is on the ground and so just disregard the input if not. bump(&sphere[i], input); //-------->>>>> //Draw the sphere if (SPHERES) { glColor3fv(sphere[i].color); glTranslatef(sphere[i].x,sphere[i].r+sphere[i].height,sphere[i].z); if(SQUASH) { double squash = (sphere[i].height/100.0)*0.6 + 0.5; glScaled(1.0, squash,1.0); } glutSolidSphere(sphere[i].r, 20.0+(int)((1-NUMSPHERES/MAXSPHERES)*(sphere[i].r/10)), 50.0+(int)((1-NUMSPHERES/MAXSPHERES)*(sphere[i].r))); } glPopMatrix(); //restore the origin } /*Text output*/ setOrthographicProjection(); //switch to orthographic projection to easier print out text glPushMatrix(); glLoadIdentity(); //Data ouput of current settings if(OUTPUT) { char temp[50]; glColor4f(1.0,1.0,1.0, 1.0); //Number of Balls sprintf(temp," # Balls: %.d", NUMSPHERES); printOut(10,10,temp); //Balls on/off? sprintf(temp," Balls: %s", (SPHERES)?"on":"off"); printOut(10,25,temp); //Airtime sprintf(temp," max. Airtime: %.1f", NUMSEC); printOut(10,40,temp); //Speedfactor sprintf(temp," Speedfactor: %.1f", SPEEDFACTOR); printOut(10,55,temp); //Cones on/off? sprintf(temp," Cones: %s", (CONES)?"on":"off"); printOut(10,70,temp); //Surface on/off? sprintf(temp," Surface: %s", (SURFACE)?"on":"off"); printOut(10,85,temp); //Bouncing balls? sprintf(temp,"Bouncing Balls: %s", (BOUNCE)?"on":"off"); printOut(10,100,temp); //Squash balls? sprintf(temp," Squash Balls: %s", (SQUASH)?"on":"off"); printOut(10,115,temp); //Beat Circles? sprintf(temp," Beat Circles: %s", (WAVEFORMCIRCLES)?"on":"off"); printOut(10, 130, temp); //Color change? sprintf(temp," Change color: %s", (COLORCHANGE)?"on":"off"); printOut(10,145,temp); //Index color of balls printOut(10,160," Start color: "); char * color; if(COLOR==0) color="white"; if(COLOR==1) {color="red"; glColor3f(1.0,0.0,0.0);} if(COLOR==2) {color="green"; glColor3f(0.0,1.0,0.0);} if(COLOR==3) {color="blue"; glColor3f(0.0,0.0,1.0);} if(COLOR==4) {color="yellow"; glColor3f(1.0,1.0,0.0);} if(COLOR==5) {color="magenta"; glColor3f(1.0,0.0,1.0);} if(COLOR==6) {color="cyan"; glColor3f(0.0,1.0,1.0);} sprintf(temp,"%s", color); printOut(138,160,temp); glColor3f(1.0, 1.0, 1.0); //help message if(!HELP) { glColor3f(1.0,1.0,0.0); printOut(width-20*8,10,"Press \'h\' for help!"); } } //help instructions if(HELP) { glColor3f(1.0,1.0,0.0); int x=200; int y=0; printOut(x,y+10," h = switch help on/off"); printOut(x,y+25," o = switch output of the current settings on/off"); printOut(x,y+55,"z/x = decrease/increase number of balls"); printOut(x,y+70,"u/i = decrease/increase the maximum airtime of the balls"); printOut(x,y+85,"j/k = decrease/increase the speed factor of the balls"); printOut(x,y+100,"n/m = decrease/increase the start color of the balls"); printOut(x,y+130," c = display cones?"); printOut(x,y+145," s = display white circle surface?"); printOut(x,y+160," w = display beat circles?"); printOut(x,y+175," a = display balls?"); printOut(x,y+190," b = allow balls to bounce on the ground?"); printOut(x,y+205," t = allow balls to be squashed?"); printOut(x,y+220," l = allow balls to change color?"); printOut(x,y+250," r = reset all settings to default value"); printOut(x,y+280,"by Ryan Messner and Simon Beisel"); } glPopMatrix(); resetPerspectiveProjection(); //reset to old view glFlush(); /* clear buffers */ //glutSwapBuffers(); /*swap the buffers*/ }