public static void SphereOverlapAll(EntityManager entityManager, ref NativeList <Entity> hitColliHistoryEntityArray, int tick, int mask, Entity forceExcluded, Entity forceIncluded, sphere sphere, List <HitCollisionData.CollisionResult> results, List <Entity> hitCollisionOwners) { for (var i = 0; i < hitColliHistoryEntityArray.Length; i++) { var entity = hitColliHistoryEntityArray[i]; if (!HitCollisionData.IsRelevant(entityManager, hitColliHistoryEntityArray[i], mask, forceExcluded, forceIncluded)) { continue; } var collectionResult = new HitCollisionData.CollisionResult(); var hit = HitCollisionData.SphereOverlapSingle(entityManager, entity, tick, sphere, ref collectionResult); if (hit) { var hitCollisionData = entityManager.GetComponentData <HitCollisionData>(hitColliHistoryEntityArray[i]); results.Add(collectionResult); hitCollisionOwners.Add(hitCollisionData.hitCollisionOwner); } } }
public static bool RayCast(sphere sphere, ray ray, float rayDist, float rayRadius) { var rayEnd = ray.origin + ray.direction * rayDist; var closestPointOnRay = ClosestPointOnLineSegment(ray.origin, rayEnd, sphere.center); var dist = distance(closestPointOnRay, sphere.center); return(dist < rayRadius + sphere.radius); }
public override void OnInspectorGUI() { sphere sphere = (sphere)target; GUILayout.Label("Oscillates around a base size."); sphere.baseSize = EditorGUILayout.Slider("Size", sphere.baseSize, .1f, 2f); sphere.transform.localScale = Vector3.one * sphere.baseSize; }
public void check_sphere_collision(sphere s) { for (int x = 0; x < x_node_count; x++) { for (int y = 0; y < y_node_count; y++) { s.node_hit_test(grid[x, y]); } } }
public static Hitable moving_obj() { var s1 = new sphere(new Vector3(0, -1000f, 0f), 1000f, new lambertMaterial(new Vector3(0.5f, 0.5f, 0.5f))); var s2 = new sphere(new Vector3(-1f, 1f, 0f), 1f, new lambertMaterial(new Vector3(0.4f, 0.2f, 0.1f))); var s3 = new moving_sphere(new Vector3(0f, 1f, 0f), new Vector3(0.5f, 1f, 0f), 0f, 1f, 1f, new lambertMaterial(new Vector3(0.4f, 0.8f, 0.1f))); return(new hitable_list(new List <Hitable>() { s1, s2, s3 })); }
void createSpheres() { List <sphere> sp = new List <sphere>(); for (int i = 0; i < numSpheres; i++) { sphere s = new sphere(); s.radius = sphereRadius + Random.Range(1 - sphereRadius, sphereRadius * 0.5f); Vector2 randomPos = Random.insideUnitCircle * placementRadius; s.center = new Vector3(randomPos.x, s.radius, randomPos.y); Color c = Random.ColorHSV(); s.color = new Vector3(c.r, c.g, c.b); sp.Add(s); } sphereBuffer = new ComputeBuffer(sp.Count, sizeof(float) * 7); sphereBuffer.SetData(sp); }
void createSpheres() { List <sphere> sp = new List <sphere>(); for (int i = 0; i < numSpheres; i++) { sphere s = new sphere(); s.radius = sphereRadius + Random.Range(1 - sphereRadius, sphereRadius * 0.5f); s.center = new Vector3(Random.Range(-placementRadius, placementRadius), Random.Range(-placementRadius, placementRadius), Random.Range(0, placementRadius / 10)); Color c = Random.ColorHSV(); s.color = new Vector3(c.r, c.g, c.b); sp.Add(s); } sphereBuffer = new ComputeBuffer(sp.Count, sizeof(float) * 7); sphereBuffer.SetData(sp); }
public static void PrepareColliders(ref ComponentArray <HitCollisionHistory> collections, int tick, int mask, Entity forceExcluded, Entity forceIncluded, sphere sphere) { Profiler.BeginSample("HitCollisionHistory.PrepareColliders [Sphere]"); for (var i = 0; i < collections.Length; i++) { var collection = collections[i]; if (!IsRelevant(collection, mask, forceExcluded, forceIncluded)) { collection.DisableHitCollision(); continue; } var stateIndex = collection.GetStateIndex(tick); var boundsCenter = collection.boundsCenterBuffer[stateIndex]; var boundsRadius = collection.settings.boundsRadius; var dist = math.distance(sphere.center, boundsCenter); var boundsHit = dist < sphere.radius + boundsRadius; if (boundsHit) { collection.EnableCollisionForIndex(stateIndex); } else { collection.DisableHitCollision(); } if (HitCollisionModule.ShowDebug.IntValue > 0) { DebugPrimitiveModule.ClearChannel(HitCollisionModule.PrimDebugChannel); DebugPrimitiveModule.CreateSpherePrimitive(HitCollisionModule.PrimDebugChannel, sphere.center, sphere.radius, Color.yellow, 5); DebugPrimitiveModule.CreateSpherePrimitive(HitCollisionModule.PrimDebugChannel, boundsCenter, boundsRadius, boundsHit ? Color.yellow : Color.gray, 5); } } Profiler.EndSample(); }
public void run() { while (true) { int count1 = twodimlist.Count; int count2 = threedimlist.Count; Console.WriteLine("\n\nTwoDim Shape : " + count1); Console.WriteLine("ThreeDim Shape : " + count2); Console.WriteLine("input len and shape"); int Len = 0; try { Len = Int32.Parse(Console.ReadLine()); } catch (FormatException ex1) { Console.WriteLine(ex1.Message); continue; } if (Len == 0) { break; } string shape = Console.ReadLine(); int num = 0; foreach (var i in twodimlist) { if (i.name == shape && i.len == Len) { Console.WriteLine("이미 존재함"); num = 1; break; } } foreach (var i in threedimlist) { if (i.name == shape && i.len == Len) { Console.WriteLine("이미 존재함"); num = 1; break; } } if (num == 1) { continue; } if (shape == "정삼각형") { TwoDim Triangle = new triangle(); Triangle.name = shape; Triangle.len = Len; Triangle.Calarea(); Triangle.Calperimeter(); Triangle.print(Triangle.Area, Triangle.perimeter); twodimlist.Add(Triangle); } else if (shape == "정사각형") { TwoDim Square = new square(); Square.name = shape; Square.len = Len; Square.Calarea(); Square.Calperimeter(); Square.print(Square.Area, Square.perimeter); twodimlist.Add(Square); } else if (shape == "원") { TwoDim Circle = new circle(); Circle.name = shape; Circle.len = Len; Circle.Calarea(); Circle.Calperimeter(); Circle.print(Circle.Area, Circle.perimeter); twodimlist.Add(Circle); } else if (shape == "구") { ThreeDim Sphere = new sphere(); Sphere.name = shape; Sphere.len = Len; Sphere.Calarea(); Sphere.Calvolume(); Sphere.print(Sphere.Area, Sphere.volume); threedimlist.Add(Sphere); } else if (shape == "정육면체") { ThreeDim Cube = new cube(); Cube.name = shape; Cube.len = Len; Cube.Calarea(); Cube.Calvolume(); Cube.print(Cube.Area, Cube.volume); threedimlist.Add(Cube); } else { Console.WriteLine("Wrong input"); } } }
/* setInfo() * Input: none * Output: none * Parses the input file and edits the background, picture size, and spheres accordingly. */ void setInfo() { using (StreamReader sr = new StreamReader("Output.ppm")) { sphereList.Clear(); string line; while ((line = sr.ReadLine()) != null) { line = line.Replace("−", "-"); string[] newLine = line.Split(new [] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (newLine [0] == "screen") { row = int.Parse(newLine[1]); col = int.Parse(newLine [2]); myPicture = new Texture2D((int)(row), (int)(col)); } else if (newLine [0] == "background") { float r = float.Parse(newLine [1]); float g = float.Parse(newLine [2]); float b = float.Parse(newLine [3]); for (int x = 0; x < myPicture.width; x++) { for (int y = 0; y < myPicture.height; y++) { c = new Color(r, g, b); myPicture.SetPixel(x, y, c); } } myPicture.Apply(); } else //newLine[0] == "sphere" { float rad = int.Parse(newLine [1]); float x = int.Parse(newLine [2]); float y = int.Parse(newLine [3]); float z = (int.Parse(newLine [4])); float r = int.Parse(newLine [5]); float g = int.Parse(newLine [6]); float b = int.Parse(newLine [7]); sphere newSphere = new sphere(rad, x, y, z, r, g, b); sphereList.Add(newSphere); } } for (int x = 0; x < sphereList.Count; x++) //sorts sphereList from smallest z value to largest { for (int y = 0; y < sphereList.Count - 1; y++) { if (sphereList [y].zCor > sphereList [y + 1].zCor) { sphere temp = sphereList [y + 1]; sphereList [y + 1] = sphereList [y]; sphereList [y] = temp; } } } } RayTraceImage(); }
public static bool SphereOverlapSingle(EntityManager entityManager, Entity entity, int tick, sphere sphere, ref CollisionResult result) { var collData = entityManager.GetComponentData <HitCollisionData>(entity); var histIndex = collData.GetHistoryIndex(tick); var transformBuffer = entityManager.GetBuffer <TransformHistory>(entity); var sphereArray = entityManager.GetBuffer <Sphere>(entity); var capsuleArray = entityManager.GetBuffer <Capsule>(entity); var boxArray = entityManager.GetBuffer <Box>(entity); var resultArray = new NativeArray <CollisionResult>(1, Allocator.TempJob); var job = new SphereOverlapJob { transformBuffer = new NativeSlice <TransformHistory>(transformBuffer.AsNativeArray(), histIndex * k_maxColliderCount), sphereArray = sphereArray.AsNativeArray(), capsuleArray = capsuleArray.AsNativeArray(), boxArray = boxArray.AsNativeArray(), sphere = sphere, result = resultArray, }; var handle = job.Schedule(); handle.Complete(); result = resultArray[0]; if (math.length(result.box.size) > 0) { DebugDraw.Prim(result.box, Color.red, 1); } if (result.capsule.radius > 0) { DebugDraw.Prim(result.capsule, Color.red, 1); } if (result.sphere.radius > 0) { DebugDraw.Prim(result.sphere, Color.red, 1); } resultArray.Dispose(); return(result.hit == 1); }
public static extern bool ColBetweenSpheres(ref sphere S1, ref sphere S2);
protected override void OnUpdate() { var requestEntityArray = RequestGroup.GetEntityArray(); var requestArray = RequestGroup.GetComponentDataArray <SplashDamageRequest>(); var hitCollisionEntityArray = ColliderGroup.GetEntityArray(); var requstCount = requestArray.Length; // Broad phase hit collision check var entityArray = new NativeArray <Entity>(hitCollisionEntityArray.Length, Allocator.TempJob); var boundsArray = new NativeArray <sphere> [requstCount]; var broadPhaseResultArray = new NativeList <Entity> [requstCount]; var broadPhaseHandleArray = new NativeArray <JobHandle>(requstCount, Allocator.Temp); // TODO (mogensh) find faster/easier way to copy entityarray to native for (int i = 0; i < hitCollisionEntityArray.Length; i++) { entityArray[i] = hitCollisionEntityArray[i]; } for (var i = 0; i < requstCount; i++) { boundsArray[i] = new NativeArray <sphere>(hitCollisionEntityArray.Length, Allocator.TempJob); broadPhaseResultArray[i] = new NativeList <Entity>(hitCollisionEntityArray.Length, Allocator.TempJob); } for (int i = 0; i < requstCount; i++) { GetBounds(EntityManager, entityArray, requestArray[i].tick, ref boundsArray[i]); } for (int i = 0; i < requstCount; i++) { var request = requestArray[i]; var broadPhaseJob = new BroadPhaseSphereOverlapJob { entities = entityArray, bounds = boundsArray[i], sphere = new sphere(request.center, request.settings.radius), result = broadPhaseResultArray[i], }; broadPhaseHandleArray[i] = broadPhaseJob.Schedule(); } var broadPhaseHandle = JobHandle.CombineDependencies(broadPhaseHandleArray); broadPhaseHandle.Complete(); for (var i = 0; i < requestArray.Length; i++) { var request = requestArray[i]; // HitCollision damage { var requestSphere = new sphere(request.center, request.settings.radius); var broadPhaseResult = broadPhaseResultArray[i]; var forceIncluded = request.settings.ownerDamageFraction > 0 ? request.instigator : Entity.Null; m_resultsBuffer.Clear(); m_resultsOwnerBuffer.Clear(); SphereOverlapAll(EntityManager, ref broadPhaseResult, request.tick, request.collisionMask, Entity.Null, forceIncluded, requestSphere, m_resultsBuffer, m_resultsOwnerBuffer); for (int j = 0; j < m_resultsBuffer.Count; j++) { Damage(request.center, ref request.settings, request.instigator, m_resultsOwnerBuffer[j], m_resultsBuffer[j].primCenter); } } // Environment damage { var hitColliderMask = 1 << m_hitCollisionLayer; var count = Physics.OverlapSphereNonAlloc(request.center, request.settings.radius, g_colliderBuffer, hitColliderMask); var colliderCollections = new Dictionary <Entity, ClosestCollision>(); GetClosestCollision(g_colliderBuffer, count, request.center, colliderCollections); foreach (var collision in colliderCollections.Values) { var collisionOwnerEntity = collision.hitCollision.owner; Damage(request.center, ref request.settings, request.instigator, collisionOwnerEntity, collision.closestPoint); } } PostUpdateCommands.DestroyEntity(requestEntityArray[i]); } broadPhaseHandleArray.Dispose(); entityArray.Dispose(); for (var i = 0; i < requstCount; i++) { boundsArray[i].Dispose(); broadPhaseResultArray[i].Dispose(); } }
IcoSphere(sphere sphere) : base(sphere.points.ToArray(), sphere.faces.ToArray()) { }
private void Awake() { currentHealth = startHealth; sphere = this.GetComponent <sphere>(); }
public static void Prim(sphere sphere, Color color, float duration = 0) { Sphere(sphere.center, sphere.radius, color, duration); }
public static void Setup(EntityManager entityManager, Entity entity, List <Transform> parents, float boundsRadius, float boundsHeightOffset, List <CapsuleCollider> capsuleColliders, List <Transform> capsuleColliderParents, List <SphereCollider> sphereColliders, List <Transform> sphereColliderParents, List <BoxCollider> boxColliders, List <Transform> boxColliderParents) { var coll = new HitCollisionData(); if (entityManager.HasComponent <HitCollisionData>(entity)) { coll = entityManager.GetComponentData <HitCollisionData>(entity); } coll.lastTick = -1; coll.lastIndex = -1; coll.boundsRadius = boundsRadius; coll.boundsHeightOffset = boundsHeightOffset; if (entityManager.HasComponent <HitCollisionData>(entity)) { entityManager.SetComponentData(entity, coll); } else { entityManager.AddComponentData(entity, coll); } // Setup history entityManager.AddBuffer <TransformHistory>(entity); var historyBuffer = entityManager.GetBuffer <TransformHistory>(entity); for (int i = 0; i < k_historyCount * k_maxColliderCount; i++) { historyBuffer.Add(new TransformHistory()); } entityManager.AddBuffer <BoundsHistory>(entity); var boundsBuffer = entityManager.GetBuffer <BoundsHistory>(entity); for (int i = 0; i < k_historyCount; i++) { boundsBuffer.Add(new BoundsHistory()); } // Primitives entityManager.AddBuffer <Capsule>(entity); var capsuleBuffer = entityManager.GetBuffer <Capsule>(entity); for (var i = 0; i < capsuleColliders.Count; i++) { var collider = capsuleColliders[i]; var localPos = collider.center; var axis = collider.direction == 0 ? Vector3.right : collider.direction == 1 ? Vector3.up : Vector3.forward; var offset = 0.5f * axis * (collider.height - 2 * collider.radius); var prim = new capsule() { p1 = localPos - offset, p2 = localPos + offset, radius = collider.radius, }; var capsule = new Capsule(); capsule.prim = primlib.transform(prim, collider.transform.localPosition, collider.transform.localRotation); var parent = capsuleColliderParents[i]; capsule.transformIndex = parents.IndexOf(parent); capsule.info = new HitCollInfo { type = HitCollType.Body }; capsuleBuffer.Add(capsule); } entityManager.AddBuffer <Box>(entity); var boxBuffer = entityManager.GetBuffer <Box>(entity); for (var i = 0; i < boxColliders.Count; i++) { var collider = boxColliders[i]; var prim = new box { center = collider.center, size = collider.size, rotation = Quaternion.identity }; var box = new Box(); box.prim = primlib.transform(prim, collider.transform.localPosition, collider.transform.localRotation); var parent = boxColliderParents[i]; box.transformIndex = parents.IndexOf(parent); box.info = new HitCollInfo { type = HitCollType.Body }; boxBuffer.Add(box); } entityManager.AddBuffer <Sphere>(entity); var sphereBuffer = entityManager.GetBuffer <Sphere>(entity); for (var i = 0; i < sphereColliders.Count; i++) { var collider = sphereColliders[i]; var prim = new sphere { center = collider.center, radius = collider.radius, }; var sphere = new Sphere(); sphere.prim = primlib.transform(prim, collider.transform.localPosition, collider.transform.localRotation); var parent = sphereColliderParents[i]; sphere.transformIndex = parents.IndexOf(parent); sphere.info = new HitCollInfo { type = HitCollType.Body }; sphereBuffer.Add(sphere); } }
public void attachPlayer(sphere player) { this.player = player; }
public void Create3D(Viewport3D vp) { this.vp = vp; vp.IsHitTestVisible = false; vp.ClipToBounds = false; RenderOptions.SetEdgeMode(vp, EdgeMode.Aliased); things3d = new List <Thing3D>(); things3d.Add(new Thing3D("directional light", new DirectionalLight(Colors.White, new Vector3D(1.1, -1.1, -1.1)))); things3d.Add(new Thing3D("directional light", new DirectionalLight(Colors.White, new Vector3D(-1.1, 0.1, 1.1)))); things3d.Add(new Thing3D("directional light", new DirectionalLight(Colors.White, new Vector3D(1.1, 0.1, -1.1)))); things3d.Add(new Thing3D("directional light", new DirectionalLight(Colors.White, new Vector3D(-1, 0, -1)))); things3d.Add(new Thing3D("directional light", new AmbientLight(Color.FromRgb(55, 55, 55)))); /* [ m11 m12 m13 m14 ] * [ m21 m22 m23 m24 ] * [ m31 m32 m33 m34 ] * [ offsetX offsetY offsetZ m44 ] */ MatrixCamera matrix_camera = new MatrixCamera(); view_matrix = Matrix3D.Parse("0.539750657951516,0.559641738748834,-0.62886433472657,0,7.37257477290143E-18,0.747025071240996,0.66479586561394,0,0.841824938595261,-0.358824005868569,0.403207273708604,0,264.62356046239,-435.674414360455,-1350.56665818377,1"); vp.Camera = new MatrixCamera(view_matrix, perspective_matrix); update_perspective_matrix(); vp.SizeChanged += new SizeChangedEventHandler(vp_SizeChanged); my_node_grid = new node_grid(new Point3D(0, 1500, 0), 500, 500, 20, 20, 1, 5000000, 1500, 2500000, 1000, 3000000, 1000); // MINIMUM AXIAL VERTEX DENSITY ~= 500 / 20 = 25 units / node_count my_box = new box(new Point3D(0, 300, 1000), 200, 100, 50, .3, 0.01); my_box2 = new box(new Point3D(0, 300, -400), 150, 20, 100, .3, 0.01); // my_sphere = new sphere(new Point3D(300, 200, 0), 100, 40, 20, 5.0, 0.01, mg); my_sphere = new sphere(new Point3D(000, 500, 02), 200, 40, 20, 10.0, .01, new DiffuseMaterial(MakeSphereGrid())); ModelVisual3D mv3d2 = new ModelVisual3D(); mv3d2.Content = my_sphere.all_models; vp.Children.Add(mv3d2); //things3d.Add(); things3d.Add(new Thing3D("box", my_box.model)); things3d.Add(new Thing3D("box", my_box2.model)); things3d.Add(new Thing3D("mesh", my_node_grid.model)); int x = -750; things3d.Add(new Thing3D("floor", GenerateFloorMesh(MakeGrid(), x))); for (int n = 0; n < things3d.Count; n++) { ModelVisual3D mv3d = new ModelVisual3D(); mv3d.Content = things3d[n].model; vp.Children.Add(mv3d); } CompositionTarget.Rendering += new EventHandler(Update); }