protected virtual void Draw3D(bool forSelection) { gl.MatrixMode(gl.MODELVIEW); gl.LoadIdentity(); // Move out Z axis so we can see everything (needed only for Perspective view) gl.Translatef(0, 0, zModel); if (projectionMode == projectionType.Perspective && // we see it only in perspective mode shadowMode != shadowType.None && forSelection != true) { DrawShadow(); } gl.Rotatef(MU.radToDeg(rotAngle), rotAxis.x, rotAxis.y, rotAxis.z); // multiply into matrix // this command swaps the Y and Z axis gl.Rotatef(-90.0f, 1.0f, 0.0f, 0.0f); CenterTheModel(); if (showOrigin) { DrawOrigin(10); } // give to the model a fixed size: 100 units gl.Scalef(scaleTo100, scaleTo100, scaleTo100); foreach (LeaderLabel l in labels) { l.UpdatePos(); } if (forSelection) { gl.Disable(gl.LIGHTING); gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL); DrawSelectableEntities(); } else { DrawEntities(); } }
public void Normalize() { double norm = Norm(); Debug.Assert(!MU.floatEqualityTest(0.0f, (float)norm)); // norm should never be close to 0 x = (float)(x / norm); y = (float)(y / norm); z = (float)(z / norm); w = (float)(w / norm); Debug.Assert(MU.floatEqualityTest(1.0f, (float)Norm())); // must be normalized, safe MU.limitRange(-1.0f, ref w, 1.0f); MU.limitRange(-1.0f, ref x, 1.0f); MU.limitRange(-1.0f, ref y, 1.0f); MU.limitRange(-1.0f, ref z, 1.0f); }
public void Normalize() { double len = Length(); if (MU.floatEqualityTest(0.0f, (float)len)) // if length is zero { x = 0.0f; y = 0.0f; z = 0.0f; } else // normalize { x = (float)(x / len); y = (float)(y / len); z = (float)(z / len); zeroClamp(); } }
public void GetAxisAngle(ref Vector v, ref float angle) { double tempAngle; // temp angle double scale; // temp vars tempAngle = Math.Acos(w); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Another version where scale is sqrt (x2 + y2 + z2) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% scale = (float)Math.Sqrt(x * x + y * y + z * z); // scale = (float)sin(temp_angle); Debug.Assert(0 <= tempAngle); // make sure angle is 0 - PI Debug.Assert(Math.PI >= tempAngle); if (MU.floatEqualityTest(0.0f, (float)scale)) { // angle is 0 or 360 so just simply set axis to 0,0,1 with angle 0 angle = 0.0f; v.x = 0.0f; v.y = 0.0f; v.z = 1.0f; // any axis will do } else { angle = (float)(tempAngle * 2.0); // angle in radians v.x = (float)(x / scale); v.y = (float)(y / scale); v.z = (float)(z / scale); v.Normalize(); Debug.Assert(0.0f <= angle); // make sure rotation around axis is 0 - 360 Debug.Assert(2 * Math.PI >= angle); Debug.Assert(v.IsUnit()); // make sure a unit axis comes up } }
protected virtual void Draw2D() { gl.MatrixMode(gl.MODELVIEW); gl.LoadIdentity(); // An optimum compromise that allows all primitives to be specified // at integer positions, while still ensuring predictable rasterization, // is to translate x and y by 0.375 gl.Translatef(0.375f, 0.375f, 0.0f); gl.Disable(gl.LIGHTING); gl.LineWidth(1.0f); if (action == actionType.ZoomWindow) { DrawZoomWindowBox(); } if (action == actionType.SelectByBox) { DrawSelectionBox(); } // DrawBoundingRect(); gl.Enable(gl.LIGHTING); if (showUCSIcon) { gl.PushMatrix(); // axis icon position gl.Translatef(50.0f, 50.0f, zUcsIcon); // axis icon rotation gl.Rotatef(MU.radToDeg(rotAngle), rotAxis.x, rotAxis.y, rotAxis.z); // multiply into matrix // swaps axis Y with Z gl.Rotatef(-90.0f, 1.0f, 0.0f, 0.0f); DrawUcsIcon(); gl.PopMatrix(); gl.Disable(gl.LIGHTING); gl.PushMatrix(); gl.Color3ub(63, 63, 63); if (hasFocus) { xUcsLabel.Draw(zLabels); yUcsLabel.Draw(zLabels); zUcsLabel.Draw(zLabels); } } if (showLabels) { gl.Disable(gl.LIGHTING); originLabel.Draw(0, 20); gl.Color3ub(255, 255, 255); foreach (Label l in labels) { l.Draw(zLabels); } } if (showLegend) { DrawLegend(); } if (showProgress) { DrawProgressBar(); } gl.Color3ub(180, 180, 180); if (stencilBits == 0) { DrawText(Width - 366, Height - 50, "Stencil buffer not available. Transparent shadow will not be rendered."); } gl.PopMatrix(); }
public float AngleFromXY() { double d = Math.Sqrt(x * x + y * y); return(MU.radToDeg((float)Math.Atan2(z, d))); }
public float AngleOnXY() { return(MU.radToDeg((float)Math.Atan2(y, x))); }
void zeroClamp() { x = MU.zeroClamp(x); y = MU.zeroClamp(y); z = MU.zeroClamp(z); }
public bool IsUnit() { return(MU.floatEqualityTest(1.0f, (float)Length())); }
public bool IsZero() { return(MU.floatEqualityTest(0.0f, (float)Length())); }
protected void AxisAndAngleOnStatusBar() { ((MainForm)this.Parent).StatusText("Axis: (" + rotAxis.x.ToString("f2") + ", " + rotAxis.y.ToString("f2") + ", " + rotAxis.z.ToString("f2") + ") Angle: " + MU.radToDeg(rotAngle).ToString("f2") + " deg"); }