/// カプセル描画 public void DrawCapsule( GraphicsContext graphics, GeometryCapsule trgCap, Camera cam, Rgba color ) { if( debShader == null || trgCap.R <= 0.00001f ){ return ; } /// 球体部分 ///--------------------------------------------- DrawSphere( graphics, new GeometrySphere( trgCap.StartPos, trgCap.R ), cam, color ); DrawSphere( graphics, new GeometrySphere( trgCap.EndPos, trgCap.R ), cam, color ); /// パイプ部分 ///--------------------------------------------- setCapsulePipeVertex( trgCap ); debVb2.SetVertices( 0, debMesh2.Positions ); debVb2.SetIndices( debMesh2.Indices ); Matrix4 localMtx; if( trgCap.StartPos.X == trgCap.EndPos.X && trgCap.StartPos.Z == trgCap.EndPos.Z ){ localMtx = Matrix4.LookAt( trgCap.EndPos, trgCap.StartPos, new Vector3(0.0f, 0.0f, 1.0f)); } else{ localMtx = Matrix4.LookAt( trgCap.EndPos, trgCap.StartPos, new Vector3(0.0f, 1.0f, 0.0f)); } Matrix4 world = localMtx.Inverse() * Matrix4.Scale( new Vector3( trgCap.R, trgCap.R, trgCap.R ) ); world.M41 = trgCap.StartPos.X; world.M42 = trgCap.StartPos.Y; world.M43 = trgCap.StartPos.Z; Matrix4 worldViewProj = cam.Projection * cam.View * world; // uniform value debShader.SetUniformValue( debUIdWVP, ref worldViewProj ); Vector4 a_Color = new Vector4( (color.R / 255.0f), (color.G / 255.0f), (color.B / 255.0f), (color.A / 255.0f) ); debShader.SetUniformValue( debShader.FindUniform( "IAmbient" ), ref a_Color ); graphics.SetShaderProgram( debShader ); graphics.SetVertexBuffer( 0, debVb2 ); graphics.DrawArrays( debMesh2.Prim, 0, debMesh2.IndexCount ); }
/// 三角形描画 public void DrawTriangle( GraphicsContext graphics, GeometryTriangle trgTri, Camera cam, Rgba color ) { if( debShader == null ){ return ; } /// バーテクスの更新 ///------------------------------------------------------------ for( int i=0; i<3; i++ ){ debMesh.Positions[ i*3+0 ] = trgTri.GetPos(i).X; debMesh.Positions[ i*3+1 ] = trgTri.GetPos(i).Y; debMesh.Positions[ i*3+2 ] = trgTri.GetPos(i).Z; debMesh.Normals[ i*3+0 ] = trgTri.Plane.Nor.X; debMesh.Normals[ i*3+1 ] = trgTri.Plane.Nor.Y; debMesh.Normals[ i*3+2 ] = trgTri.Plane.Nor.Z; } debVb.SetVertices( 0, debMesh.Positions ); debVb.SetIndices( debMesh.Indices ); drawMesh( graphics, cam, color ); }
/// private メソッド ///--------------------------------------------------------------------------- /// 描画 private void drawMesh( GraphicsContext graphics, Camera cam, Rgba color ) { Matrix4 world = Matrix4.Translation( new Vector3( 0, 0, 0 ) ); Matrix4 worldViewProj = cam.Projection * cam.View * world; // uniform value debShader.SetUniformValue( debUIdWVP, ref worldViewProj ); Vector4 a_Color = new Vector4( (color.R / 255.0f), (color.G / 255.0f), (color.B / 255.0f), (color.A / 255.0f) ); debShader.SetUniformValue( debShader.FindUniform( "IAmbient" ), ref a_Color ); graphics.SetShaderProgram( debShader ); graphics.SetVertexBuffer( 0, debVb ); graphics.DrawArrays( debMesh.Prim, 0, debMesh.IndexCount ); }
/// 球描画 public void DrawSphere( GraphicsContext graphics, GeometrySphere trgSph, Camera cam, Rgba color ) { if( debShader == null ){ return ; } debVb.SetVertices( 0, debMesh.Positions ); debVb.SetIndices( debMesh.Indices ); Matrix4 world = Matrix4.Translation( new Vector3( trgSph.X, trgSph.Y, trgSph.Z ) ) * Matrix4.Scale( new Vector3( trgSph.R, trgSph.R, trgSph.R ) ); Matrix4 worldViewProj = cam.Projection * cam.View * world; // uniform value debShader.SetUniformValue( debUIdWVP, ref worldViewProj ); Vector4 a_Color = new Vector4( (color.R / 255.0f), (color.G / 255.0f), (color.B / 255.0f), (color.A / 255.0f) ); debShader.SetUniformValue( debShader.FindUniform( "IAmbient" ), ref a_Color ); graphics.SetShaderProgram( debShader ); graphics.SetVertexBuffer( 0, debVb ); graphics.DrawArrays( debMesh.Prim, 0, debMesh.IndexCount ); }
/// Line描画 public void DrawLine( GraphicsContext graphics, GeometryLine trgLine, Camera cam, Rgba color ) { if( debShader == null ){ return ; } /// バーテクスの更新 ///------------------------------------------------------------ for( int i=0; i<2; i++ ){ debMesh.Positions[ i*3+0 ] = trgLine.GetPos(i).X; debMesh.Positions[ i*3+1 ] = trgLine.GetPos(i).Y; debMesh.Positions[ i*3+2 ] = trgLine.GetPos(i).Z; debMesh.Normals[ i*3+0 ] = 0.0f; debMesh.Normals[ i*3+1 ] = 1.0f; debMesh.Normals[ i*3+2 ] = 0.0f; } debVb.SetVertices( 0, debMesh.Positions ); debVb.SetIndices( debMesh.Indices ); drawMesh( graphics, cam, color ); }
/// カレントのカメラの登録解除 public void ClearCurrentCamera() { currentCamera = null; }
/// 破棄 public void Term() { useGraphics = null; currentCamera = null; }
/// カレントのカメラを登録 public void SetCurrentCamera( Camera cam ) { /// 参照 currentCamera = cam; }