void PruebaVentana::Init3D() { mesh = MeshLoader::LoadFromX(m_d3ddevice, "media\\x\\tiger.x"); string errors; effect = Effect::FromFile(m_d3ddevice,"media\\shaders\\prueba.fx", ShaderFlags_None, errors); if(!errors.empty()) { MessageBox(NULL,errors.c_str(),"",0); } init_light(); m_d3ddevice.RenderState.Lighting = false; m_d3ddevice.RenderState.CullMode = Cull_None; m_d3ddevice.RenderState.ZBufferEnable = true; m_d3ddevice.RenderState.Ambient = D3DCOLOR_XRGB(50,50,50); m_d3ddevice.RenderState.NormalizeNormals = true; m_d3ddevice.RenderState.AlphaBlendEnable = true; m_d3ddevice.RenderState.blendOperation = BlendOperation_Add; m_d3ddevice.RenderState.SourceBlend = Blend_SourceAlpha; m_d3ddevice.RenderState.AlphaBlendEnable = true; m_d3ddevice.RenderState.fillMode = FillMode_Solid; FontDescription fd; fd.Height = 20; fd.FaceName = "Arial"; fd.Weight = FontWeight_Normal; font = Font(m_d3ddevice, fd); }
void calc_light(t_param *param, t_info *info, t_list *spot) { t_info *light; t_spot *o_spot; t_lum lum; int *s_color; if (info->distance < 0) return ; s_color = init_color(); while (spot) { o_spot = (t_spot *)spot->content; light = init_light(info, o_spot); calc_intersection(param, light); if (point_cmp(info->r_pos, light->r_pos) == 1) { lum.fading = ft_abs(calc_fading(light->r_line.vec, info->vec_n)); lum.shining = ft_abs(calc_shining(info->vec_n, light->r_line.vec)); info->light += o_spot->value * lum.fading; info->light += o_spot->value * lum.shining * lum.fading; calc_color(&s_color, o_spot->color, o_spot->value, lum.fading); } spot = spot->next; } info->color = retrieve_col(s_color, damer(param, info, info->s_pos), get_shine(info)); }
void get_light(t_tmp *tmp, t_obj obc, t_cod cor, t_sph *obj_a) { t_sph *tm; t_sph *obj_hit; double old_lx[3]; double old_n[3]; double r; double d; tm = obj_a; obj_hit = obc.nt; init_light(&cor, old_lx, old_n); while (obj_a) { if (obj_a->bri > 0) { set_r_d(&r, &d, &obc, obj_a); set_ray(&cor, obj_a, &obc); rand_vec(&(cor.l_x), (double)AR(atan(r / d))); calc_pt(tmp, &obc, &cor, tm); obc.bounce -= 80; do_lum(&obc, &cor, obj_hit, (2 * M_PI * (1 - (d / (sqrt(pow(d, 2) + pow(r, 2))))))); } obj_a = obj_a->nt; } de_init_light(&cor, old_lx, old_n); }
void setup() { glClearColor(0.0, 0.0, 0.0, 1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-RADIUS, RADIUS, -RADIUS, RADIUS, -RADIUS, RADIUS); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); init_light(GL_LIGHT0, 0, 1, 1, 1, 1, 1); init_light(GL_LIGHT1, 1, 0, 1, 1, 1, 1); init_light(GL_LIGHT2, 1, 1, 0, 1, 1, 1); init_balls(); init_bat(); }
t_data *init(void) { t_data *d; if(!(d = tt_malloc(sizeof(t_data)))) exit(tt_pl("Failed to alloc data")); d->r.o = VEC3(0, 0, 0); tt_pl("Init mlx"); init_mlx(d); tt_pl("Init obj"); init_obj(d); tt_pl("Init light"); init_light(d); return (d); }
void initDefault(void) { armData.x = 0.0; armData.y = (LARGE_CUBE_SIZE /2 )-1; armData.z = 0.0; armData.visible = UNVISIBLE; armData.inputDirection = INPUT_NO_DIRECTION; armData.inputEnable = INPUT_ENABLE; armData.inAnimation = IN_CONTROL; armData.counter = 0; init_light(); init_texture(); init_object(); }
/* * Construct and return a new world object. */ struct world_t* world_init() { struct world_t* w = (struct world_t*)malloc(sizeof(struct world_t)); memset(w, 0, sizeof(struct world_t)); w->flags = WORLD_DEFAULT_FLAGS; /* setup the camera */ init_camera(&w->camera); /* setup the environment */ init_env(&w->env); /* setup the main light */ init_light(&w->light[0]); return w; }
void initValores(){ glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); init_light (); }
void main() { char tmpchr; char retval; SD_addr addr=0; //number of characters since the start of the current sentence int sentence_start=-1; unsigned short sentence_finished=0; unsigned char file_created=0; unsigned long bytes_received = 0; char *rx_read = rx_buffer3; char *rx_read_start; WORD fat16_date, fat16_time; packet_type pkt_type=UNKNOWN; init_light(); SD_init(); init_uart(); init_fat16(); // init_slow_gps(); //INTCONbits.GIEH=1; //start 'er up RCSTA1bits.CREN=1; tmpchr = get_uart_byte(); wait_for_eol(); while (1) { tmpchr = get_uart_byte(); if (tmpchr == '$') { sentence_start=0; sentence_finished=0; pkt_type=UNKNOWN; } if (tmpchr == '\n') { sentence_start=0; sentence_finished=1; pkt_type=UNKNOWN; } // light_off(); //according to the data sheet 1=SPS mode(?), 2=DGPS SBS mode, 6=Dead Reconing(?) mean the fixes are valid if (pkt_type == GGA && sentence_start == 43 && !(tmpchr == '1' || tmpchr== '2' || tmpchr=='6')) { rx_read-=43; bytes_received-=43; wait_for_eol(); continue; } // in an RMC sentence, the "A" field indicates that a fix is valid if (pkt_type == RMC && sentence_start == 18 && tmpchr != 'A') { rx_read-=18; bytes_received-=18; wait_for_eol(); continue; } // only consider $GPGGA and $GPRMC packets by the 4th byte we can figure out if we need this transmission or not // if we don't need it, just roll back the pointers/counters in the buffer and throw away the remaining bytes in this sentence if (sentence_start == 4) { if (tmpchr == 'M') { pkt_type = RMC; } else if (tmpchr == 'G') { pkt_type = GGA; } else { rx_read-=4; bytes_received-=4; wait_for_eol(); pkt_type = UNKNOWN; continue; } } *rx_read = tmpchr; rx_read++; sentence_start++; bytes_received++; // light_on(); if (bytes_received >= 512 && sentence_finished) { RCSTA1bits.CREN=0; //disable reception for now to avoid overrun errors rx_read_start = rx_read - bytes_received; // should always be the same as rx_buffer3 if (!file_created) { retval = find_date_time_from_sentence_buffer(&fat16_date, &fat16_time, rx_read_start, bytes_received); if (retval == 0) { create_file( fat16_date, fat16_time ); } else { create_file( 0x3ee7, /* july 7 2010 */ 0x2108 /*04:08:16am */ ); } file_created = 1; } //write data to the SD card write_buf_to_file((BYTE *)rx_read_start); /* if (retval != 0) goto bad; */ bytes_received-=512; if (bytes_received > 0) { // to make life easy, move the leftover parts of the buffer back to the top and continue copying data below it memcpy(rx_read_start, rx_read - bytes_received, bytes_received); } rx_read-=512; //renable reception RCSTA1bits.CREN=1; /* odds are we are going to have a fraction of a sentence if we start logging whatever comes in now, so wait for the sentence to end before going on */ wait_for_eol(); } } bad: SLOW_ERROR(); } // end main
void Application::load(SceneInfo* sceneInfo) { vector<Collada::Node>& nodes = sceneInfo->nodes; vector<DynamicScene::SceneLight *> lights; vector<DynamicScene::SceneObject *> objects; // save camera position to update camera control later CameraInfo *c; Vector3D c_pos = Vector3D(); Vector3D c_dir = Vector3D(); int len = nodes.size(); for (int i = 0; i < len; i++) { Collada::Node& node = nodes[i]; Collada::Instance *instance = node.instance; const Matrix4x4& transform = node.transform; switch(instance->type) { case Collada::Instance::CAMERA: c = static_cast<CameraInfo*>(instance); c_pos = (transform * Vector4D(c_pos,1)).to3D(); c_dir = (transform * Vector4D(c->view_dir,1)).to3D().unit(); init_camera(*c, transform); break; case Collada::Instance::LIGHT: { lights.push_back( init_light(static_cast<LightInfo&>(*instance), transform)); break; } case Collada::Instance::SPHERE: objects.push_back( init_sphere(static_cast<SphereInfo&>(*instance), transform)); break; case Collada::Instance::POLYMESH: objects.push_back( init_polymesh(static_cast<PolymeshInfo&>(*instance), transform)); break; case Collada::Instance::MATERIAL: init_material(static_cast<MaterialInfo&>(*instance)); break; } } scene = new DynamicScene::Scene(objects, lights); const BBox& bbox = scene->get_bbox(); if (!bbox.empty()) { Vector3D target = bbox.centroid(); canonical_view_distance = bbox.extent.norm() / 2 * 1.5; double view_distance = canonical_view_distance * 2; double min_view_distance = canonical_view_distance / 10.0; double max_view_distance = canonical_view_distance * 20.0; canonicalCamera.place(target, acos(c_dir.y), atan2(c_dir.x, c_dir.z), view_distance, min_view_distance, max_view_distance); camera.place(target, acos(c_dir.y), atan2(c_dir.x, c_dir.z), view_distance, min_view_distance, max_view_distance); set_scroll_rate(); } // set default draw styles for meshEdit - scene->set_draw_styles(&defaultStyle, &hoverStyle, &selectStyle); }
void display(void) { glViewport(0,0,(GLsizei)WINDOW_WIDTH,(GLsizei)WINDOW_HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40,(GLfloat)WINDOW_WIDTH/(GLfloat)WINDOW_HEIGHT, 1, 100); gluLookAt(0,15, 20, 0, 0, 0, 0, 1, 0); int i; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); init_light(); drawCage(); for (i = 0; i < 5; i++) { drawObject(stObj[i]); } drawArmBand(); glLoadIdentity(); glTranslatef(armData.x, (LARGE_CUBE_SIZE /2)+0.5, armData.z); renderArm(&band); glRotatef(45,0,1,0); renderArm(&hand); glPushMatrix(); renderArm(&claw1); renderArm(&claw5); glPopMatrix(); glPushMatrix(); renderArm(&claw2); renderArm(&claw6); glPopMatrix(); glPushMatrix(); renderArm(&claw3); renderArm(&claw7); glPopMatrix(); glPushMatrix(); renderArm(&claw4); renderArm(&claw8); glPopMatrix(); if (armData.visible == VISIBLE) { glTranslatef(0,-0.5,0); glRotatef(-45,0,1,0); renderArm(&hanggedObject); } glPushAttrib(GL_TRANSFORM_BIT // to backup & restore "current matrix mode" | GL_ENABLE_BIT); // to backup & restore "depth test" and "lighting" status glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glMatrixMode(GL_PROJECTION); glPushMatrix(); // not to mess up the projection matrix... glLoadIdentity(); glOrtho(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); // not to mess up the modelview matrix... glLoadIdentity(); { char buf[128]; int i; sprintf(buf, "claw position: (%f, %f, %f)", armData.x, armData.y ,armData.z); glColor3f(1,1,1); glRasterPos3f(10, 10, 0); for(i = 0 ; i < strlen(buf) ; i++) { glutBitmapCharacter(GLUT_BITMAP_9_BY_15, buf[i]); } } glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glPopAttrib(); glViewport(638,0,150,150); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40,150/150,1, 100); //glOrtho(, 2.0, -2, 2, 1, 10); gluLookAt(armData.x,armData.y,armData.z, armData.x,-6,armData.z, 0, 0, -1); glMatrixMode(GL_MODELVIEW); init_light(); drawCage(); for (i = 0; i < 5; i++) { drawObject(stObj[i]); } drawArmBand(); glLoadIdentity(); glTranslatef(armData.x, (LARGE_CUBE_SIZE /2)+0.5, armData.z); renderArm(&band); glRotatef(45,0,1,0); renderArm(&hand); glPushMatrix(); renderArm(&claw1); renderArm(&claw5); glPopMatrix(); glPushMatrix(); renderArm(&claw2); renderArm(&claw6); glPopMatrix(); glPushMatrix(); renderArm(&claw3); renderArm(&claw7); glPopMatrix(); glPushMatrix(); renderArm(&claw4); renderArm(&claw8); glPopMatrix(); if (armData.visible == VISIBLE) { glTranslatef(0,-0.5,0); glRotatef(-45,0,1,0); renderArm(&hanggedObject); } glutSwapBuffers(); }