void BSP(const Mat4f& camera, std::size_t p) { assert(p < std::size_t(plane.size())); // the normal vector of the plane Vec4f normal(make_plane[p].Normal(), 0.0); // check if we are seeing the front or the back face GLfloat sign = ((camera*normal).z() >= 0.0f)? 1.0f: -1.0f; bool at_leaf = p+1 == plane.size(); gl.Enable(Functionality::ClipDistance, p); torus_clip_signs[p].Set(-sign); plane_clip_signs[p].Set(-sign); if(at_leaf) RenderTorus(); else BSP(camera, p+1); gl.Disable(Functionality::ClipDistance, p); RenderPlane(p); gl.Enable(Functionality::ClipDistance, p); torus_clip_signs[p].Set(+sign); plane_clip_signs[p].Set(+sign); if(at_leaf) RenderTorus(); else BSP(camera, p+1); gl.Disable(Functionality::ClipDistance, p); }
/******************************************************************************* * 函数名称: main * 输入参数: * 输出参数: * --返回值: * 函数功能: -- *******************************************************************************/ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ BSP(); loop(); return 0u; }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); auto camera = CamMatrixf::Orbiting( Vec3f(), 6.0, FullCircles(time / 10.0), Degrees(45.0 + SineWave(time / 7.0)*30.0) ); auto model = ModelMatrixf::RotationX(FullCircles(time / 12.0)); plane_camera_matrix.Set(camera); torus_camera_matrix.Set(camera); torus_model_matrix.Set(model); BSP(camera, 0); }