/// <summary> Create an <see cref="AxisAlignedBox"/> using two corners </summary> /// <param name="corner1">The first corner of the <see cref="AxisAlignedBox"/></param> /// <param name="corner2">The corner on the opposite side of the <see cref="AxisAlignedBox"/></param> public AxisAlignedBox(Position3 corner1, Position3 corner2) { Position3 minCorner = Position3.ComponentMin(corner1, corner2); Position3 maxCorner = Position3.ComponentMax(corner1, corner2); Bounds = new Position3[] { minCorner, maxCorner }; }
public Particle(int id, Position3 position, Vector3 velocity, Vector3 acceleration) { Id = id; Position = position; Velocity = velocity; Acceleration = acceleration; }
public void GetPosition(object p) { switch (p.ToString()) { case "1": Position1 = (double)ActPos1.Value; Inifile.INIWriteValue(iniPosition, "Axis1", "Position1", Position1.ToString()); break; case "2": Position2 = (double)ActPos1.Value; Inifile.INIWriteValue(iniPosition, "Axis1", "Position2", Position2.ToString()); break; case "3": Position3 = (double)ActPos1.Value; Inifile.INIWriteValue(iniPosition, "Axis1", "Position3", Position3.ToString()); break; case "4": Position4 = (double)ActPos1.Value; Inifile.INIWriteValue(iniPosition, "Axis1", "Position4", Position4.ToString()); break; case "5": Position5 = (double)ActPos1.Value; Inifile.INIWriteValue(iniPosition, "Axis1", "Position5", Position5.ToString()); break; } }
/// <summary> /// Makes the contents of this message dump to a easy to understand string /// </summary> /// <returns></returns> public override string ToString() { return(string.Format( "{0} - {1:1;0;0}{2:1;0;0}{3:1;0;0}", ErrorCode, Position1.GetHashCode(), Position2.GetHashCode(), Position3.GetHashCode())); }
public CCPoint GetWorldPosition(float hexRadius, float hexMargin) { var p1 = Position1.GetWorldPosition(hexRadius, hexMargin); var p2 = Position2.GetWorldPosition(hexRadius, hexMargin); var p3 = Position3.GetWorldPosition(hexRadius, hexMargin); var result = (p1 + p2 + p3) / 3; return(result); }
public override int GetHashCode() { unchecked { var hashCode = Position1.GetHashCode(); hashCode = (hashCode * 397) ^ Position2.GetHashCode(); hashCode = (hashCode * 397) ^ Position3.GetHashCode(); return(hashCode); } }
protected override void ProcessInputs(out bool processAllOutputs) { data = new Position3( (float)inX.GetData(), (float)inY.GetData(), (float)inZ.GetData()); outputs[0].SetData(data.ToVector()); hasProcessedThisFrame = true; processAllOutputs = true; }
Chunk CreateChunk(Position3 pos) { Chunk chunk; chunks.TryGetValue(pos, out chunk); if (chunk == null) { chunk = new Chunk(pos); } return(CreateChunk(chunk)); }
public void Constructor() { Position3 P1 = Utils.ThreadRandom.Vector(); Position3 P2 = Utils.ThreadRandom.Vector(); Position3 P3 = Utils.ThreadRandom.Vector(); Triangle triangle = new(P1, P2, P3); Assert.AreEqual(P1, triangle.P1); Assert.AreEqual(P2, triangle.P2); Assert.AreEqual(P3, triangle.P3); }
public Body6Dof(int id, float confidence, float p0, float p1, float p2, float m0, float m1, float m2, float m3, float m4, float m5, float m6, float m7, float m8) : base(id) { this.Confidence = confidence; this.Position = new Position3(p0, p1, p2); this.RotationMatrix = new Rotation3x3(m0, m1, m2, m3, m4, m5, m6, m7, m8); }
/// <summary> Create an <see cref="AxisAlignedBox"/> that encompasses <paramref name="positions"/> </summary> /// <param name="positions">The positions that the <see cref="AxisAlignedBox"/> should encompass</param> public AxisAlignedBox(params Position3[] positions) { Position3 minCorner = Position3.PositiveInfinity; Position3 maxCorner = Position3.NegativeInfinity; foreach (Position3 position in positions) { minCorner = Position3.ComponentMin(minCorner, position); maxCorner = Position3.ComponentMax(maxCorner, position); } Bounds = new Position3[] { minCorner, maxCorner }; }
public void ExceptValueExcludesCorrectValue() { var p = Position3.Create("foo", "bar", "baz"); var p1 = p.ExceptValue1; Assert.Equal("bar", p1.ProductValue1); Assert.Equal("baz", p1.ProductValue2); var p2 = p.ExceptValue2; Assert.Equal("foo", p2.ProductValue1); Assert.Equal("baz", p2.ProductValue2); }
// TODO Optimize public IEnumerable <HexagonNode> GetAdjacentHexagonNodes() { var positions = new[] { Position1, Position2, Position3 }; var adj1 = Position1.GetAdjacentHexagonPositions(); var adj2 = Position2.GetAdjacentHexagonPositions(); var adj3 = Position3.GetAdjacentHexagonPositions(); var new3 = adj1.Intersect(adj2).First(a => !positions.Contains(a)); var new2 = adj1.Intersect(adj3).First(a => !positions.Contains(a)); var new1 = adj2.Intersect(adj3).First(a => !positions.Contains(a)); var result = new[] { new HexagonNode(new1, Position2, Position3), new HexagonNode(Position1, new2, Position3), new HexagonNode(Position1, Position2, new3) }; return(result); }
public void AddingPositionBufferedAddsPositionComponentsToBuffer() { Vector3 testCandidate = new Vector3(5.2f, -1.1f, -3.1f); Position3 toAdd = new Position3(1.5f, 1.1f, 2.8f); float expectedZ = -3.1f + 2.8f; testCandidate.AddImmutableBufferResult(toAdd); Assert.That(testCandidate.GetBufferedResultX(), Is.EqualTo(6.7f)); Assert.That(testCandidate.GetBufferedResultY(), Is.EqualTo(0.0f)); Assert.That(testCandidate.GetBufferedResultZ(), Is.EqualTo(expectedZ)); Assert.That(testCandidate.GetX(), Is.EqualTo(5.2f)); Assert.That(testCandidate.GetY(), Is.EqualTo(-1.1f)); Assert.That(testCandidate.GetZ(), Is.EqualTo(-3.1f)); }
void Update() { Vector3 pos; Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; // get mouse position if (Physics.Raycast(r, out hit, 10000.0f)) { if (!marker.gameObject.activeSelf) { marker.gameObject.SetActive(true); } pos = hit.point - hit.normal * 0.5f; bool wantToBuild = Input.GetButtonDown("Fire1"); bool wantToDelete = Input.GetButtonDown("Fire2"); bool wantToMakeSlope = Input.GetKeyDown(KeyCode.F); // interaction! if (wantToDelete) { ChangeVoxel(Position3.FlooredVector(pos), new Voxel(0)); // REMOVE } else if (wantToBuild) { ChangeVoxel(Position3.FlooredVector(pos) + Position3.RoundedVector(hit.normal), new Voxel(2)); // ADD } else if (wantToMakeSlope) { ChangeVoxel(Position3.FlooredVector(pos) + Position3.RoundedVector(hit.normal), new Voxel(10)); // ADD } pos = hit.point + hit.normal * 0.5f; pos.x = Mathf.Floor(pos.x) + 0.5f; pos.y = Mathf.Floor(pos.y) + 0.5f; pos.z = Mathf.Floor(pos.z) + 0.5f; marker.position = pos; } else { if (marker.gameObject.activeSelf) { marker.gameObject.SetActive(false); } } }
public void GetClippedPoints_TwoClipped() { Position3 P1 = new(1, 0, 1); Position3 P2 = new(0, 0, 1); Position3 P3 = new(0, 0, -1); Triangle triangle = new(P1, P2, P3); AxisAlignedPlane plane = new(Unit3.Z, 0); List <Position3> points = new(triangle.GetClippedPoints(plane)); Assert.AreEqual(points.Count, 4); CollectionAssert.Contains(points, triangle.P1); CollectionAssert.Contains(points, triangle.P2); CollectionAssert.DoesNotContain(points, triangle.P3); Position3 P31 = Position3.Lerp(P3, P2, 0.5f); Position3 P32 = Position3.Lerp(P3, P1, 0.5f); CollectionAssert.Contains(points, P31); CollectionAssert.Contains(points, P32); }
public BodyFlystick(int id, float confidence, float p0, float p1, float p2, float m0, float m1, float m2, float m3, float m4, float m5, float m6, float m7, float m8, int[] buttons, int buttonCount, float[] controllers, int controllerCount) : base(id) { this.Confidence = confidence; this.Position = new Position3(p0, p1, p2); this.RotationMatrix = new Rotation3x3(m0, m1, m2, m3, m4, m5, m6, m7, m8); this.Buttons = buttons; this.Controllers = controllers; this.ButtonCount = buttonCount; this.ControllerCount = controllerCount; }
public void GetClippedPoints_OneClipped() { Position3 P1 = new(1, 0, 1); Position3 P2 = new(0, 0, 1); Position3 P3 = new(0, 0, -1); Triangle triangle = new(P1, P2, P3); AxisAlignedPlane plane = new(Unit3.MinZ, 0); Position3[] points = triangle.GetClippedPoints(plane).ToArray(); Assert.AreEqual(points.Length, 3); CollectionAssert.DoesNotContain(points, triangle.P1); CollectionAssert.DoesNotContain(points, triangle.P2); CollectionAssert.Contains(points, triangle.P3); Position3 P11 = Position3.Lerp(P1, P3, 0.5f); Position3 P21 = Position3.Lerp(P2, P3, 0.5f); CollectionAssert.Contains(points, P11); CollectionAssert.Contains(points, P21); }
Position3 getPosition(string data) { string subData = getAfter(data); ////After first Parameter -> CommandType, ParameterType and Parameter subData = getAfter(subData); //After second Parameter -> ParameterType and Parameter subData = getAfter(subData); //After third Parameter -> Only Parameters string x = getNext(subData); //Third Parameter -> Parameter of command, the X, Y and Z axis of position subData = getAfter(subData); // Y and Z string y = getNext(subData); //Fourth Parameter -> Parameter of command, the y axis of position subData = getAfter(subData); // Z string z = getNext(subData); //Fifth Parameter -> Parameter of command, the Z axis of position Position3 position = new Position3(); position.x = toFloat(x); position.y = toFloat(y); position.z = toFloat(z); return(position); }
/// <summary> Get the normal of the <see cref="AxisAlignedBox"/> at a specified <paramref name="position"/> </summary> /// <param name="position">The surface position to get the normal for</param> /// <returns>The normal at the specified <paramref name="position"/></returns> public Normal3 SurfaceNormal(Position3 position) { Direction3 direction = (position - Center) / (Position3.Origin + Size); Direction1 x = IDirection1.Abs(direction.X); Direction1 y = IDirection1.Abs(direction.Y); Direction1 z = IDirection1.Abs(direction.Z); Normal3 normal; if (x > y && x > z) { normal = direction.X > 0f ? Normal3.UnitX : -Normal3.UnitX; } else if (y > z) { normal = direction.Y > 0f ? Normal3.UnitY : -Normal3.UnitY; } else { normal = direction.Z > 0f ? Normal3.UnitZ : -Normal3.UnitZ; } return(normal); }
/// <summary> Clip the <see cref="AxisAlignedBox"/> by a <paramref name="plane"/> </summary> /// <param name="plane">The <see cref="AxisAlignedPlane"/> to clip the <see cref="AxisAlignedBox"/> with</param> /// <returns>A new clipped <see cref="AxisAlignedBox"/> if it's not clipped entirely</returns> public IEnumerable <AxisAlignedBox> Clip(AxisAlignedPlane plane) { Position3 minCorner = MinCorner; Position3 maxCorner = MaxCorner; if (plane.Normal == Normal3.UnitX) { minCorner = new(Position1.Max(MinCorner.X, plane.Position.X), MinCorner.Y, MinCorner.Z); } else if (plane.Normal == -Normal3.UnitX) { maxCorner = new(Position1.Min(MinCorner.X, plane.Position.X), MaxCorner.Y, MaxCorner.Z); } else if (plane.Normal == Normal3.UnitY) { minCorner = new(MinCorner.X, Position1.Max(MinCorner.Y, plane.Position.Y), MinCorner.Z); } else if (plane.Normal == -Normal3.UnitY) { maxCorner = new(MaxCorner.X, Position1.Min(MaxCorner.Y, plane.Position.Y), MaxCorner.Z); } else if (plane.Normal == Normal3.UnitZ) { minCorner = new(MinCorner.X, MinCorner.Y, Position1.Max(MinCorner.Z, plane.Position.Z)); } else if (plane.Normal == -Normal3.UnitZ) { maxCorner = new(MaxCorner.X, MaxCorner.Y, Position1.Min(MaxCorner.Z, plane.Position.Z)); } if (minCorner == MinCorner && maxCorner == MaxCorner) { yield return(this); } else if (minCorner.X < maxCorner.X && minCorner.Y < maxCorner.Y && minCorner.Z < maxCorner.Z) { yield return(new AxisAlignedBox(minCorner, maxCorner)); } }
public ISpectrum GetEmittance(Position3 position, Normal3 orientation, Normal3 direction) { return(Spectrum); }
public IProbabilityDistribution <Normal3> GetDirections(Normal3 incomingDirection, Position3 position, Normal3 orientation, ISpectrum spectrum) { return(new SphericalUniform()); }
public void LookAt(Position3 Target) { Target -= Position; fViewMatrix = Matrix.CreateLookAt(Vector3.Zero, (Vector3)Target, (Vector3)fUp); Vector3 Scale; Vector3 Translation; fViewMatrix.Decompose(out Scale, out fOrientation, out Translation); fOrientation = Quaternion.Inverse(fOrientation); // transform the local reference vectors to get the world vectors Vector3.Transform(ref fForwardLocal, ref fOrientation, out fForward); Vector3.Transform(ref fRightLocal, ref fOrientation, out fRight); Vector3.Transform(ref fUpLocal, ref fOrientation, out fUp); fViewProjectionMatrix = fViewMatrix * fProjectionMatrix; fFrustum = new BoundingFrustum(fViewProjectionMatrix); }
public IProbabilityDistribution <Normal3> GetOrientations(Position3 position, Normal3 direction, IShape shape) { return(new UniformPMF <Normal3>(shape.OutwardsDirection(position))); }
public void UpdateCamera(float elapsed) { fRotationalVelocity += (fRotationalAcceleration * elapsed); fRotationTime += elapsed; while (fRotationTime >= (1.0f / 60.0f)) { fRotationalVelocity *= fRotationalDrag; fRotationTime -= (1.0f / 60.0f); fRotationalAcceleration = Vector3.Zero; } float Yaw = MathHelper.ToRadians(fRotationalVelocity.Y * elapsed); float Pitch = MathHelper.ToRadians(fRotationalVelocity.X * elapsed); float Roll = MathHelper.ToRadians(fRotationalVelocity.Z * elapsed); // create a rotation quaternion based on orientation changes - this is the amount to rotate Quaternion Rotation = Quaternion.CreateFromYawPitchRoll(Yaw, Pitch, Roll); // add the rotation to the current rotation quaternion fOrientation *= Rotation; // transform the local reference vectors to get the world vectors Vector3.Transform(ref fForwardLocal, ref fOrientation, out fForward); Vector3.Transform(ref fRightLocal, ref fOrientation, out fRight); Vector3.Transform(ref fUpLocal, ref fOrientation, out fUp); // TODO : not positive this needs to be done fForward.Normalize(); fRight.Normalize(); fUp.Normalize(); // apply linear acceleration to velocity fLinearVelocity += fLinearAcceleration * elapsed; fLinearTime += elapsed; while (fLinearTime >= (1.0f / 60.0f)) { fLinearVelocity *= fLinearDrag; fLinearTime -= (1.0f / 60.0f); fLinearAcceleration = Vector3.Zero; } fLocalPosition.Add(fLinearVelocity); Position = fLocalPosition + AttachedPosition; // update matrices UpdateViewMatrix(); }
public IProbabilityDistribution <Normal3> GetDirections(Normal3 incomingDirection, Position3 position, Normal3 orientation, ISpectrum spectrum) { throw new NotImplementedException("Requires structure to remember indices of refraction"); }
// public Chunk(Position3 pos) { this.pos = pos; Main.chunks[pos] = this; }
private void processCommand(string data) { string idCommand = getCommandId(data); CommandType commandType = getCommandType(data); ParameterType parameterType = getParameterType(data); if (checkCmdParType(commandType, parameterType)) { ActionHand ah = getActionAndHand(commandType); if (ah != null) { switch (parameterType) { case ParameterType.WithId: int id = getId(data); GameObject gO = getGameObjectById(id); runningCommands.Add(scm.sendCommand(idCommand, ah.hand, ah.action, gO.transform)); break; case ParameterType.WithPos: Position3 position = getPosition(data); Vector3 auxPosition = new Vector3(position.x, position.y, position.z); runningCommands.Add(scm.sendCommand(idCommand, ah.hand, ah.action, auxPosition)); break; case ParameterType.WithString: string str = getText(data); runningCommands.Add(scm.sendCommand(idCommand, ah.action, str)); break; case ParameterType.WithAngle: float angle = getAngle(data); runningCommands.Add(scm.sendCommand(idCommand, ah.action, angle)); break; case ParameterType.WithoutParameter: if (ah.isToUseHand()) { runningCommands.Add(scm.sendCommand(idCommand, ah.hand, ah.action)); } else { runningCommands.Add(scm.sendCommand(idCommand, ah.action)); } break; default: { break; } } } else { Response response = new Response { idCommand = idCommand, executed = false }; sendResponse(response); } } }
public IProbabilityDistribution <Normal3> GetDirections(Normal3 incomingDirection, Position3 position, Normal3 orientation, ISpectrum spectrum) { return(new HemisphericalDiffuse(orientation)); }
public IRay GetRay(Position3 position, Normal3 orientation, Normal3 direction) { return(new Ray(position, direction)); }
// void OnGUI() { GUI.Label(new Rect(10, 10, 300, 200), "Pos: " + Position3.FlooredVector(marker.position) + "\nMove with Mouse MB\nCreate with LB\nRemove with RB"); }
// // helper method int GetVoxelRelPosIndex(Position3 pos) { return (pos.y + 1) * chunkSizeA2P2 + (pos.z + 1) * chunkSizeA2 + (pos.x + 1); }
// CREATE OR CHANGE A VOXEL void ChangeVoxel(Position3 posAbs, Voxel voxel, bool updateChunk = true, int padX = 0, int padY = 0, int padZ = 0) { #if UNITY_EDITOR if (padX < -1 || padX > 1) { Debug.LogError("Padding (X) too big!"); } if (padY < -1 || padY > 1) { Debug.LogError("Padding (Y) too big!"); } if (padZ < -1 || padZ > 1) { Debug.LogError("Padding (Z) too big!"); } #endif Position3 chunkPos = new Position3( (posAbs.x < 0 ? (posAbs.x - chunkSize + 1) : posAbs.x) / chunkSize - padX, // TODO: >> instead of /? (posAbs.y < 0 ? (posAbs.y - chunkSize + 1) : posAbs.y) / chunkSize - padY, // TODO: >> instead of /? (posAbs.z < 0 ? (posAbs.z - chunkSize + 1) : posAbs.z) / chunkSize - padZ // TODO: >> instead of /? ); Chunk curChunk; if (!chunks.TryGetValue(chunkPos, out curChunk)) { curChunk = new Chunk(chunkPos); } Position3 posRel = posAbs - (chunkPos * chunkSize); int posRelIndex = GetVoxelRelPosIndex(posRel); List<int> dataPosInd = new List<int>(); // using List<>s for edit mode only? List<Voxel> dataVoxel = new List<Voxel>(); if (curChunk.additionalVoxelsDataNum != 0) { // get the already created add voxel data dataPosInd.AddRange(curChunk.additionalVoxelsDataPosIndices); dataVoxel.AddRange(curChunk.additionalVoxelsDataBoxIndices); } if (dataPosInd.Contains(posRelIndex)) { // box was changed already Voxel sb = GetStandardVoxel(posAbs.x, posAbs.y, posAbs.z); int dpi = dataPosInd.IndexOf(posRelIndex); if (voxel == sb) { // is standard box? -> remove this add data dataPosInd.RemoveAt(dpi); dataVoxel.RemoveAt(dpi); curChunk.additionalVoxelsDataNum--; } else { // is new box type? -> replace it dataVoxel[dpi] = voxel; } } else { // voxel was never changed before? -> add it dataPosInd.Add(posRelIndex); dataVoxel.Add(voxel); curChunk.additionalVoxelsDataNum++; } curChunk.additionalVoxelsDataPosIndices = dataPosInd.ToArray(); curChunk.additionalVoxelsDataBoxIndices = dataVoxel.ToArray(); // somewhere at the limits? if (padY == 0 && padZ == 0 && posRel.x == 0) ChangeVoxel(posAbs, voxel, updateChunk, 1); else if (padY == 0 && padZ == 0 && posRel.x == chunkSize - 1) ChangeVoxel(posAbs, voxel, updateChunk, -1); if (padX == 0 && padZ == 0 && posRel.y == 0) ChangeVoxel(posAbs, voxel, updateChunk, 0, 1); else if (padX == 0 && padZ == 0 && posRel.y == chunkSize - 1) ChangeVoxel(posAbs, voxel, updateChunk, 0, -1); if (padX == 0 && padY == 0 && posRel.z == 0) ChangeVoxel(posAbs, voxel, updateChunk, 0, 0, 1); else if (padX == 0 && padY == 0 && posRel.z == chunkSize - 1) ChangeVoxel(posAbs, voxel, updateChunk, 0, 0, -1); // update chunk if (updateChunk) { CreateChunk(curChunk); } else { tempChunksToGetUpdated.Add(curChunk); } }
public void Clone(Camera camera) { Orientation = camera.Orientation; fLocalPosition = camera.fLocalPosition; UpdateCamera(0); }
public ISpectrum GetAlbedo(Position3 position, Normal3 orientation, Normal3 direction) { return(Albedo); }
Chunk CreateChunk(Position3 pos) { Chunk chunk; chunks.TryGetValue(pos, out chunk); if (chunk == null) { chunk = new Chunk(pos); } return CreateChunk(chunk); }