private bool WithinSOI(BodyInfo body) { double distance = PrecisePosition.Distance(shipPosition, body.precisePosition); float SOI = body.radius * SOIScaler; return(distance < SOI); }
public static PrecisePosition FromOffsets( Position position, double incOffset, double aziOffset, double gtfOffset) { var p = new PrecisePosition(position, incOffset, aziOffset, gtfOffset); return(p); }
public OrbitPoint[] GenerateOrbit(BodyInfo body) { List <OrbitPoint> orbitPoints = new List <OrbitPoint>(); OrbitalElements orbit = body.orbit; double semiMinorAxis = orbit.SemiMinorAxis(); //double moveOffset = (orbit.apoapsis + orbit.periapsis) / 2 - orbit.periapsis; float timer = Mathf.PI * 2; for (float t = 0; t < timer; t++) { double posX = orbit.semiMajorAxis * Mathd.Cos(timer) /* - moveOffset*/; double posZ = semiMinorAxis * Mathd.Sin(timer); double posY = 0; // ? double nPosX = posX * Mathd.Cos(orbit.inclination) - posY * Mathd.Sin(orbit.inclination); double nPosY = posY * Mathd.Cos(orbit.inclination) + posX * Mathd.Sin(orbit.inclination); double nPosX2 = nPosX * Mathd.Cos(orbit.inclination) - posZ * Mathd.Sin(orbit.inclination); double nPosZ = posZ * Mathd.Cos(orbit.inclination) + nPosX * Mathd.Sin(orbit.inclination); PrecisePosition pointPosition = new PrecisePosition(nPosX, nPosY, nPosZ); double pointVelocity = Mathd.Sqrt( Mathd.Abs((g * body.mass) * ((2 / body.radius) - (1 / orbit.semiMajorAxis))) ); orbitPoints.Add(new OrbitPoint(pointPosition, pointVelocity)); } return(orbitPoints.ToArray()); }
protected override void OnUpdate() { if (flag) { return; } flag = true; ComponentGroup planetGroup = GetComponentGroup(typeof(Planet), typeof(PlanetNoise)); ComponentGroup dataGroup = GetComponentGroup(typeof(PlanetSharedData)); ComponentDataArray <Planet> planetArray = planetGroup.GetComponentDataArray <Planet>(); ComponentDataArray <PlanetNoise> noiseArray = planetGroup.GetComponentDataArray <PlanetNoise>(); SharedComponentDataArray <PlanetSharedData> dataArray = dataGroup.GetSharedComponentDataArray <PlanetSharedData>(); GameObject prefab = dataArray[0].nodePrefab; for (int i = 0; i < planetArray.Length; ++i) { Planet planet = planetArray[i]; PlanetNoise noise = noiseArray[i]; HyperDistance r = planet.radius; for (int n = 0; n < 20; ++n) { Entity nodeEntity = EntityManager.Instantiate(prefab); TerrainNode node = EntityManager.GetComponentData <TerrainNode>(nodeEntity); node.level = 0; node.planetData = planet; node.noiseData = noise; node.built = 0; node.divided = 0; node.hyperDistant = 1; int idx = n * 3; node.corner1 = icoVerts[idx]; node.corner2 = icoVerts[idx + 1]; node.corner3 = icoVerts[idx + 2]; EntityManager.SetComponentData(nodeEntity, node); HyperPosition pos = math.normalize(node.corner1 + node.corner2 + node.corner3) * r; PrecisePosition prspos = new PrecisePosition { pos = pos.prs }; EntityManager.SetComponentData(nodeEntity, prspos); OctantPosition octpos = new OctantPosition { pos = pos.oct }; EntityManager.SetComponentData(nodeEntity, octpos); } } }
public static PrecisePosition FromAbsolute( Position position, double inc, double azi, double gtf) { var p = new PrecisePosition(position, 0, 0, 0); p.IncOffset = inc - p._values[0]; p.AziOffset = azi - p._values[1]; p.GtfOffset = gtf - p._values[2]; return(p); }
public override bool Equals(System.Object obj) { if (obj == null) { return(false); } PrecisePosition p = obj as PrecisePosition; if ((System.Object)p == null) { return(false); } return(this == p); }
public static async Task <MeasureResult> DeserializeAsync(string fileName, IEnumerable <byte> content) { await ThreadingUtils.ContinueAtThreadPull(); var eb = new ExceptionBuilder(); try { var date = CommonUtils.TryOrDefault( () => DateTime.ParseExact(fileName.Split(" InGK ").FirstElement(), TIME_FORMAT, null)); eb.SetException("Не удалось прочитать файл. Формат файла некорректен."); var reader = new StreamReader(content.ToMemoryStream(), Encoding.GetEncoding(CSV_ENCODING)); var columns = reader .ReadAllLines() .FirstItem() .Split(CSV_SEPARATOR); var rows = parsePositionMeasures(reader).ToArray(); return(new MeasureResult(date, columns, rows)); } catch (Exception ex) { throw eb.InstantiateException(ex); } IEnumerable <PositionMeasureResult> parsePositionMeasures(StreamReader reader) { var lines = reader.ReadAllLines().ToArray().StartEnumeration(); lines.AdvanceOrThrow(); while (true) { var one = parseOne(); if (one == null) { yield break; } else { yield return(one); } } PositionMeasureResult parseOne() { if (lines.IsFinished) { return(null); } var line = lines.Current; if (line == null) { return(null); } else if (!line.StartsWith("Position")) { throw new Exception(); } var serializedPosition = line .Split(CSV_SEPARATOR) .Skip(2) .Take(3) .Select(v => v.ParseToDoubleInvariant()) .ToArray(); var p = new V3(serializedPosition[0], serializedPosition[1], serializedPosition[2]); var positionInfo = (from pos in EnumUtils.GetValues <Position>() let angles = pos.GetAngles() let v3 = new V3(angles.Inc, angles.Azi, angles.GTF) let dV = v3 - p select(DDistance: dV, Position: pos)) .OrderBy(v => v.DDistance.Mag) .FirstItem().Position; var position = PrecisePosition.FromAbsolute( positionInfo, p.X, p.Y, p.Z); var positionMeasure = new PositionMeasureResult( position, new List <IEnumerable <double> >()); foreach (var l in lines.AdvanceRange()) { if (l.StartsWith("Position")) { break; } var measures = l .Split(CSV_SEPARATOR) .Where(v => v.IsNotNullOrWhiteSpace()) .Select(v => v.ParseToDoubleInvariant()) .ToArray(); positionMeasure.Result.Add(measures); } return(positionMeasure); } } }
public PositionMeasureResult(PrecisePosition position, IList <IEnumerable <double> > result) { Position = position ?? throw new ArgumentNullException(nameof(position)); Result = result ?? throw new ArgumentNullException(nameof(result)); }
private void Subdivide(Entity e, TerrainNode t, HPMeshInstanceRenderer r, PlanetSharedData d, float parentPrcSubdivideDist, int parentOctSubdivideDist, float3 parentPrcCenter, int3 parentOctCenter) { Entity[] entities = new Entity[4]; TerrainNode[] nodes = new TerrainNode[4]; float3 corner0 = t.corner1; float3 corner1 = t.corner2; float3 corner2 = t.corner3; for (int i = 0; i < 4; ++i) { entities[i] = EntityManager.Instantiate(d.nodePrefab); nodes[i] = EntityManager.GetComponentData <TerrainNode>(entities[i]); nodes[i].level = t.level + 1; nodes[i].planetData = t.planetData; nodes[i].noiseData = t.noiseData; nodes[i].built = 0; nodes[i].divided = 0; nodes[i].childrenBuilt = 0; nodes[i].parentEntity = e; nodes[i].parentPreciseCenter = parentPrcCenter; nodes[i].parentOctantCenter = parentOctCenter; nodes[i].parentPreciseSubdivideDist = parentPrcSubdivideDist; nodes[i].parentOctantSubdivideDist = parentOctSubdivideDist; } float3 mid01 = corner1 - corner0; mid01 = corner0 + math.normalize(mid01) * (math.length(mid01) / 2f); float3 mid02 = corner2 - corner0; mid02 = corner0 + math.normalize(mid02) * (math.length(mid02) / 2f); float3 mid12 = corner2 - corner1; mid12 = corner1 + math.normalize(mid12) * (math.length(mid12) / 2f); nodes[0].corner1 = corner0; nodes[0].corner2 = mid01; nodes[0].corner3 = mid02; nodes[1].corner1 = mid01; nodes[1].corner2 = corner1; nodes[1].corner3 = mid12; nodes[2].corner1 = mid02; nodes[2].corner2 = mid12; nodes[2].corner3 = corner2; nodes[3].corner1 = mid02; nodes[3].corner2 = mid01; nodes[3].corner3 = mid12; for (int i = 0; i < 4; ++i) { EntityManager.SetComponentData(entities[i], nodes[i]); HyperPosition pos = math.normalize(nodes[i].corner1 + nodes[i].corner2 + nodes[i].corner3) * t.planetData.radius; PrecisePosition prspos = new PrecisePosition { pos = pos.prs }; EntityManager.SetComponentData(entities[i], prspos); OctantPosition octpos = new OctantPosition { pos = pos.oct }; EntityManager.SetComponentData(entities[i], octpos); } t.divided = 1; t.built = 0; EntityManager.SetComponentData(e, t); }
protected override void OnUpdate() { for (int i = meshCreationSets.Count - 1; i >= 0; --i) { if (meshCreationSets[i].jobHandle.IsCompleted) { meshCreationSets[i].jobHandle.Complete(); if (EntityManager.Exists(meshCreationSets[i].entity)) { Mesh mesh = new Mesh(); mesh.vertices = meshCreationSets[i].verts.ToArray(); mesh.triangles = meshCreationSets[i].tris.ToArray(); mesh.RecalculateNormals(); HPMeshInstanceRenderer r = EntityManager.GetSharedComponentData <HPMeshInstanceRenderer>(meshCreationSets[i].entity); r.mesh = mesh; EntityManager.SetSharedComponentData(meshCreationSets[i].entity, r); TerrainNode node = EntityManager.GetComponentData <TerrainNode>(meshCreationSets[i].entity); if (node.level != 0 && EntityManager.Exists(node.parentEntity)) { TerrainNode parentNode = EntityManager.GetComponentData <TerrainNode>(node.parentEntity); if (parentNode.divided == 1) { ++parentNode.childrenBuilt; if (parentNode.childrenBuilt == 4) { HPMeshInstanceRenderer parentR = EntityManager.GetSharedComponentData <HPMeshInstanceRenderer>(node.parentEntity); parentR.mesh = null; EntityManager.SetSharedComponentData(node.parentEntity, parentR); } EntityManager.SetComponentData(node.parentEntity, parentNode); } } } meshCreationSets[i].verts.Dispose(); meshCreationSets[i].tris.Dispose(); meshCreationSets.RemoveAt(i); } } ComponentGroup nodeGroup = GetComponentGroup(typeof(TerrainNode), typeof(HPMeshInstanceRenderer), typeof(PrecisePosition), typeof(OctantPosition)); ComponentGroup camGroup = GetComponentGroup(typeof(Flycam), typeof(PrecisePosition), typeof(Rotation), typeof(OctantPosition)); ComponentGroup dataGroup = GetComponentGroup(typeof(PlanetSharedData)); SharedComponentDataArray <PlanetSharedData> planetDataArray = dataGroup.GetSharedComponentDataArray <PlanetSharedData>(); PlanetSharedData[] dataArray = new PlanetSharedData[planetDataArray.Length]; for (int i = 0; i < dataArray.Length; ++i) { dataArray[i] = planetDataArray[i]; } EntityArray entityTempArray = nodeGroup.GetEntityArray(); Entity[] entityArray = new Entity[entityTempArray.Length]; for (int i = 0; i < entityArray.Length; ++i) { entityArray[i] = entityTempArray[i]; } SharedComponentDataArray <HPMeshInstanceRenderer> meshCDArray = nodeGroup.GetSharedComponentDataArray <HPMeshInstanceRenderer>(); HPMeshInstanceRenderer[] meshArray = new HPMeshInstanceRenderer[meshCDArray.Length]; for (int i = 0; i < meshArray.Length; ++i) { meshArray[i] = meshCDArray[i]; } ComponentDataArray <TerrainNode> nodeCDArray = nodeGroup.GetComponentDataArray <TerrainNode>(); TerrainNode[] nodeArray = new TerrainNode[nodeCDArray.Length]; for (int i = 0; i < nodeCDArray.Length; ++i) { nodeArray[i] = nodeCDArray[i]; } ComponentDataArray <PrecisePosition> nodePosArray = nodeGroup.GetComponentDataArray <PrecisePosition>(); PrecisePosition[] posArray = new PrecisePosition[nodePosArray.Length]; for (int i = 0; i < nodePosArray.Length; ++i) { posArray[i] = nodePosArray[i]; } ComponentDataArray <OctantPosition> nodeOctArray = nodeGroup.GetComponentDataArray <OctantPosition>(); OctantPosition[] octArray = new OctantPosition[nodePosArray.Length]; for (int i = 0; i < nodeOctArray.Length; ++i) { octArray[i] = nodeOctArray[i]; } ComponentDataArray <PrecisePosition> camPosArray = camGroup.GetComponentDataArray <PrecisePosition>(); float3 camPos = camPosArray[0].pos; ComponentDataArray <OctantPosition> camOctArray = camGroup.GetComponentDataArray <OctantPosition>(); int3 camOct = camOctArray[0].pos; float octantSize = HyperposStaticReferences.OctantSize; for (int i = 0; i < meshArray.Length; ++i) { if (nodeArray[i].built == 1 && nodeArray[i].divided == 0) { if (nodeArray[i].level < nodeArray[i].planetData.maxNodeLevels) { float3 corner0 = nodeArray[i].corner1; float3 corner1 = nodeArray[i].corner2; float3 corner2 = nodeArray[i].corner3; HyperDistance sphereRadius = nodeArray[i].planetData.radius; HyperPosition corner0Pos = corner0 * sphereRadius; HyperPosition corner1Pos = corner1 * sphereRadius; HyperDistance distToSubdivide = MathUtils.Distance(corner0Pos, corner1Pos) * (PERCENT_DIST_TO_SUBDIVIDE_AT / 100f); HyperPosition centerPos = GetNodeCenter(nodeArray[i]); //if (UnityEngine.Random.Range(0, 20) == 2) // Debug.Log(MathUtils.ToString(distToSubdivide) + "\n" + MathUtils.ToString(centerPos)); if (InSubdivideDist(camOct, camPos, centerPos.oct, centerPos.prs, distToSubdivide.oct, distToSubdivide.prs)) { //Debug.Log(MathUtils.ToString(distToSubdivide) + "\n" + MathUtils.ToString(centerPos) // + "\n" + camOct + " " + camPos); Subdivide(entityArray[i], nodeArray[i], meshArray[i], dataArray[0], distToSubdivide.prs, distToSubdivide.oct, centerPos.prs, centerPos.oct); } } if (nodeArray[i].level > 0 && EntityManager.Exists(nodeArray[i].parentEntity)) { HPMeshInstanceRenderer parentR = EntityManager.GetSharedComponentData <HPMeshInstanceRenderer>(nodeArray[i].parentEntity); //float dist = math.distance(camPos, nodeArray[i].parentCenter); //HyperDistance dist = MathUtils.Distance(camOct, camPos, // nodeArray[i].parentOctantCenter, nodeArray[i].parentPreciseCenter); //if (parentR.mesh != null // && (dist.octantDist < nodeArray[i].parentOctantSubdivideDist // || (dist.octantDist == nodeArray[i].parentOctantSubdivideDist && dist.preciseDist < nodeArray[i].parentPreciseSubdivideDist))) if (!InSubdivideDist(camOct, camPos, nodeArray[i].parentOctantCenter, nodeArray[i].parentPreciseCenter, nodeArray[i].parentOctantSubdivideDist, nodeArray[i].parentPreciseSubdivideDist)) { EntityManager.DestroyEntity(entityArray[i]); } } } else if (nodeArray[i].built == 0 && nodeArray[i].divided == 1) { float3 corner0 = nodeArray[i].corner1; float3 corner1 = nodeArray[i].corner2; float3 corner2 = nodeArray[i].corner3; HyperDistance sphereRadius = nodeArray[i].planetData.radius; HyperPosition corner0Pos = corner0 * sphereRadius; HyperPosition corner1Pos = corner1 * sphereRadius; HyperDistance distToSubdivide = MathUtils.Distance(corner0Pos, corner1Pos) * (PERCENT_DIST_TO_SUBDIVIDE_AT / 100f); HyperPosition centerPos = GetNodeCenter(nodeArray[i]); if (!InSubdivideDist(camOct, camPos, centerPos.oct, centerPos.prs, distToSubdivide.oct, distToSubdivide.prs)) { nodeArray[i].divided = 0; nodeArray[i].childrenBuilt = 0; EntityManager.SetComponentData(entityArray[i], nodeArray[i]); } } else if (nodeArray[i].built == 0 && nodeArray[i].divided == 0) { nodeArray[i].built = 1; Planet planetData = nodeArray[i].planetData; // rez is the number of vertices on one side of the mesh/triangle // the part in parentheses is called the "Mersenne Number" int rez = 2 + ((int)Mathf.Pow(2, planetData.meshSubdivisions) - 1); // nTris is the number of tris in the mesh int t = rez - 2; int nTris = (t * (t + 1)) + (rez - 1); // nVerts is the number of vertices in the mesh // it is the formula for the "Triangle Sequence" of numbers int nVerts = (rez * (rez + 1)) / 2; NativeArray <Vector3> verts = new NativeArray <Vector3>(nVerts, Allocator.Persistent); NativeArray <int> tris = new NativeArray <int>(nTris * 3, Allocator.Persistent); HyperPosition centerPos = GetNodeCenter(nodeArray[i]); HyperPosition camHyp = new HyperPosition { prs = camPos, oct = camOct }; HyperDistance dist = MathUtils.Distance(centerPos, camHyp); //if (dist > planetData.hyperdistanceThreshold) //{ // nodeArray[i].hyperDistant = 1; // if(!EntityManager.HasComponent<HyperdistantMarker>(entityArray[i])) // EntityManager.AddComponent(entityArray[i], typeof(HyperdistantMarker)); //} //else //{ // nodeArray[i].hyperDistant = 0; // if (EntityManager.HasComponent<HyperdistantMarker>(entityArray[i])) // EntityManager.RemoveComponent(entityArray[i], typeof(HyperdistantMarker)); //} MeshBuildJob job = new MeshBuildJob(); job.node = nodeArray[i]; job.corner0 = nodeArray[i].corner3; job.corner1 = nodeArray[i].corner2; job.corner2 = nodeArray[i].corner1; job.rez = rez; job.nTris = nTris; job.nVerts = nVerts; job.verts = verts; job.tris = tris; JobHandle handle = job.Schedule(); JobHandle.ScheduleBatchedJobs(); MeshCreationSet mcs = new MeshCreationSet(); mcs.entity = entityArray[i]; mcs.jobHandle = handle; mcs.verts = verts; mcs.tris = tris; meshCreationSets.Add(mcs); EntityManager.SetComponentData(entityArray[i], nodeArray[i]); } } }
protected override void OnUpdate() { ComponentGroup nodeGroup = GetComponentGroup(typeof(Flycam), typeof(PrecisePosition), typeof(OctantPosition), typeof(Rotation)); EntityArray tempEntityArray = nodeGroup.GetEntityArray(); Entity[] entityArray = new Entity[tempEntityArray.Length]; for (int i = 0; i < entityArray.Length; ++i) { entityArray[i] = tempEntityArray[i]; } ComponentDataArray <Flycam> tempFlycamArray = nodeGroup.GetComponentDataArray <Flycam>(); Flycam[] flycamArray = new Flycam[tempFlycamArray.Length]; for (int i = 0; i < flycamArray.Length; ++i) { flycamArray[i] = tempFlycamArray[i]; } ComponentDataArray <PrecisePosition> tempPosArray = nodeGroup.GetComponentDataArray <PrecisePosition>(); PrecisePosition[] posArray = new PrecisePosition[tempPosArray.Length]; for (int i = 0; i < tempPosArray.Length; ++i) { posArray[i] = tempPosArray[i]; } ComponentDataArray <OctantPosition> tempOPosArray = nodeGroup.GetComponentDataArray <OctantPosition>(); OctantPosition[] oposArray = new OctantPosition[tempOPosArray.Length]; for (int i = 0; i < tempOPosArray.Length; ++i) { oposArray[i] = tempOPosArray[i]; } ComponentDataArray <Rotation> tempRotArray = nodeGroup.GetComponentDataArray <Rotation>(); Rotation[] rotArray = new Rotation[tempRotArray.Length]; for (int i = 0; i < tempRotArray.Length; ++i) { rotArray[i] = tempRotArray[i]; } //Position[] nodeArray = new Position[posArray.Length]; //for (int i = 0; i < posArray.Length; ++i) // nodeArray[i] = posArray[i]; quaternion pitchChange = quaternion.RotateX(Input.GetAxis("Mouse Y") * -flycamArray[0].mouseSensitivity); quaternion yawChange = quaternion.RotateY(Input.GetAxis("Mouse X") * flycamArray[0].mouseSensitivity); quaternion rollChange = quaternion.RotateZ(Input.GetAxis("Roll") * -flycamArray[0].rollSensitivity); quaternion rotChange = math.mul(pitchChange, yawChange); rotChange = math.mul(rollChange, rotChange); rotArray[0] = new Rotation { Value = math.mul(rotArray[0].Value, rotChange) }; Flycam flyCam = flycamArray[0]; float axisScrollWheel = Input.GetAxis("Mouse ScrollWheel"); float octantSize = HyperposStaticReferences.OctantSize; float ospeed = flyCam.octMoveSpeed; float ospeedChange = flyCam.octMoveSpeed * flycamArray[0].moveSpeedChangeMultiplier * axisScrollWheel; ospeed += ospeedChange; float pspeedChange = ospeed % 1f; ospeed -= pspeedChange; pspeedChange *= octantSize; pspeedChange += flyCam.moveSpeed * flycamArray[0].moveSpeedChangeMultiplier * axisScrollWheel; flyCam.moveSpeed += pspeedChange; int overSpeed = (int)(flyCam.moveSpeed / octantSize); flyCam.moveSpeed -= overSpeed * octantSize; flyCam.octMoveSpeed = (int)ospeed + overSpeed; EntityManager.SetComponentData(entityArray[0], flyCam); SystemStaticReferences.SpeedText.text = flyCam.moveSpeed.ToString() + " m/s " + flyCam.octMoveSpeed.ToString() + " oct/s"; float3 forward = math.forward(rotArray[0].Value); float3 right = MathUtils.right(rotArray[0].Value); float3 up = MathUtils.up(rotArray[0].Value); float dt = Time.deltaTime; float axisForeBack = Input.GetAxis("ForeBack"); float axisHorizontal = Input.GetAxis("Horizontal"); float axisVertical = Input.GetAxis("Vertical"); float3 octChangeInitial = forward * axisForeBack * dt * flyCam.octMoveSpeed + right * axisHorizontal * dt * flyCam.octMoveSpeed + up * axisVertical * dt * flyCam.octMoveSpeed; float3 posChange = octChangeInitial % 1f; int3 octChange = (int3)(octChangeInitial - posChange); posChange *= octantSize; posChange += forward * axisForeBack * dt * flyCam.moveSpeed + right * axisHorizontal * dt * flyCam.moveSpeed + up * axisVertical * dt * flyCam.moveSpeed; int3 overPos = (int3)(posChange / octantSize); posChange -= (float3)overPos * octantSize; octChange += overPos; //float3 posChange = forward * Input.GetAxis("ForeBack") * dt * flyCam.moveSpeed // + right * Input.GetAxis("Horizontal") * dt * flyCam.moveSpeed // + up * Input.GetAxis("Vertical") * dt * flyCam.moveSpeed; posArray[0] = new PrecisePosition() { pos = posArray[0].pos + posChange }; oposArray[0] = new OctantPosition() { pos = oposArray[0].pos + octChange }; EntityManager.SetComponentData(entityArray[0], posArray[0]); EntityManager.SetComponentData(entityArray[0], rotArray[0]); EntityManager.SetComponentData(entityArray[0], oposArray[0]); }
protected override void OnUpdate() { float octantSize = HyperposStaticReferences.OctantSize; ComponentGroup camGroup = GetComponentGroup(typeof(Flycam), typeof(PrecisePosition), typeof(OctantPosition)); EntityArray entityArray = camGroup.GetEntityArray(); Entity camEntity = entityArray[0]; ComponentDataArray <PrecisePosition> tempcposArray = camGroup.GetComponentDataArray <PrecisePosition>(); PrecisePosition camPos = tempcposArray[0]; ComponentDataArray <OctantPosition> coctposArray = camGroup.GetComponentDataArray <OctantPosition>(); float3 coverPosF = math.floor(camPos.pos / octantSize); int3 coverPos = (int3)coverPosF; OctantPosition coctpos = coctposArray[0]; //Debug.Log("POS:" + camPos.pos + " OCTPOS:" + coctpos.pos); if (coverPos.x != 0 || coverPos.y != 0 || coverPos.z != 0) { coctpos.pos += coverPos; float3 offsetAmt = coverPosF * octantSize; camPos = new PrecisePosition { pos = camPos.pos - offsetAmt }; EntityManager.SetComponentData(camEntity, coctpos); EntityManager.SetComponentData(camEntity, camPos); } localOctant = coctpos.pos; ComponentGroup preciseGroup = GetComponentGroup(typeof(PrecisePosition), typeof(Position), typeof(OctantPosition)); EntityArray pposEntityArray = preciseGroup.GetEntityArray(); ComponentDataArray <PrecisePosition> pposArray = preciseGroup.GetComponentDataArray <PrecisePosition>(); ComponentDataArray <OctantPosition> oposArray = preciseGroup.GetComponentDataArray <OctantPosition>(); ComponentDataArray <Position> posArray = preciseGroup.GetComponentDataArray <Position>(); for (int i = 0; i < pposArray.Length; ++i) { PrecisePosition ppos = pposArray[i]; OctantPosition octpos = oposArray[i]; float3 overPosF = math.floor(ppos.pos / octantSize); int3 overPos = (int3)overPosF; Entity entity = pposEntityArray[i]; if (overPos.x != 0 || overPos.y != 0 || overPos.z != 0) { octpos.pos += overPos; float3 offsetAmt = overPosF * octantSize; ppos = new PrecisePosition { pos = ppos.pos - offsetAmt }; EntityManager.SetComponentData(entity, octpos); EntityManager.SetComponentData(entity, ppos); } if (EntityManager.HasComponent <HyperdistantMarker>(entity)) { float3 octOffset = octpos.pos - localOctant; posArray[i] = new Position { Value = camPos.pos + octOffset + (ppos.pos - camPos.pos) / octantSize }; } else { float3 octOffset = octpos.pos - localOctant; posArray[i] = new Position { Value = ppos.pos + octOffset * octantSize }; } } //ComponentGroup camGroup = GetComponentGroup(typeof(Position), typeof(Flycam)); // //EntityArray entityArray = camGroup.GetEntityArray(); //Entity camEntity = entityArray[0]; // //ComponentDataArray<Position> cposArray = camGroup.GetComponentDataArray<Position>(); //Position camPos = cposArray[0]; // //float3 overPosF = math.floor(camPos.Value / octantSize); //int3 overPos = (int3)overPosF; // //if(overPos.x != 0 || overPos.y != 0 || overPos.z != 0) //{ // OctantPosition octpos; // // if (EntityManager.HasComponent<OctantPosition>(camEntity)) // { // octpos = EntityManager.GetComponentData<OctantPosition>(camEntity); // } // else // { // octpos = new OctantPosition(); // EntityManager.AddComponentData(camEntity, octpos); // } // // octpos.pos += overPos; // float3 offsetAmt = overPosF * octantSize; // camPos = new Position { Value = camPos.Value - offsetAmt }; // // EntityManager.SetComponentData(camEntity, octpos); // EntityManager.SetComponentData(camEntity, camPos); // // Debug.Log("POS:" + camPos.Value + " OCTPOS:" + octpos.pos); // // // // ComponentGroup hyperposGroup = GetComponentGroup(typeof(Position), typeof(PrecisePosition)); // ComponentDataArray<Position> posArray = hyperposGroup.GetComponentDataArray<Position>(); // // for(int i = 0; i < posArray.Length; ++i) // { // posArray[i] = new Position { Value = posArray[i].Value - offsetAmt }; // } //} // // // //ComponentGroup hyperdistGroup = GetComponentGroup(typeof(Position), typeof(HyperdistantMarker)); //ComponentDataArray<Position> hdposArray = hyperdistGroup.GetComponentDataArray<Position>(); //ComponentDataArray<HyperdistantMarker> hyperdistArray = hyperdistGroup.GetComponentDataArray<HyperdistantMarker>(); // //for(int i = 0; i < hdposArray.Length; ++i) //{ // hdposArray[i] = new Position { Value = camPos.Value + (hyperdistArray[i].precisePos - camPos.Value) / octantSize }; //} }
public OrbitPoint(PrecisePosition position, double velocity) { this.position = position; this.velocity = velocity; }