public override void SetTerrain(float[] heightMap) { for (int i = 0; i < 65536; i++) { this._heightmap[i] = (double)heightMap[i]; } IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0); d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256); LandGeom = d.CreateHeightfield(space, HeightmapData, 1); d.Matrix3 R = new d.Matrix3(); Axiom.MathLib.Quaternion q1 = Axiom.MathLib.Quaternion.FromAngleAxis(1.5707f, new Axiom.MathLib.Vector3(1, 0, 0)); Axiom.MathLib.Quaternion q2 = Axiom.MathLib.Quaternion.FromAngleAxis(1.5707f, new Axiom.MathLib.Vector3(0, 1, 0)); //Axiom.MathLib.Quaternion q3 = Axiom.MathLib.Quaternion.FromAngleAxis(3.14f, new Axiom.MathLib.Vector3(0, 0, 1)); q1 = q1 * q2; //q1 = q1 * q3; Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(); float angle = 0; q1.ToAngleAxis(ref angle, ref v3); d.RFromAxisAndAngle(out R, v3.x, v3.y, v3.z, angle); d.GeomSetRotation(LandGeom, ref R); d.GeomSetPosition(LandGeom, 128, 128, 0); }
public void Transform(Vector3 scale, Quaternion rotate, Vector3 translate) { foreach (MovingPart part in parts) { part.Transform(scale, rotate, translate); } }
private static RenderedNode NewRenderedObject(string meshName, int id, int index, Vector3 position, float scale, Quaternion orientation) { RenderedNode n = NewRenderedObject(meshName, id, index, position, scale); n.node.Orientation = orientation; return(n); }
private static RenderedNode NewRenderedObject(string meshName, int id, int index, Vector3 position, Vector3 scale, Quaternion orientation) { RenderedNode n = UnscaledRenderedObject(meshName, id, index, position); n.node.ScaleFactor = scale; n.node.Orientation = orientation; return(n); }
private static RenderedNode NewRenderedBox(int id, int index, CollisionOBB box) { RenderedNode n = UnscaledRenderedObject("unit_box.mesh", id, index, box.center); n.node.ScaleFactor = 2 * box.extents * MO.DivMeter; Quaternion q = Quaternion.Identity; q.FromAxes(box.axes[0], box.axes[1], box.axes[2]); n.node.Orientation = q; return(n); }
public void Transform(Vector3 scale, Quaternion rotate, Vector3 translate) { // TODO: This is a temporary solution, and terribly inefficient. // I need to update the transforms on the node properly, without // the remove/add. RenderedNode.RemoveNodeRendering(id, ref renderedNodes); shape = constantShape.Clone(); shape.Transform(scale, rotate, translate); id = api.SphereTree.GetId(); renderedNodes = null; RenderedNode.MaybeCreateRenderedNodes(false, shape, id, ref renderedNodes); sphere = null; }
public override void Transform(Vector3 scale, Quaternion rotate, Vector3 translate) { if (!IsUniformScale(scale)) { throw new Exception("Unsupported non-uniform scale on Sphere"); } // Update radius and center to take the scale into account radius *= scale.x; center *= scale.x; // We can ignore the rotate for a sphere // Update the center to take the translate into account center += translate; }
public override void Transform(Vector3 scale, Quaternion rotate, Vector3 translate) { if (!IsUniformScale(scale)) { throw new Exception("Unsupported non-uniform scale on Capsule"); } Matrix4 transform = Matrix4.Identity; transform.Scale = scale; transform = rotate.ToRotationMatrix() * transform; transform.Translation = translate; bottomcenter = transform * bottomcenter; topcenter = transform * topcenter; capRadius *= scale.x; this.height = (topcenter - bottomcenter).Length; this.center = (topcenter + bottomcenter) * 0.5f; this.radius = height * 0.5f + capRadius; }
public override void Transform(Vector3 scale, Quaternion rotate, Vector3 translate) { if (!IsUniformScale(scale)) { throw new Exception("Unsupported non-uniform scale on OBB"); } Matrix4 transform = Matrix4.Identity; transform.Scale = scale; transform = rotate.ToRotationMatrix() * transform; transform.Translation = translate; this.center = transform * center; for (int i = 0; i < this.axes.Length; ++i) { this.axes[i] = rotate * axes[i]; } this.extents = scale.x * extents; this.radius = extents.Length; }
public override void Transform(Vector3 scale, Quaternion rotate, Vector3 translate) { if (rotate != Quaternion.Identity) { throw new Exception("Unsupported non-identity rotation on AABB"); } Matrix4 transform = Matrix4.Identity; transform.Scale = scale; transform = rotate.ToRotationMatrix() * transform; transform.Translation = translate; float s = 0.0f; this.min = transform * min; this.max = transform * max; for (int i = 0; i < 3; i++) { this.center[i] = (min[i] + max[i]) / 2; s += ((max[i] - min[i]) * (max[i] - min[i])); } this.radius = (float)Math.Sqrt((double)(s / 4)); }
private void generateButton_Click(object sender, EventArgs e) { Cursor previousCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; doneLabel.Visible = false; //outputPictureBox.Visible = false; if (generateLogFile.Checked) { string p = "NormalBump.log"; FileStream f = new FileStream(p, FileMode.Create, FileAccess.Write); logStream = new StreamWriter(f); logStream.Write(string.Format("{0} Started writing to {1}\n", DateTime.Now.ToString("hh:mm:ss"), p)); } // run the algorithm Bitmap normalMap = new Bitmap(normalMapTextBox.Text); Bitmap bumpMap = new Bitmap(bumpMapTextBox.Text); if (normalMap.Width != bumpMap.Width) { ShowError("Normal Map width {0} is not the same as Bump Map width {1}", normalMap.Width, bumpMap.Width); return; } if (normalMap.Height != bumpMap.Height) { ShowError("Normal Map height {0} is not the same as Bump Map height {1}", normalMap.Height, bumpMap.Height); return; } Bitmap outputMap = (Bitmap)normalMap.Clone(); PixelFormat normalFormat = normalMap.PixelFormat; PixelFormat bumpFormat = bumpMap.PixelFormat; // This will be set by the slider float scaleFactor = (float)trackBar.Value / 100f; if (reverseBumpDirection.Checked) { scaleFactor = -scaleFactor; } Vector3 unitZ = new Vector3(0f, 0f, 1f); float epsilon = 0.0000001f; // Loop through the bump map pixels, computing the normals // into the output map int w = normalMap.Width; int h = normalMap.Height; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { // Fetch the normal map normal vector Color c = normalMap.GetPixel(x, y); Vector3 normal = new Vector3(colorToFloat(c.R), colorToFloat(c.G), colorToFloat(c.B)).ToNormalized(); Vector3 result = normal; // If we're at the edge, use the normal vector if (x < w - 1 && y < h - 1) { // Compute the bump normal vector int xyLevel = bumpLevel(bumpMap, x, y); float dx = scaleFactor * (bumpLevel(bumpMap, x + 1, y) - xyLevel); float dy = scaleFactor * (bumpLevel(bumpMap, x, y + 1) - xyLevel); float dz = 255f; Vector3 bumpNormal = new Vector3(dx, dy, dz).ToNormalized(); if (generateLogFile.Checked) { Log("X {0}, Y {1}, normal {2}, bumpNormal {3}\n", x, y, normal, bumpNormal); } Vector3 axis = unitZ.Cross(normal); if (axis.Length > epsilon) { float cosAngle = unitZ.Dot(normal); float angle = (float)Math.Acos(cosAngle); Quaternion q = Quaternion.FromAngleAxis(angle, axis); Matrix3 rot = q.ToRotationMatrix(); result = rot * bumpNormal; if (generateLogFile.Checked) { Log(" Angle {0}, Quaternion {1}, Result {2}\n", angle, q, result); } } } Color resultColor = Color.FromArgb(floatToColor(result.x), floatToColor(result.y), floatToColor(result.z)); outputMap.SetPixel(x, y, resultColor); } } if (generateLogFile.Checked) { logStream.Close(); } outputMap.Save(outputMapTextBox.Text); outputPictureBox.Image = outputMap; outputPictureBox.Visible = true; Cursor.Current = previousCursor; doneLabel.Visible = true; }
public abstract void Transform(Vector3 scale, Quaternion rotate, Vector3 translate);
public override void Transform(Vector3 scale, Quaternion rotate, Vector3 translate) { if (!IsUniformScale(scale)) throw new Exception("Unsupported non-uniform scale on OBB"); Matrix4 transform = Matrix4.Identity; transform.Scale = scale; transform = rotate.ToRotationMatrix() * transform; transform.Translation = translate; this.center = transform * center; for (int i = 0; i < this.axes.Length; ++i) this.axes[i] = rotate * axes[i]; this.extents = scale.x * extents; this.radius = extents.Length; }
public override void Transform(Vector3 scale, Quaternion rotate, Vector3 translate) { if (!IsUniformScale(scale)) throw new Exception("Unsupported non-uniform scale on Capsule"); Matrix4 transform = Matrix4.Identity; transform.Scale = scale; transform = rotate.ToRotationMatrix() * transform; transform.Translation = translate; bottomcenter = transform * bottomcenter; topcenter = transform * topcenter; capRadius *= scale.x; this.height = (topcenter - bottomcenter).Length; this.center = (topcenter + bottomcenter) * 0.5f; this.radius = height * 0.5f + capRadius; }
public override void Transform(Vector3 scale, Quaternion rotate, Vector3 translate) { throw new Exception("The method or operation is not implemented."); }
public override void Transform(Vector3 scale, Quaternion rotate, Vector3 translate) { if (rotate != Quaternion.Identity) throw new Exception("Unsupported non-identity rotation on AABB"); Matrix4 transform = Matrix4.Identity; transform.Scale = scale; transform = rotate.ToRotationMatrix() * transform; transform.Translation = translate; float s = 0.0f; this.min = transform * min; this.max = transform * max; for (int i = 0; i < 3; i++) { this.center[i] = (min[i] + max[i]) / 2; s += ((max[i] - min[i]) * (max[i] - min[i])); } this.radius = (float)Math.Sqrt((double)(s / 4)); }
public override void Transform(Vector3 scale, Quaternion rotate, Vector3 translate) { if (!IsUniformScale(scale)) throw new Exception("Unsupported non-uniform scale on Sphere"); // Update radius and center to take the scale into account radius *= scale.x; center *= scale.x; // We can ignore the rotate for a sphere // Update the center to take the translate into account center += translate; }
public void Transform(Vector3 scale, Quaternion rotate, Vector3 translate) { foreach(MovingPart part in parts) part.Transform(scale, rotate, translate); }