public void Draw(DrawMethodArgs args) { PhysicsScene scene = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex); PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex); if (!objectBase.EnableDrawing) { return; } PhysicsObject physicsObjectWithActiveCamera = scene.GetPhysicsObjectWithActiveCamera(0); if (physicsObjectWithActiveCamera == null) { return; } PhysicsCamera activeCamera = physicsObjectWithActiveCamera.Camera; if (activeCamera == null) { return; } float time = args.Time; activeCamera.GetTransposeRotation(ref world); Vector3.TransformVector(ref demo.CursorLightDirection, ref world, out localLightDirection); activeCamera.View.GetViewMatrix(ref view); activeCamera.Projection.GetProjectionMatrix(ref projection); objectBase.MainWorldTransform.GetTransformMatrix(ref world); if (objectBase.UserDataStr != null) { GL.Disable(EnableCap.DepthTest); GL.DepthMask(false); DemoMesh mesh = demo.Meshes[objectBase.UserDataStr]; PhysicsLight sceneLight = scene.Light; sceneLight.GetDirection(ref lightDirection); sceneLight.SetDirection(ref localLightDirection); mesh.Draw(ref world, ref view, ref projection, sceneLight, objectBase.Material, activeCamera, false, demo.EnableWireframe); sceneLight.SetDirection(ref lightDirection); GL.DepthMask(true); GL.Enable(EnableCap.DepthTest); } }
void Draw(DrawMethodArgs args) { PhysicsScene scene = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex); PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex); PhysicsObject physicsObjectWithActiveCamera = scene.GetPhysicsObjectWithActiveCamera(0); if (physicsObjectWithActiveCamera == null) { return; } PhysicsCamera activeCamera = physicsObjectWithActiveCamera.Camera; if (activeCamera == null) { return; } DemoMesh mesh = demo.Meshes[objectBase.UserDataStr]; if ((mesh == null) || (mesh.Vertices == null)) { return; } if (mesh.Dynamic && objectBase.Shape.ShapePrimitive.DynamicUpdate) { objectBase.Shape.GetMeshVertices(1.0f, 1.0f, false, true, mesh.Vertices); mesh.SetVertices(mesh.Vertices); } float time = args.Time; objectBase.MainWorldTransform.GetTransformMatrix(ref world); activeCamera.View.GetViewMatrix(ref view); activeCamera.Projection.GetProjectionMatrix(ref projection); PhysicsLight sceneLight = scene.Light; if (objectBase.Shape.ShapePrimitive.DynamicUpdateState) { mesh.Draw(ref world, ref view, ref projection, sceneLight, objectBase.Material, activeCamera, false, demo.EnableWireframe); } else { mesh = demo.Meshes[lakeInstanceName]; mesh.Draw(ref world, ref view, ref projection, sceneLight, objectBase.Material, activeCamera, false, demo.EnableWireframe); } }
public void Draw(ref Matrix4 world, ref Matrix4 view, ref Matrix4 projection, PhysicsLight light, PhysicsMaterial material, PhysicsCamera camera, bool sleep, bool wireframe) { Render.SetWorld(ref world); Render.SetView(ref view); Render.SetProjection(ref projection); Render.EnableScaleNormals = scaleNormals; light.GetDirection(ref lightDirection); light.GetDiffuse(ref lightDiffuse); light.GetSpecular(ref lightSpecular); if (meshCullMode == CullFaceMode.FrontAndBack) { GL.Disable(EnableCap.CullFace); } GL.CullFace(meshCullMode); DemoTexture currentTexture = meshTexture; if (material.UserDataStr != null) { currentTexture = demo.Textures[material.UserDataStr]; } material.GetAmbient(ref ambient); material.GetDiffuse(ref diffuse); material.GetEmission(ref emission); material.GetSpecular(ref specular); if (sleep) { diffuse.X = 0.7f; diffuse.Y = 1.0f; diffuse.Z = 1.0f; } Render.SetAmbient(ref ambient); Render.SetSpecular(ref specular); Render.SetEmission(ref emission); Render.SpecularPower = material.SpecularPower; Render.Alpha = material.TransparencyFactor; Render.EnableTwoSidedNormals = material.TwoSidedNormals; if (!wireframe) { Render.SetDiffuse(ref diffuse); if (currentTexture != null) { Render.EnableTexture = true; Render.Texture = currentTexture.Handle; } else { Render.EnableTexture = false; } } else { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); diffuse.X *= 4.0f; diffuse.Y *= 4.0f; diffuse.Z *= 4.0f; Render.SetDiffuse(ref diffuse); Render.EnableTexture = false; } Render.Apply(); if (demo.EnableVertexBuffer) { if (meshVertexBuffer != -1) { if (meshIndexBuffer != -1) { GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.NormalArray); GL.EnableClientState(ArrayCap.TextureCoordArray); GL.BindBuffer(BufferTarget.ArrayBuffer, meshVertexBuffer); GL.BindBuffer(BufferTarget.ElementArrayBuffer, meshIndexBuffer); GL.VertexPointer(3, VertexPointerType.Float, VertexPositionNormalTexture.SizeInBytes, IntPtr.Zero); GL.NormalPointer(NormalPointerType.Float, VertexPositionNormalTexture.SizeInBytes, (IntPtr)Vector3.SizeInBytes); GL.TexCoordPointer(2, TexCoordPointerType.Float, VertexPositionNormalTexture.SizeInBytes, (IntPtr)(Vector3.SizeInBytes + Vector3.SizeInBytes)); GL.DrawElements(PrimitiveType.Triangles, indexCount, meshIndicesType, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero); GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero); GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero); GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.NormalArray); GL.DisableClientState(ArrayCap.TextureCoordArray); } else { GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.NormalArray); GL.EnableClientState(ArrayCap.TextureCoordArray); GL.BindBuffer(BufferTarget.ArrayBuffer, meshVertexBuffer); GL.VertexPointer(3, VertexPointerType.Float, VertexPositionNormalTexture.SizeInBytes, IntPtr.Zero); GL.NormalPointer(NormalPointerType.Float, VertexPositionNormalTexture.SizeInBytes, (IntPtr)Vector3.SizeInBytes); GL.TexCoordPointer(2, TexCoordPointerType.Float, VertexPositionNormalTexture.SizeInBytes, (IntPtr)(Vector3.SizeInBytes + Vector3.SizeInBytes)); GL.DrawArrays(PrimitiveType.Triangles, 0, vertexCount); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero); GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero); GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero); GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.NormalArray); GL.DisableClientState(ArrayCap.TextureCoordArray); } } } else { VertexPositionNormalTexture v1, v2, v3; if (meshIndices16Bit != null) { GL.Begin(PrimitiveType.Triangles); for (int i = 0; i < indexCount; i += 3) { v1 = meshVertices[meshIndices16Bit[i]]; v2 = meshVertices[meshIndices16Bit[i + 1]]; v3 = meshVertices[meshIndices16Bit[i + 2]]; GL.TexCoord2(v1.TextureCoordinate); GL.Normal3(v1.Normal); GL.Vertex3(v1.Position); GL.TexCoord2(v2.TextureCoordinate); GL.Normal3(v2.Normal); GL.Vertex3(v2.Position); GL.TexCoord2(v3.TextureCoordinate); GL.Normal3(v3.Normal); GL.Vertex3(v3.Position); } GL.End(); } else if (meshIndices32Bit != null) { GL.Begin(PrimitiveType.Triangles); for (int i = 0; i < indexCount; i += 3) { v1 = meshVertices[meshIndices32Bit[i]]; v2 = meshVertices[meshIndices32Bit[i + 1]]; v3 = meshVertices[meshIndices32Bit[i + 2]]; GL.TexCoord2(v1.TextureCoordinate); GL.Normal3(v1.Normal); GL.Vertex3(v1.Position); GL.TexCoord2(v2.TextureCoordinate); GL.Normal3(v2.Normal); GL.Vertex3(v2.Position); GL.TexCoord2(v3.TextureCoordinate); GL.Normal3(v3.Normal); GL.Vertex3(v3.Position); } GL.End(); } else { GL.Begin(PrimitiveType.Triangles); for (int i = 0; i < vertexCount; i += 3) { v1 = meshVertices[i]; v2 = meshVertices[i + 1]; v3 = meshVertices[i + 2]; GL.TexCoord2(v1.TextureCoordinate); GL.Normal3(v1.Normal); GL.Vertex3(v1.Position); GL.TexCoord2(v2.TextureCoordinate); GL.Normal3(v2.Normal); GL.Vertex3(v2.Position); GL.TexCoord2(v3.TextureCoordinate); GL.Normal3(v3.Normal); GL.Vertex3(v3.Position); } GL.End(); } } if (meshCullMode == CullFaceMode.FrontAndBack) { GL.Enable(EnableCap.CullFace); } if (wireframe) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } }