void get_camera_vector(int j, int i, float v[3], int x, int y) { struct camera *c = get_camera(i); float X[3]; float Y[3]; float Z[3]; float V[3]; /* Get the point vector in camera coordinates. */ if (c->type == CAMERA_PERSP) get_display_point(V, c->pos_offset, x, y); else { V[0] = (float) x; V[1] = (float) y; V[2] = -1.0; } /* Transform this vector to world coordinates. */ get_entity_x_vector(j, X); get_entity_y_vector(j, Y); get_entity_z_vector(j, Z); v[0] = V[0] * X[0] + V[1] * Y[0] + V[2] * Z[0]; v[1] = V[0] * X[1] + V[1] * Y[1] + V[2] * Z[1]; v[2] = V[0] * X[2] + V[1] * Y[2] + V[2] * Z[2]; }
void recv_set_camera_range(void) { struct camera *c = get_camera(recv_index()); c->n = recv_float(); c->f = recv_float(); }
/* * path trace across whole screen image. */ void ri_transport_pathtrace(const ri_display_drv_t *ddrv) { int i; int x, y; int nsamples; /* nsamples per pixel */ int ntotalpixels; int nfinishedpixels; double dcol[3]; /* tempolary color buffer */ float fcol[3]; ri_option_t *opt; /* rendering options */ ri_vector_t radiance; /* Initialize */ opt = ri_render_get()->context->option; pixwidth = opt->camera->horizontal_resolution; pixheight = opt->camera->vertical_resolution; nsamples = opt->pt_nsamples; ntotalpixels = pixwidth * pixheight * nsamples; nfinishedpixels = 0; light = (ri_light_t *)(ri_list_first(ri_render_get()->lightlist)->data); get_camera(&cam_pos, &cam_dir, &c2w); /* for each pixel, trace nsamples rays. */ for (x = 0; x < pixwidth; x++) { for (y = pixheight - 1; y >= 0; y--) { dcol[0] = 0.0; dcol[1] = 0.0; dcol[2] = 0.0; for (i = 0; i < nsamples; i++) { trace_pixel(&radiance, x, y); // add_color(x, y, radiance); dcol[0] += (double)radiance.f[0]; dcol[1] += (double)radiance.f[1]; dcol[2] += (double)radiance.f[2]; } nfinishedpixels += nsamples; #if 0 printf("%f %% finished\r", (float)(nfinishedpixels * 100.0 / ntotalpixels)); fflush(stdout); #endif fcol[0] = (float)(dcol[0] / (double)nsamples); fcol[1] = (float)(dcol[1] / (double)nsamples); fcol[2] = (float)(dcol[2] / (double)nsamples); ddrv->write(x, pixheight - 1 - y, &fcol[0]); } } }
void send_set_camera_range(int i, float n, float f) { struct camera *c = get_camera(i); send_event(EVENT_SET_CAMERA_RANGE); send_index(i); send_float((c->n = n)); send_float((c->f = f)); }
static int new_camera(void) { int i, n = vecnum(camera); for (i = 0; i < n; ++i) if (get_camera(i)->count == 0) return i; return vecadd(camera); }
t_objs *get_data(char *str, t_objs *obj, t_env *e) { if (!(get_camera(str, obj))) ft_error("Camera description not found. Please add one", 2); if (!(obj = get_obj(str, obj))) ft_error("No object description found. Please add one", 2); get_light(str, e); free(str); return (obj); }
void recv_set_camera_image(void) { struct camera *c = get_camera(recv_index()); c->image = recv_index(); c->l = recv_float(); c->r = recv_float(); c->b = recv_float(); c->t = recv_float(); }
static void init_camera(int i) { struct camera *c = get_camera(i); if (c->state == 0 && c->image) { /* The camera needs an offscreen render target. Initialize it. */ GLenum T = get_image_target(c->image); GLuint O = get_image_buffer(c->image); int w = get_image_w(c->image); int h = get_image_h(c->image); if (GL_has_framebuffer_object) { init_image(c->image); glGenFramebuffersEXT(1, &c->frame); glGenTextures (1, &c->depth); /* Initialize the depth render target. */ glBindTexture(T, c->depth); glTexImage2D(T, 0, GL_DEPTH_COMPONENT24, w, h, 0, GL_DEPTH_COMPONENT, GL_INT, NULL); glTexParameteri(T, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(T, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(T, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(T, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(T, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY); glTexParameteri(T, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB); /* Attach the framebuffer render targets. */ opengl_push_framebuffer(c->frame); { glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, T, O, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, T, c->depth, 0); } opengl_pop_framebuffer(); } } c->state = 1; }
void recv_set_camera_stereo(void) { struct camera *c = get_camera(recv_index()); c->mode = recv_index(); c->eye_offset[0][0] = recv_float(); c->eye_offset[0][1] = recv_float(); c->eye_offset[0][2] = recv_float(); c->eye_offset[1][0] = recv_float(); c->eye_offset[1][1] = recv_float(); c->eye_offset[1][2] = recv_float(); }
static void free_camera(int i) { struct camera *c = get_camera(i); if (c->count > 0) { c->count--; if (c->count == 0) memset(c, 0, sizeof (struct camera)); } }
void send_set_camera_image(int i, int j, float l, float r, float b, float t) { struct camera *c = get_camera(i); send_event(EVENT_SET_CAMERA_IMAGE); send_index(i); send_index((c->image = j)); send_float((c->l = l)); send_float((c->r = r)); send_float((c->b = b)); send_float((c->t = t)); }
int main() { doSysInit(); menu_init(15); create_camera(); create_hud(); initPostprocessing(get_camera()); invoke_game_state(TARGET_GAME_STATE, 0); }
void send_set_camera_stereo(int i, const float L[3], const float R[3], int mode) { struct camera *c = get_camera(i); send_event(EVENT_SET_CAMERA_STEREO); send_index(i); send_index((c->mode = mode)); send_float((c->eye_offset[0][0] = L[0])); send_float((c->eye_offset[0][1] = L[1])); send_float((c->eye_offset[0][2] = L[2])); send_float((c->eye_offset[1][0] = R[0])); send_float((c->eye_offset[1][1] = R[1])); send_float((c->eye_offset[1][2] = R[2])); }
static void fini_camera(int i) { struct camera *c = get_camera(i); if (c->state == 1) { if (c->frame && GL_has_framebuffer_object) glDeleteFramebuffersEXT(1, &c->frame); if (c->depth) glDeleteTextures(1, &c->depth); c->frame = 0; c->depth = 0; c->state = 0; } }
void recv_create_camera(void) { int i = new_camera(); int t = recv_index(); struct camera *c = get_camera(i); c->count = 1; c->type = t; c->n = recv_float(); c->f = recv_float(); c->frame = 0; c->depth = 0; c->image = 0; recv_create_entity(); }
static GnomeVFSResult do_create ( GnomeVFSMethod *method, GnomeVFSMethodHandle **handle, GnomeVFSURI *uri, GnomeVFSOpenMode mode, gboolean exclusive, guint perm, GnomeVFSContext *context) { Camera *camera; CameraAbilities a; FileHandle *file_handle; GnomeVFSResult result; G_LOCK (cameras); result = get_camera (uri, &camera); if (result != GNOME_VFS_OK) { G_UNLOCK (cameras); return (result); } gp_camera_get_abilities (camera, &a); if (!(a.folder_operations & GP_FOLDER_OPERATION_PUT_FILE)) { unref_camera (camera); G_UNLOCK (cameras); return (GNOME_VFS_ERROR_NOT_SUPPORTED); } /* Construct the file handle */ file_handle = g_new0 (FileHandle, 1); file_handle->camera = camera; gp_file_new (&(file_handle->file)); file_handle->create = TRUE; file_handle->dirname = gnome_vfs_uri_extract_dirname (uri); file_handle->preview = (camera_uri_get_user_name (uri) != NULL); *handle = (GnomeVFSMethodHandle *) file_handle; G_UNLOCK (cameras); return (GNOME_VFS_OK); }
void recv_set_camera_offset(void) { struct camera *c = get_camera(recv_index()); c->pos_offset[0] = recv_float(); c->pos_offset[1] = recv_float(); c->pos_offset[2] = recv_float(); c->view_basis[0][0] = recv_float(); c->view_basis[0][1] = recv_float(); c->view_basis[0][2] = recv_float(); c->view_basis[1][0] = recv_float(); c->view_basis[1][1] = recv_float(); c->view_basis[1][2] = recv_float(); c->view_basis[2][0] = recv_float(); c->view_basis[2][1] = recv_float(); c->view_basis[2][2] = recv_float(); }
void mininode_culling::traverse_init() { // state initialization mininode_group::traverse_init(); mininode_cam *camera=get_camera(); miniv3d eye=camera->get_eye().vec; miniv3d dir=camera->get_dir(); double cone=camera->get_cone(); orb_radius=camera->get_orb_radius(); camera->get_orb_axis(orb_r_major,orb_r_minor); view_point=eye; cone_stack.push(minicone(eye,dir,cone)); mininode_geometry::reset_render_count(); }
fn Camera* new_camera() { u32 num_cameras = scene::ctx->num_cameras; auto c = get_camera(num_cameras); c->id = num_cameras; c->entity = scene::new_entity(); c->projection_type = camera::Projection::PERSPECTIVE; c->projection = mat4::identity; c->view = mat4::identity; c->view_projection = mat4::identity; c->normal = mat3::identity; c->mask = 0; c->dirty = true; c->aspect = 1.0f; c->near = 0.01f; c->far = 100.0f; c->fov = 60.0f; return c; }
void send_set_camera_offset(int i, const float p[3], const float M[16]) { struct camera *c = get_camera(i); send_event(EVENT_SET_CAMERA_OFFSET); send_index(i); send_float((c->pos_offset[0] = p[0])); send_float((c->pos_offset[1] = p[1])); send_float((c->pos_offset[2] = p[2])); send_float((c->view_basis[0][0] = M[0])); send_float((c->view_basis[0][1] = M[1])); send_float((c->view_basis[0][2] = M[2])); send_float((c->view_basis[1][0] = M[4])); send_float((c->view_basis[1][1] = M[5])); send_float((c->view_basis[1][2] = M[6])); send_float((c->view_basis[2][0] = M[8])); send_float((c->view_basis[2][1] = M[9])); send_float((c->view_basis[2][2] = M[10])); }
void *parse_scene(const parsing_sect_t *section, t_scene *scene) { t_camera *camera; if (scene->name != NULL) free(scene->name); scene->name = ft_strdup(section->name); if (section->option_count > 0) { if (section->options[0][0] == NULL) die("Bad input file."); camera = get_camera(scene, section->options[0][1]); if (camera == NULL) die("This camera is not defined."); scene->active_camera = camera; } return (NULL); }
void draw_grid(mat4 transform) { glUseProgram(grid_program.handle); glEnableVertexAttribArray(grid_vertex_attrib); glBindBuffer(GL_ARRAY_BUFFER, grid_buffer); glVertexAttribPointer(grid_vertex_attrib, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); checkGLError(); glEnableVertexAttribArray(grid_position_attrib); glBindBuffer(GL_ARRAY_BUFFER, grid_position_buffer); glVertexAttribPointer(grid_position_attrib, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); glEnableVertexAttribArray(grid_horizontal_attrib); glBindBuffer(GL_ARRAY_BUFFER, grid_horiz_buffer); glVertexAttribIPointer(grid_horizontal_attrib, 1, GL_UNSIGNED_INT, 0, (void*)0); bind_texture_to_program(grid_program, "texture", grid_dash_texture, GL_TEXTURE0); mat4 tt = ident; mat4_translate(&tt, 0, 0, -10); mat4 camera = get_camera(); glUniformMatrix4fv(grid_transform_uniform, 1, GL_FALSE, camera.data); glVertexAttribDivisor(grid_vertex_attrib, 0); glVertexAttribDivisor(grid_position_attrib, 1); glVertexAttribDivisor(grid_horizontal_attrib, 1); checkGLError(); glDrawArraysInstanced(GL_LINES, 0, 2, TILEMAP_DIMS * 2); glDisableVertexAttribArray(grid_vertex_attrib); glVertexAttribDivisor(grid_position_attrib, 0); glVertexAttribDivisor(grid_horizontal_attrib, 0); }
static void display(void) { matrix m; vector eye, at, up; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Render scene */ glMatrixMode(GL_PROJECTION); mat_persp(m, fovy, (double) width / height, znear, zfar); glLoadMatrixf(m); glMatrixMode(GL_MODELVIEW); get_camera(eye, at, up); mat_lookat(m, eye, at, up); glLoadMatrixf(m); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_DIFFUSE, (GLfloat[4]) { 1.0f, 1.0f, 1.0f, 1.0f }); glLightfv(GL_LIGHT0, GL_POSITION, (GLfloat[4]) { eye[0], eye[1], eye[2], 1.0f }); glEnable(GL_LIGHT0); ed_render(ed); gl_draw_xyz(); /* Render overlays */ gl_begin_2d(); gl_draw_fps(0.925f, 0.975f); ed_render_overlay(ed); gl_end_2d(); /* Swap buffers */ glutSwapBuffers(); glutPostRedisplay(); }
int send_create_camera(int t) { int i; if ((i = new_camera()) >= 0) { struct camera *c = get_camera(i); c->count = 1; c->type = t; c->n = (t == CAMERA_ORTHO) ? -1000.0f : 0.1f; c->f = (t == CAMERA_ORTHO) ? 1000.0f : 1000.0f; c->frame = 0; c->depth = 0; c->image = 0; c->view_basis[0][0] = 1.0f; c->view_basis[0][1] = 0.0f; c->view_basis[0][2] = 0.0f; c->view_basis[1][0] = 0.0f; c->view_basis[1][1] = 1.0f; c->view_basis[1][2] = 0.0f; c->view_basis[2][0] = 0.0f; c->view_basis[2][1] = 0.0f; c->view_basis[2][2] = 1.0f; send_event(EVENT_CREATE_CAMERA); send_index(t); send_float(c->n); send_float(c->f); return send_create_entity(TYPE_CAMERA, i); } return -1; }
void read_scene(FILE* fp, int version) { if (version > -1 || version < -2) error("Scene file version %d is not supported", version); fread(&number_of_cameras, sizeof(int), 1, fp); if (number_of_cameras) { cameras = new OBJECT_3D_SCENE_CAMERA_INFO[number_of_cameras]; for (int camera_count = 0; camera_count < number_of_cameras; camera_count++) { cameras[camera_count].camera_name_index = get_camera(fp); cameras[camera_count].camera_index = read_new_camera(fp); } } else cameras = NULL; fread(&number_of_scene_link_objects, sizeof(int), 1, fp); if (number_of_scene_link_objects) { scene_link_objects = new OBJECT_3D_SCENE_LINK_OBJECT [number_of_scene_link_objects]; for (int tmp = 0; tmp < number_of_scene_link_objects; tmp++) { scene_link_objects[tmp].scene_index = get_scene(fp); fread(&scene_link_objects[tmp].x, sizeof(float), 1, fp); fread(&scene_link_objects[tmp].y, sizeof(float), 1, fp); fread(&scene_link_objects[tmp].z, sizeof(float), 1, fp); fread(&scene_link_objects[tmp].heading, sizeof(float), 1, fp); fread(&scene_link_objects[tmp].pitch, sizeof(float), 1, fp); fread(&scene_link_objects[tmp].roll, sizeof(float), 1, fp); } } else scene_link_objects = NULL; fread(&number_of_sprite_lights, sizeof(int), 1, fp); number_of_sprite_lights = number_of_sprite_lights; sprite_lights = NULL; if (number_of_sprite_lights) { sprite_lights = new OBJECT_3D_SPRITE_LIGHT[number_of_sprite_lights]; for (int tmp = 0; tmp < number_of_sprite_lights; tmp++) { int red, green, blue; fread(&sprite_lights[tmp].position.x, sizeof(float), 1, fp); fread(&sprite_lights[tmp].position.y, sizeof(float), 1, fp); fread(&sprite_lights[tmp].position.z, sizeof(float), 1, fp); fread(&sprite_lights[tmp].scale.x, sizeof(float), 1, fp); fread(&sprite_lights[tmp].scale.y, sizeof(float), 1, fp); fread(&sprite_lights[tmp].scale.z, sizeof(float), 1, fp); fread(&red, sizeof(int), 1, fp); fread(&green, sizeof(int), 1, fp); fread(&blue, sizeof(int), 1, fp); sprite_lights[tmp].colour.red = red; sprite_lights[tmp].colour.green = green; sprite_lights[tmp].colour.blue = blue; } } if (version <= -2) fread(&number_of_ambient_lights, sizeof(int), 1, fp); else number_of_ambient_lights = 0; ambient_lights = NULL; if (number_of_ambient_lights) { ambient_lights = new OBJECT_3D_AMBIENT_LIGHT[number_of_ambient_lights]; for (int tmp = 0; tmp < number_of_ambient_lights; tmp++) { fread(&ambient_lights[tmp].colour.red, sizeof(float), 1, fp); fread(&ambient_lights[tmp].colour.green, sizeof(float), 1, fp); fread(&ambient_lights[tmp].colour.blue, sizeof(float), 1, fp); ambient_lights[tmp].light_index = get_light(fp); } } if (version <= -2) fread(&number_of_distant_lights, sizeof(int), 1, fp); else number_of_distant_lights = 0; distant_lights = NULL; if (number_of_distant_lights) { distant_lights = new OBJECT_3D_DISTANT_LIGHT[number_of_distant_lights]; for (int tmp = 0; tmp < number_of_distant_lights; tmp++) { fread(&distant_lights[tmp].heading, sizeof(float), 1, fp); fread(&distant_lights[tmp].pitch, sizeof(float), 1, fp); fread(&distant_lights[tmp].roll, sizeof(float), 1, fp); fread(&distant_lights[tmp].colour.red, sizeof(float), 1, fp); fread(&distant_lights[tmp].colour.green, sizeof(float), 1, fp); fread(&distant_lights[tmp].colour.blue, sizeof(float), 1, fp); distant_lights[tmp].light_index = get_light(fp); } } fread(&total_number_of_sub_objects, sizeof(int), 1, fp); fread(&total_number_of_sub_object_indices, sizeof(int), 1, fp); if (total_number_of_sub_object_indices) current_scene_sub_object_index_array = new OBJECT_3D_SUB_OBJECT_INDEX[total_number_of_sub_object_indices]; else current_scene_sub_object_index_array = NULL; if (total_number_of_sub_objects) current_scene_sub_object_array = new OBJECT_3D_DATABASE_ENTRY[total_number_of_sub_objects]; else current_scene_sub_object_array = NULL; scene_sub_object_indices_array = current_scene_sub_object_index_array; scene_sub_object_array = current_scene_sub_object_array; fread(&number_of_texture_animations, sizeof(int), 1, fp); if (number_of_texture_animations) { texture_animations = new int[number_of_texture_animations]; for (int tmp = 0; tmp < number_of_texture_animations; tmp++) fread(&texture_animations[tmp], sizeof(int), 1, fp); } else texture_animations = NULL; fread(&number_of_approximations, sizeof(int), 1, fp); index = get_object(fp); if (number_of_approximations) { approximations = new OBJECT_3D_APPROXIMATION_INFO[number_of_approximations]; for (int approximation = 0; approximation < number_of_approximations; approximation++) { approximations[approximation].object_number = get_object(fp); fread(&approximations[approximation].distance, sizeof(float), 1, fp); } } fread(&shadow_approximation_index, sizeof(int), 1, fp); shadow_polygon_object_index = get_object(fp); fread(&shadow_polygon_object_scale.x, sizeof(float), 1, fp); fread(&shadow_polygon_object_scale.y, sizeof(float), 1, fp); fread(&shadow_polygon_object_scale.z, sizeof(float), 1, fp); collision_object_index = get_object(fp); if (!collision_object_index) collision_object_index = -1; read_keyframes(fp, &number_of_keyframes, &keyframes); fseek(fp, sizeof(float), SEEK_CUR); read_value_keyframes(fp, &number_of_object_dissolve_keyframes, &object_dissolve_keyframes); read_value_keyframes(fp, &number_of_displacement_amplitude_keyframes, &displacement_amplitude_keyframes); read_indices(fp, &number_of_sub_object_indices, &sub_object_indices); read_subobjects(fp, &number_of_sub_objects, &sub_objects, NULL); QuickSearch quick(*this); }
TITANIUM_PROPERTY_GETTER(View, camera) { return get_camera()->get_object(); }
int camera_onscreen(int i) { return (get_camera(i)->image == 0); }
static void dupe_camera(int i) { get_camera(i)->count++; }
/** * \brief Makes the camera traverse a separator. * \param separator The separator to traverse. */ void Map::traverse_separator(Separator* separator) { Camera& camera = get_camera(); camera.traverse_separator(separator); }
static void draw_camera(int i, int j, int f, float a) { struct camera *c = get_camera(i); init_camera(i); if (c->frame) { /* Apply a basic projection for offscreen rendering. */ glMatrixMode(GL_PROJECTION); { glPushMatrix(); glLoadIdentity(); if (c->type == CAMERA_ORTHO) glOrtho (c->l, c->r, c->b, c->t, c->n, c->f); else glFrustum(c->l, c->r, c->b, c->t, c->n, c->f); } glMatrixMode(GL_MODELVIEW); { glPushMatrix(); glLoadIdentity(); } /* Render the scene to the offscreen buffer. */ glPushAttrib(GL_VIEWPORT_BIT | GL_SCISSOR_BIT); { int w = get_image_w(c->image); int h = get_image_h(c->image); glViewport(0, 0, w, h); glScissor (0, 0, w, h); opengl_push_framebuffer(c->frame); { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); draw_scene(j, f, a); } opengl_pop_framebuffer(); } glPopAttrib(); /* Revert the projection. */ glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } else { int eye; int tile; int pass; /* Iterate over all tiles of this host. */ for (tile = 0; tile < (int) get_tile_count(); ++tile) { float d[2][3]; /* Iterate over the eyes. */ get_eye_pos(d[0], c, 0, tile); get_eye_pos(d[1], c, 1, tile); for (eye = 0; eye < (c->mode ? 2 : 1); ++eye) { camera_eye = eye; if (draw_tile(c, eye, tile, d[eye])) { pass = 0; /* Iterate over all passes of this eye and tile. */ while ((pass = draw_pass(c->mode, eye, tile, pass, d))) { if (get_tile_flags(tile) & TILE_TEST_COLOR) draw_color(j, eye); else if (get_tile_flags(tile) & TILE_TEST_GHOST) draw_ghost(j, eye); else draw_scene(j, f, a); } } } } /* HACK */ if (c->mode != STEREO_VARRIER_00) opengl_set_fence(); } }