void updateCamera(Scene* scene) { double time = WallClockTime() - sceneTimeOffset; double rtime = (time / 21.35634); // camera rotation time rtime = rtime - floor(rtime); double btime = (time / 59.8752); // camera bobbing time btime = btime - floor(btime); double ltime = (time / 98.7654); // light rotation time ltime = ltime - floor(ltime); double lbtime = (time / 92.764); // light bobbing time lbtime = lbtime - floor(lbtime); camInit(scene->cam); cl_float3 pos; cl_float3 center; vecInit(center, 14.9f, 9.7f, -14.85f); vecInit(pos, 33.0f * sin(rtime * M_PI * 2.0), 8.0f * sin(btime * M_PI * 2.0 + 0.3), 33.0f * (cos(rtime * M_PI * 2.0) - 0.11)); vecAdd(pos, center); camMove(scene->cam, pos); camLookAt(scene->cam, center); vecInit(pos, 5.0f * sin(-ltime * M_PI * 2.0), 8.0f + 6.0f * sin(lbtime * M_PI * 2.0), 5.0f * cos(ltime * M_PI * 2.0)); vecNormalize(pos); scene->lightDir = pos; }
void resetFollow() { g_pFollowing = 0; camInputFly(g_Input, false); camInit(g_Camera); camInputInit(g_Input); camInputExplore(g_Input, true); }
int main(void){ cli();//disable interrupts /* Setup the 8mhz PWM clock * This will be on pin 11*/ DDRB|=(1<<3);//pin 11 ASSR &= ~(_BV(EXCLK) | _BV(AS2)); TCCR2A=(1<<COM2A0)|(1<<WGM21)|(1<<WGM20); TCCR2B=(1<<WGM22)|(1<<CS20); OCR2A=0;//(F_CPU)/(2*(X+1)) DDRC&=~15;//low d0-d3 camera DDRD&=~252;//d7-d4 and interrupt pins _delay_ms(3000); //set up twi for 100khz TWSR&=~3;//disable prescaler for TWI TWBR=72;//set to 100khz //enable serial UBRR0H=0; UBRR0L=1;//0 = 2M baud rate. 1 = 1M baud. 3 = 0.5M. 7 = 250k 207 is 9600 baud rate. UCSR0A|=2;//double speed aysnc UCSR0B = (1<<RXEN0)|(1<<TXEN0);//Enable receiver and transmitter UCSR0C=6;//async 1 stop bit 8bit char no parity bits camInit(); #ifdef useVga setRes(VGA); setColorSpace(BAYER_RGB); wrReg(0x11,25); #elif defined(useQvga) setRes(QVGA); setColorSpace(YUV422); wrReg(0x11,12); #else setRes(QQVGA); setColorSpace(YUV422); wrReg(0x11,3); #endif /* If you are not sure what value to use here for the divider (register 0x11) * Values I have found to work raw vga 25 qqvga yuv422 12 qvga yuv422 21 * run the commented out test below and pick the smallest value that gets a correct image */ while (1){ /* captureImg operates in bytes not pixels in some cases pixels are two bytes per pixel * So for the width (if you were reading 640x480) you would put 1280 if you are reading yuv422 or rgb565 */ /*uint8_t x=63;//Uncomment this block to test divider settings note the other line you need to uncomment do{ wrReg(0x11,x); _delay_ms(1000);*/ #ifdef useVga captureImg(640,480); #elif defined(useQvga) captureImg(320*2,240); #else captureImg(160*2,120); #endif //}while(--x);//Uncomment this line to test divider settings } }
/*** Initialize the camera module. @function init @treturn[1] boolean `true` if everything went fine @treturn[2] boolean `false` in case of error @treturn[2] integer error code */ static int cam_init(lua_State *L) { Result ret = camInit(); if (ret) { lua_pushboolean(L, false); lua_pushinteger(L, ret); return 2; } lua_pushboolean(L, true); return 1; }
int main(int argc, char **argv) { // Initialize the GLUT framework. if (!glueInit(550, 800, argc, argv, kernelRun)) { return 1; } std::string path( argv[ 0 ] ); int lastSlash = path.find_last_of( "\\" ); path.resize( lastSlash + 1 ); path.append( "../../content/" ); // Load an asvo from file. Object3d imrod = obj3dInit(BFSOctreeImport ( ( path + "imrod.asvo" ).c_str(), ( path + "diffuse.raw" ).c_str(), ( path + "illum.raw" ).c_str(), ( path + "spec.raw" ).c_str(), ( path + "normal.raw" ).c_str() ), true); Vector3 rotAxis = { 1.f, 0.f, 0.f }; obj3dAssignTransform(&imrod, h_createRotation(rotAxis, -1.5707f)); // Copy the model to device memory. BFSOctreeCopyToDevice(&imrod.data); // Set up the camera. Vector3 pos = { 0.f, 25.f, -100.f }; Vector3 lookAt = { 0.f, 0.f, 0.f }; camInit(pos, lookAt, 1.f, glueGetWindowRatio(), 10.f, 200.f); // Set up the light. Vector3 light = { -1.f, -0.5f, 0.5f }; lightSet(light, 0.8f); // Set which model to render (only one supported at the moment). kernelSetParams(imrod); // Start the main render-and-update loop glutMainLoop(); // Do cleanup work. BFSOctreeCleanup(&imrod.data); kernelCleanup(); glueCleanup(); return 0; }
void myInit() { initMaths(); camInit(g_Camera); camInputInit(g_Input); camInputExplore(g_Input, true); glClearColor(0.01f, 0.01f, 0.01f, 0.0f); //sets the colour values to use when clearing the colours, essentially sets the canvas colour glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHT0); //sets the colour of the light (0 == white) glEnable(GL_LIGHTING); //allows GL to make lighting calculations glEnableClientState(GL_VERTEX_ARRAY); pushTail(initSun(createNewElement())); //init sun loadTextures(); }
int main(int argc, char * argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(640, 480); glutCreateWindow("Load Wavefront Obj"); glutIdleFunc(&render); glutKeyboardFunc(&key_down); glutKeyboardUpFunc(&key_up); glMatrixMode(GL_PROJECTION); gluPerspective(45, 640.0 / 480.0, 1, 100); glMatrixMode(GL_MODELVIEW); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_CULL_FACE); /* lighting */ { float light_pos[] = { 0, 0, 0, 1 }; float white_light[] = { 1.1, 1.1, 1.1, 1 }; float ambient[] = { 0.4, 0.4, 0.4, 1 }; glLightfv(GL_LIGHT0, GL_POSITION, light_pos); glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT0, GL_SPECULAR, white_light); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } glClearColor(0, 0, 0, 0); glEnable(GL_DEPTH_TEST); glClearDepth(1.0); camInit(); FILE * fp = fopen("xxx.obj", "r"); go = load_obj(fp); fclose(fp); glutMainLoop(); return 0; }
//! A appeller juste avant la boucle principale (Main Loop) et après la creation de a fenetre GLvoid GLInit(GLsizei Width, GLsizei Height) { printf("repertoire courant="); system("pwd"); glEnable(GL_TEXTURE_2D); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // The Background Color = Black glClearDepth(1.0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); // Indique à GL de calculer la couleur suivant la formule // couleur_du_buffer = alpha * couleur_polygone + (1-alpha)*couleur_du_buffer_de_fond glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); // Indique à GL d'eliminer les fragments du polygones qui sont transparents // (On ne garde que les pixel dont alpha>0.01, ) glAlphaFunc(GL_GREATER, 0.01f); glDisable(GL_ALPHA_TEST) ; glEnable( GL_NORMALIZE); // set up lights. glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, LightSpecular); glLightfv(GL_LIGHT1, GL_POSITION, LightPosition); glEnable(GL_LIGHT1); if (bLight) glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glEnable( GL_COLOR_MATERIAL ); //glDisable( GL_COLOR_MATERIAL ); camInit(cam); sceneInit( scene ); }
static void task_capture_cam_thread(void* arg) { capture_cam_data* data = (capture_cam_data*) arg; Handle events[EVENT_COUNT] = {0}; events[EVENT_CANCEL] = data->cancelEvent; Result res = 0; u32 bufferSize = data->width * data->height * sizeof(u16); u16* buffer = (u16*) calloc(1, bufferSize); if(buffer != NULL) { if(R_SUCCEEDED(res = camInit())) { u32 cam = data->camera == CAMERA_OUTER ? SELECT_OUT1 : SELECT_IN1; if(R_SUCCEEDED(res = CAMU_SetSize(cam, SIZE_CTR_TOP_LCD, CONTEXT_A)) && R_SUCCEEDED(res = CAMU_SetOutputFormat(cam, OUTPUT_RGB_565, CONTEXT_A)) && R_SUCCEEDED(res = CAMU_SetFrameRate(cam, FRAME_RATE_30)) && R_SUCCEEDED(res = CAMU_SetNoiseFilter(cam, true)) && R_SUCCEEDED(res = CAMU_SetAutoExposure(cam, true)) && R_SUCCEEDED(res = CAMU_SetAutoWhiteBalance(cam, true)) && R_SUCCEEDED(res = CAMU_Activate(cam))) { u32 transferUnit = 0; if(R_SUCCEEDED(res = CAMU_GetBufferErrorInterruptEvent(&events[EVENT_BUFFER_ERROR], PORT_CAM1)) && R_SUCCEEDED(res = CAMU_SetTrimming(PORT_CAM1, true)) && R_SUCCEEDED(res = CAMU_SetTrimmingParamsCenter(PORT_CAM1, data->width, data->height, 400, 240)) && R_SUCCEEDED(res = CAMU_GetMaxBytes(&transferUnit, data->width, data->height)) && R_SUCCEEDED(res = CAMU_SetTransferBytes(PORT_CAM1, transferUnit, data->width, data->height)) && R_SUCCEEDED(res = CAMU_ClearBuffer(PORT_CAM1)) && R_SUCCEEDED(res = CAMU_SetReceiving(&events[EVENT_RECV], buffer, PORT_CAM1, bufferSize, (s16) transferUnit)) && R_SUCCEEDED(res = CAMU_StartCapture(PORT_CAM1))) { bool cancelRequested = false; while(!task_is_quit_all() && !cancelRequested && R_SUCCEEDED(res)) { svcWaitSynchronization(task_get_pause_event(), U64_MAX); s32 index = 0; if(R_SUCCEEDED(res = svcWaitSynchronizationN(&index, events, EVENT_COUNT, false, U64_MAX))) { switch(index) { case EVENT_CANCEL: cancelRequested = true; break; case EVENT_RECV: svcCloseHandle(events[EVENT_RECV]); events[EVENT_RECV] = 0; svcWaitSynchronization(data->mutex, U64_MAX); memcpy(data->buffer, buffer, bufferSize); GSPGPU_FlushDataCache(data->buffer, bufferSize); svcReleaseMutex(data->mutex); res = CAMU_SetReceiving(&events[EVENT_RECV], buffer, PORT_CAM1, bufferSize, (s16) transferUnit); break; case EVENT_BUFFER_ERROR: svcCloseHandle(events[EVENT_RECV]); events[EVENT_RECV] = 0; if(R_SUCCEEDED(res = CAMU_ClearBuffer(PORT_CAM1)) && R_SUCCEEDED(res = CAMU_SetReceiving(&events[EVENT_RECV], buffer, PORT_CAM1, bufferSize, (s16) transferUnit))) { res = CAMU_StartCapture(PORT_CAM1); } break; default: break; } } } CAMU_StopCapture(PORT_CAM1); bool busy = false; while(R_SUCCEEDED(CAMU_IsBusy(&busy, PORT_CAM1)) && busy) { svcSleepThread(1000000); } CAMU_ClearBuffer(PORT_CAM1); } CAMU_Activate(SELECT_NONE); } camExit(); } free(buffer); } else { res = R_APP_OUT_OF_MEMORY; } for(int i = 0; i < EVENT_COUNT; i++) { if(events[i] != 0) { svcCloseHandle(events[i]); events[i] = 0; } } svcCloseHandle(data->mutex); data->result = res; data->finished = true; }
int main(int argc, char *argv[]) { SDL_Surface *screen; if (argc > 1) { screen = gu_init_SDL("URS Ship Viewer", atoi(argv[1])); } else { screen = gu_init_SDL("URS Ship Viewer", 0); } gu_init_GL(); gu_init_display(display); skuInitKeyBinder(&kb); skuBindKeyHandler(&kb, SDLK_BACKSPACE, reinitCam); skuBindKeyHandler(&kb, SDLK_UP, rotateUp); skuBindKeyHandler(&kb, SDLK_DOWN, rotateDown); skuBindKeyHandler(&kb, SDLK_LEFT, rotateLeft); skuBindKeyHandler(&kb, SDLK_RIGHT, rotateRight); skuBindKeyHandler(&kb, SDLK_z, zoom); skuBindKeyHandler(&kb, SDLK_s, dezoom); skuBindKeyHandler(&kb, SDLK_q, left); skuBindKeyHandler(&kb, SDLK_d, right); camInit(&camera); gu_initLights(); GLfloat whiteLight[4] = {1, 1, 1, 1}; GLfloat blackLight[4] = {0, 0, 0, 1}; glLightfv(GL_LIGHT0, GL_AMBIENT, blackLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight); glMatrixMode(GL_PROJECTION); gluPerspective(50, (float) screen->w / screen->h, 1, 10000); glMatrixMode(GL_MODELVIEW); reinitCam(); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); initShip(&ship, 0, 0, 0); initSun(&sun, 0, 30, 30, 3, 0, 0, 0, 0); GLuint texDesc; gu_initTextures(&texDesc, 1, 1, "space.png"); initSpace(&space, 0, 0, 0, 10, 0, 0, texDesc, 10); continuer = 1; SDL_Event event; Uint32 startTime; Uint32 ellapsedTime = 0; int frameNb = 0; //Boucle principale while (continuer) { //Les FPS startTime = SDL_GetTicks(); if (ellapsedTime >= 1000) { printf("\r~%d fps", frameNb); fflush(stdout); ellapsedTime = 0; frameNb = 0; } //Les events while (SDL_PollEvent(&event)) { eventCatcher(&event); } skuHandle(&kb); gu_display(); frameNb++; ellapsedTime += SDL_GetTicks() - startTime; } //C'est finit, libération des ressources printf("\n"); gu_SDLQuit(1); exit(EXIT_SUCCESS); }
//! Quand une touche est pressée void keyPressed(unsigned char key, int x, int y) { //usleep(100); switch (key) { case ESCAPE: // termine exit(1); break; case 'h': case 'H': help(); break; case 'z': case 'Z': bAnim = !bAnim; break; case 'g': case 'G': bGrid = !bGrid; break; case 'a': case 'A': bAxe = !bAxe; break; case 'f': case 'F': if (cam.flyOrTrackball==CAMERA_TRACKBALL) camSetFlyTrackballMode(cam, CAMERA_FLY); else camSetFlyTrackballMode(cam, CAMERA_TRACKBALL); printf("Camera fly=0 or trackball=1 : %d\n", cam.flyOrTrackball); break; case 'I': LightPosition[0] = 5.0f; LightPosition[1] = 15.0f; LightPosition[2] = 5.0f; break; case 'i': camInit(cam); break; case 'w': case 'W': bWireframe = !bWireframe; if (bWireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); printf("wireframe=%d\n", bWireframe); break; case 'b': case 'B': // switch the blending //~ printf("B/b pressed; blending is: %d\n", bBlend); bBlend = bBlend ? 0 : 1; // switch the current value of blend, between 0 and 1. if (bBlend) { glEnable(GL_BLEND); glEnable(GL_ALPHA_TEST) ; } else { glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); } printf("Blending is now: %d\n", bBlend); break; case 'l': case 'L': // switch the lighting //~ printf("L/l pressed; lighting is: %d\n", bLight); bLight = bLight ? 0 : 1; // switch the current value of light, between 0 and 1. if (bLight) { glEnable(GL_LIGHTING); } else { glDisable(GL_LIGHTING); } printf("Lighting is now: %d\n", bLight); break; default: printf ("Key %d pressed. No action there yet.\n", key); break; } }
void setupAnim(Scene* scene, int imgWidth, int imgHeight) { // Positions Everybody! scene->numSpheres = NUMSPHERES; // three mirrored juggling spheres for (int i = 0; i <= 2; i++) { scene->spheres[i].radius = 1.4f; vecInit(scene->spheres[i].color, 0.5f, 0.5f, 0.5f); scene->spheres[i].ambient = 0.1f; scene->spheres[i].diffuse = 0.3f; scene->spheres[i].highlight = 0.8f; scene->spheres[i].roughness = 0.05f; scene->spheres[i].reflection = 0.8f; } vecInit(scene->spheres[0].center, 11.0f, 0.0f, 0.0f); vecInit(scene->spheres[1].center, 11.0f, 0.0f, 0.0f); vecInit(scene->spheres[2].center, 11.0f, 0.0f, 0.0f); // torso: seven spheres for (int i = 3; i <= 10; i++) { float fraction = float(i - 3) / 7.0f; scene->spheres[i].radius = 1.6f + 0.4f * fraction; vecInit(scene->spheres[i].center, 15.1f, 8.5f + 3.2f * fraction, -15.1f); vecInit(scene->spheres[i].color, 0.843f, 0.12f, 0.11f); scene->spheres[i].ambient = 0.3f; scene->spheres[i].diffuse = 0.8f; scene->spheres[i].highlight = 1.0f; scene->spheres[i].roughness = 0.1f; scene->spheres[i].reflection = 0.0f; } // head scene->spheres[11].radius = 1.4; vecInit(scene->spheres[11].center, 15.1f, 15.5f, -15.1f); vecInit(scene->spheres[11].color, 0.95f, 0.64f, 0.63f); scene->spheres[11].ambient = 0.25f; scene->spheres[11].diffuse = 0.9f; scene->spheres[11].highlight = 1.0f; scene->spheres[11].roughness = 0.1f; scene->spheres[11].reflection = 0.0f; // neck scene->spheres[12].radius = 0.5; vecInit(scene->spheres[12].center, 15.1f, 14.0f, -15.1f); vecInit(scene->spheres[12].color, 0.95f, 0.64f, 0.63f); scene->spheres[12].ambient = 0.25f; scene->spheres[12].diffuse = 0.9f; scene->spheres[12].highlight = 1.0f; scene->spheres[12].roughness = 0.1f; scene->spheres[12].reflection = 0.0f; // outer limb parts for (int i = 13; i <= 20; i++) { for (int j = 0; j < 4; j++) { scene->spheres[i + 17 * j].radius = 0.25f + 0.25f * float(i - 13) / 7.0f; vecInit(scene->spheres[i + 17 * j].center, 0.0f, 0.0f, 0.0f); vecInit(scene->spheres[i + 17 * j].color, 0.95f, 0.64f, 0.63f); scene->spheres[i + 17 * j].ambient = 0.25f; scene->spheres[i + 17 * j].diffuse = 0.9f; scene->spheres[i + 17 * j].highlight = 1.0f; scene->spheres[i + 17 * j].roughness = 0.1f; scene->spheres[i + 17 * j].reflection = 0.0f; } } // inner limb parts for (int i = 21; i <= 29; i++) { for (int j = 0; j < 4; j++) { scene->spheres[i + 17 * j].radius = 0.5f; vecInit(scene->spheres[i + 17 * j].center, 0.0f, 0.0f, 0.0f); vecInit(scene->spheres[i + 17 * j].color, 0.95f, 0.64f, 0.63f); scene->spheres[i + 17 * j].ambient = 0.25f; scene->spheres[i + 17 * j].diffuse = 0.9f; scene->spheres[i + 17 * j].highlight = 1.0f; scene->spheres[i + 17 * j].roughness = 0.1f; scene->spheres[i + 17 * j].reflection = 0.0f; } } // eyes scene->spheres[81].radius = 0.4; vecInit(scene->spheres[81].center, 14.2f, 15.4f, -14.4f); vecInit(scene->spheres[81].color, 0.121f, 0.105f, 0.58f); scene->spheres[81].ambient = 0.25f; scene->spheres[81].diffuse = 0.9f; scene->spheres[81].highlight = 1.0f; scene->spheres[81].roughness = 0.1f; scene->spheres[81].reflection = 0.0f; scene->spheres[82].radius = 0.4; vecInit(scene->spheres[82].center, 14.2f, 15.4f, -14.4f); vecInit(scene->spheres[82].color, 0.121f, 0.105f, 0.58f); scene->spheres[82].ambient = 0.25f; scene->spheres[82].diffuse = 0.9f; scene->spheres[82].highlight = 1.0f; scene->spheres[82].roughness = 0.1f; scene->spheres[82].reflection = 0.0f; // hair scene->spheres[83].radius = 1.4; vecInit(scene->spheres[83].center, 15.2f, 15.4f, -15.1f); vecInit(scene->spheres[83].color, 0.15f, 0.066f, 0.09f); scene->spheres[83].ambient = 0.25f; scene->spheres[83].diffuse = 0.9f; scene->spheres[83].highlight = 1.0f; scene->spheres[83].roughness = 0.1f; scene->spheres[83].reflection = 0.0f; // Lights! vecInit(scene->lightDir, -56.4f, 68.6f, 34.7f); vecNormalize(scene->lightDir); // Camera! camInit(scene->cam); cl_float3 tmp; vecInit(tmp, -7.8f, 10.0f, 7.8f); camMove(scene->cam, tmp); vecInit(tmp, 80.0f, 10.7f, -100.0f); camLookAt(scene->cam, tmp); scene->cam.imgWidth = imgWidth; scene->cam.imgHeight = imgHeight; // Action! animatePositions(scene, true); }