public void BuildClipPlanes() { if (editor.m_decal_active == -1) { return; } GL.PushMatrix(); GL.DeleteLists(GL_CLIP_PLANES, 1); GL.NewList(GL_CLIP_PLANES, ListMode.Compile); { GL.Begin(PrimitiveType.Lines); if (editor.m_level.selected_segment > -1 && editor.m_level.selected_side > -1) { Side s = editor.m_level.segment[editor.m_level.selected_segment].side[editor.m_level.selected_side]; Decal d = s.decal[editor.m_decal_active]; for (int i = 0; i < Decal.NUM_EDGES; i++) { if (d.clip_normal[i] != Vector3.Zero) { GL.Color3(C_decal_clip[i]); CreateLine(s.FindEdgeCenter(i), s.FindEdgeCenter(i) + d.clip_normal[i] * CLIP_DIST); CreateLine(s.FindEdgeCenterOffset(i, 0.1f), s.FindEdgeCenterOffset(i, 0.1f) + d.clip_normal[i] * CLIP_DIST); CreateLine(s.FindEdgeCenterOffset(i, 0.9f), s.FindEdgeCenterOffset(i, 0.9f) + d.clip_normal[i] * CLIP_DIST); CreateLine(s.FindEdgeCenterOffset(i, 0.1f) + d.clip_normal[i] * CLIP_DIST, s.FindEdgeCenterOffset(i, 0.9f) + d.clip_normal[i] * CLIP_DIST); } } } GL.End(); } GL.EndList(); GL.PopMatrix(); }
public void FindBaseAttributes(Decal d) { Side s = d.side; m_base_normal = s.FindNormal(); // Center position switch (d.align) { case DecalAlign.TEXTURE: m_base_pos = s.FindUVCenterIn3D(); break; case DecalAlign.CENTER: m_base_pos = s.FindCenter(); break; case DecalAlign.EDGE_RIGHT: case DecalAlign.EDGE_DOWN: case DecalAlign.EDGE_LEFT: case DecalAlign.EDGE_UP: m_base_pos = s.FindEdgeCenter((int)d.align - (int)DecalAlign.EDGE_RIGHT); break; } m_base_rvec = Vector3.Zero; // Up vector switch (d.align) { case DecalAlign.TEXTURE: m_base_uvec = s.FindUVUpVector(); break; case DecalAlign.CENTER: m_base_uvec = s.FindBestEdgeDir(); break; case DecalAlign.EDGE_RIGHT: case DecalAlign.EDGE_DOWN: case DecalAlign.EDGE_LEFT: case DecalAlign.EDGE_UP: m_base_rvec = -s.FindEdgeDir((int)d.align - (int)DecalAlign.EDGE_RIGHT); m_base_uvec = Vector3.Cross(m_base_normal, m_base_rvec); break; } // Find the right vec for cases we haven't already if (m_base_rvec == Vector3.Zero) { m_base_rvec = Vector3.Cross(m_base_uvec, m_base_normal); } // Apply the rotation of the decal properties to the Up and Right Vector Matrix4 vec_rot = Matrix4.CreateFromAxisAngle(m_base_normal, d.RotationAngle()); m_base_uvec = Vector3.TransformNormal(m_base_uvec, vec_rot); m_base_rvec = Vector3.TransformNormal(m_base_rvec, vec_rot); // Base rotation m_base_rot = Matrix4.Transpose(Matrix4.LookAt(Vector3.Zero, m_base_normal, m_base_uvec)); }