/* * Perform view frustum culling from a specific camera viewpoint */ void Renderer::cullFromCamera(Scene *scene, Camera* camera, ShaderManager* shader_manager) { std::vector<SceneObject*> scene_objects; glm::mat4 view_matrix = camera->getViewMatrix(); glm::mat4 projection_matrix = camera->getProjectionMatrix(); glm::mat4 vp_matrix = glm::mat4(projection_matrix * view_matrix); glm::vec3 campos(view_matrix[3]); scene_objects.reserve(1024); scene_objects.clear(); render_data_vector.clear(); // Travese all scene objects in the scene as a tree and do frustum culling at the same time if enabled // 1. Build the view frustum float frustum[6][4]; build_frustum(frustum, (const float*) glm::value_ptr(vp_matrix)); // 2. Iteratively execute frustum culling for each root object (as well as its children objects recursively) SceneObject *object = scene->getRoot(); if (DEBUG_RENDERER) { LOGD("FRUSTUM: start frustum culling for root %s\n", object->name().c_str()); } // frustum_cull(camera->owner_object()->transform()->position(), object, frustum, scene_objects, scene->get_frustum_culling(), 0); frustum_cull(campos, object, frustum, scene_objects, scene->get_frustum_culling(), 0); if (DEBUG_RENDERER) { LOGD("FRUSTUM: end frustum culling for root %s\n", object->name().c_str()); } // 3. do occlusion culling, if enabled occlusion_cull(scene, scene_objects, shader_manager, vp_matrix); }
void editFieldDlg::on_comboTabla_currentIndexChanged(const QString &arg1) { ui->comboCampo->clear(); ui->comboCampo->addItems(campos(arg1)); }
void SnowFlakeParticles::Draw(){ for(int loop =0; loop< MAXSNOWPOINTPARTICLES;loop++){ float matrix[16]; vec3f campos(camx,camy,camz); vec3f vectoreye = (campos - vec3f(pool[loop].x,pool[loop].y,pool[loop].z)); vec3f look = mxy::normalize(vectoreye); vec3f right = mxy::normalize(cross(look,tempup)); vec3f rightup = mxy::normalize(cross(right,look)); glPushMatrix(); /*glGetFloatv(GL_MODELVIEW_MATRIX , matrix);*/ // matrix[0] = matrix[10] = 1.0f; // // matrix[2] = matrix[4] = matrix[6] = matrix[8] = 0.0f; matrix[0] = right.x; matrix[1] =right.y; matrix[2] = right.z; matrix[3] = 0; matrix[4] = rightup.x; matrix[5] =rightup.y; matrix[6] = rightup.z; matrix[7] = 0; matrix[8] = look.x; matrix[9] =look.y; matrix[10] = look.z; matrix[11] = 0; /*glLoadMatrixf(matrix);*/ glEnable(GL_BLEND); // Enable Blending glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Type Of Blending To Perform glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); // Really Nice Perspective Calculations glHint(GL_POINT_SMOOTH_HINT,GL_NICEST); // Really Nice Point Smoothing glEnable(GL_TEXTURE_2D); // Enable Texture Mapping glBindTexture(GL_TEXTURE_2D,texture); glColor4f(pool[loop].r,pool[loop].g,pool[loop].b,pool[loop].a); glBegin(GL_TRIANGLE_STRIP); // Build Quad From A Triangle Strip glTexCoord2d(1,1); glVertex3f(pool[loop].x+snowflakesize,pool[loop].y+snowflakesize,pool[loop].z); // Top Right glTexCoord2d(0,1); glVertex3f(pool[loop].x-snowflakesize,pool[loop].y+snowflakesize,pool[loop].z); // Top Left glTexCoord2d(1,0); glVertex3f(pool[loop].x+snowflakesize,pool[loop].y-snowflakesize,pool[loop].z); // Bottom Right glTexCoord2d(0,0); glVertex3f(pool[loop].x-snowflakesize,pool[loop].y-snowflakesize,pool[loop].z); // Bottom Left glEnd(); glDisable(GL_BLEND); glPopMatrix(); /************************************************************************/ /* update data */ /************************************************************************/ pool[loop].x_old_speed = pool[loop].x_speed; pool[loop].y_old_speed = pool[loop].y_speed; pool[loop].z_old_speed = pool[loop].z_speed; pool[loop].x_speed = pool[loop].x_old_speed + pool[loop].xa * intervaltime; pool[loop].y_speed = pool[loop].y_old_speed + pool[loop].ya * intervaltime; pool[loop].z_speed = pool[loop].z_old_speed + pool[loop].za * intervaltime; pool[loop].x = pool[loop].x + 0.5* (pool[loop].x_speed + pool[loop].x_old_speed) *intervaltime; pool[loop].y = pool[loop].y + 0.5* (pool[loop].y_speed + pool[loop].y_old_speed) *intervaltime; pool[loop].z = pool[loop].z + 0.5* (pool[loop].z_speed + pool[loop].z_old_speed) *intervaltime; pool[loop].life -= pool[loop].fade * intervaltime; if (pool[loop].life<0.0f || pool[loop].y <0){ pool[loop].active=true; // Make All The Particles Active pool[loop].life=life; // Give All The Particles Full Life pool[loop].fade=FADEFUNC; // Random Fade Speed pool[loop].r = 0.9; // Select Red Rainbow Color pool[loop].g = 0.9; // Select Red Rainbow Color pool[loop].b = 0.9; // Select Red Rainbow Color pool[loop].a = 1.0; pool[loop].x_speed = 0; pool[loop].y_speed = 0; pool[loop].z_speed = 0; pool[loop].xa= 0; pool[loop].ya= gravity; pool[loop].za= 0; float anglex = RANGEOFANGLE * randf1(); float anflez = RANGEOFANGLE * randf1(); pool[loop].x = radius * sin(anglex); float temp = radius * cos(anglex); pool[loop].y = temp + hight; pool[loop].z = radius * sin(anflez); } } }
void EditCodeBarDlg::on_comboTable_currentIndexChanged(const QString &arg1) { ui->comboCampo->clear(); ui->comboCampo->addItems(campos(arg1)); }
void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize, f32 tool_reload_ratio) { // Get player position // Smooth the movement when walking up stairs v3f old_player_position = m_playernode->getPosition(); v3f player_position = player->getPosition(); //if(player->touching_ground && player_position.Y > old_player_position.Y) if(player->touching_ground && player_position.Y > old_player_position.Y) { f32 oldy = old_player_position.Y; f32 newy = player_position.Y; f32 t = exp(-23*frametime); player_position.Y = oldy * t + newy * (1-t); } // Set player node transformation m_playernode->setPosition(player_position); m_playernode->setRotation(v3f(0, -1 * player->getYaw(), 0)); m_playernode->updateAbsolutePosition(); // Get camera tilt timer (hurt animation) float cameratilt = fabs(fabs(-(player->hurt_tilt_timer_max/2)+player->hurt_tilt_timer)-player->hurt_tilt_timer_max/2)/5; v3f campos(player->getEyeOffset()); v3f camrot(player->getPitch(), 0, 0); //f32 incr = 0.3/m_sprinting_fov_states; /*if(m_sprinting_fov_state <= 0) { m_sprinting_fov_state = incr; } else if(m_sprinting_fov_state < 0.3) { m_sprinting_fov_state += incr; }*/ if(player->sprinting_timer != -10 && player->sprinting_timer != -20 && player->sprinting_timer != -30) { m_sprinting_fov_state = 0.3-player->sprinting_timer; } m_headnode->updateAbsolutePosition(); if(cameratilt > 0) { campos += v3f(0, cameratilt * -13, 0); camrot += v3f(0, 0, cameratilt * 13 * BS); } if(player->control.sneak) { campos += v3f(0, -player->camera_sneak_state*BS, 0); if (player->camera_sneak_state < 0.18) player->camera_sneak_state += 0.02; } else if (player->camera_sneak_state > 0) { player->camera_sneak_state -= 0.02; } campos += v3f(0, 0, m_sprinting_fov_state * BS); // Set head node transformation m_headnode->setPosition(campos); m_headnode->setRotation(camrot); m_headnode->updateAbsolutePosition(); // Compute relative camera position and target v3f rel_cam_pos = v3f(0,0,0); v3f rel_cam_target = v3f(0,0,1); v3f rel_cam_up = v3f(0,1,0); if (m_view_bobbing_anim != 0) { f32 bobfrac = my_modf(m_view_bobbing_anim * 2); f32 bobdir = (m_view_bobbing_anim < 0.5) ? 1.0 : -1.0; #if 1 f32 bobknob = 1.2; f32 bobtmp = sin(pow(bobfrac, bobknob) * PI); //f32 bobtmp2 = cos(pow(bobfrac, bobknob) * PI); v3f bobvec = v3f( 0.3 * bobdir * sin(bobfrac * PI), -0.28 * bobtmp * bobtmp, 0.); //rel_cam_pos += 0.2 * bobvec; //rel_cam_target += 0.03 * bobvec; //rel_cam_up.rotateXYBy(0.02 * bobdir * bobtmp * PI); float f = 1.0; f *= g_settings->getFloat("view_bobbing_amount"); rel_cam_pos += bobvec * f; //rel_cam_target += 0.995 * bobvec * f; rel_cam_target += bobvec * f; rel_cam_target.Z -= 0.005 * bobvec.Z * f; //rel_cam_target.X -= 0.005 * bobvec.X * f; //rel_cam_target.Y -= 0.005 * bobvec.Y * f; rel_cam_up.rotateXYBy(-0.03 * bobdir * bobtmp * PI * f); #else f32 angle_deg = 1 * bobdir * sin(bobfrac * PI); f32 angle_rad = angle_deg * PI / 180; f32 r = 0.05; v3f off = v3f( r * sin(angle_rad), r * (cos(angle_rad) - 1), 0); rel_cam_pos += off; //rel_cam_target += off; rel_cam_up.rotateXYBy(angle_deg); #endif } // Compute absolute camera position and target m_headnode->getAbsoluteTransformation().transformVect(m_camera_position, rel_cam_pos); m_headnode->getAbsoluteTransformation().rotateVect(m_camera_direction, rel_cam_target - rel_cam_pos); v3f abs_cam_up; m_headnode->getAbsoluteTransformation().rotateVect(abs_cam_up, rel_cam_up); // Set camera node transformation m_cameranode->setPosition(m_camera_position); m_cameranode->setUpVector(abs_cam_up); // *100.0 helps in large map coordinates m_cameranode->setTarget(m_camera_position + 100 * m_camera_direction); // Get FOV setting f32 fov_degrees = g_settings->getFloat("fov"); fov_degrees = MYMAX(fov_degrees, 10.0); fov_degrees = MYMIN(fov_degrees, 170.0); // FOV and aspect ratio m_aspect = (f32)screensize.X / (f32) screensize.Y; m_fov_y = fov_degrees * PI / 180.0; // Increase vertical FOV on lower aspect ratios (<16:10) m_fov_y *= MYMAX(1.0, MYMIN(1.4, sqrt(16./10. / m_aspect))); // WTF is this? It can't be right m_fov_x = 2 * atan(0.5 * m_aspect * tan(m_fov_y)); m_fov_x += m_sprinting_fov_state; m_fov_y += m_sprinting_fov_state; m_cameranode->setAspectRatio(m_aspect); m_cameranode->setFOV(m_fov_y); // Position the wielded item //v3f wield_position = v3f(45, -35, 65); v3f wield_position = v3f(55, -35, 65); //v3f wield_rotation = v3f(-100, 120, -100); v3f wield_rotation = v3f(-100, 120, -100); if(m_digging_anim < 0.05 || m_digging_anim > 0.5) { f32 frac = 1.0; if(m_digging_anim > 0.5) frac = 2.0 * (m_digging_anim - 0.5); // This value starts from 1 and settles to 0 f32 ratiothing = pow((1.0f - tool_reload_ratio), 0.5f); //f32 ratiothing2 = pow(ratiothing, 0.5f); f32 ratiothing2 = (easeCurve(ratiothing*0.5))*2.0; wield_position.Y -= frac * 25.0 * pow(ratiothing2, 1.7f); //wield_position.Z += frac * 5.0 * ratiothing2; wield_position.X -= frac * 35.0 * pow(ratiothing2, 1.1f); wield_rotation.Y += frac * 70.0 * pow(ratiothing2, 1.4f); //wield_rotation.X -= frac * 15.0 * pow(ratiothing2, 1.4f); //wield_rotation.Z += frac * 15.0 * pow(ratiothing2, 1.0f); } if(m_digging_button != -1) { if(m_digging_button == 0 && m_eatable) { m_is_eating = true; wield_position.X = 0; wield_position.Y = -20 + m_eating_anim; wield_position.Z = 65; wield_rotation.X = 0; wield_rotation.Y = 0; wield_rotation.Z = 0; } else { m_is_eating = false; f32 digfrac = m_digging_anim; wield_position.X -= 50 * sin(pow(digfrac, 0.7f) * PI); wield_position.Y += 24 * sin(digfrac * 1.8 * PI); wield_position.Z += 25 * 0.5; // Euler angles are PURE EVIL, so why not use quaternions? core::quaternion quat_begin(wield_rotation * core::DEGTORAD); core::quaternion quat_end(v3f(80, 30, 100) * core::DEGTORAD); core::quaternion quat_slerp; quat_slerp.slerp(quat_begin, quat_end, sin(digfrac * PI)); quat_slerp.toEuler(wield_rotation); wield_rotation *= core::RADTODEG; } } else { f32 bobfrac = my_modf(m_view_bobbing_anim); wield_position.X -= sin(bobfrac*PI*2.0) * 3.0; wield_position.Y += sin(my_modf(bobfrac*2.0)*PI) * 3.0; } m_wieldnode->setPosition(wield_position); m_wieldnode->setRotation(wield_rotation); m_wieldlight = player->light; // Render distance feedback loop updateViewingRange(frametime); // If the player seems to be walking on solid ground, // view bobbing is enabled and the player is not flying, // start (or continue) the view bobbing animation. v3f speed = player->getSpeed(); if ((hypot(speed.X, speed.Z) > BS) && (player->touching_ground) && (g_settings->getBool("view_bobbing") == true) && (!player->is_flying || !m_gamedef->checkLocalPrivilege("fly"))) { // Start animation m_view_bobbing_state = 1; //m_view_bobbing_speed = MYMIN(speed.getLength(), 40); m_view_bobbing_speed = speed.getLength()*0.7; } else if (m_view_bobbing_state == 1) { // Stop animation m_view_bobbing_state = 2; m_view_bobbing_speed = 60; } }