public AABB EncapsulatingAABB(TransformComponent transform) { AABB result = AABB.Empty(); switch (Shape) { case RyneCollisionShape.CollisionShapeAABB: result = ExtractAABB(transform); break; case RyneCollisionShape.CollisionShapeSphere: Sphere sphere = ExtractSphere(transform); result.Min = new Float4(sphere.Position - new Float3(sphere.Radius), 0.0f); result.Max = new Float4(sphere.Position + new Float3(sphere.Radius), 0.0f); break; case RyneCollisionShape.CollisionShapeCube: Cube cube = ExtractCube(transform); foreach (var vertex in cube.GetVertices()) { result.Min = RyneMath.Min(result.Min, new Float4(vertex)); result.Max = RyneMath.Max(result.Max, new Float4(vertex)); } break; default: Logger.Error("EncapsulatingAABB for unsupported shape"); break; } return(result); }
public override unsafe void RenderGui(ImGuiWrapper gui) { base.RenderGui(gui); if (gui is SceneEditorGui sceneGui) { var color = Color; if (gui.InputFloat3("Color", &color)) { Color = RyneMath.Max(color, new Float3(0.01f)); Changed = true; } var intensity = Intensity; if (gui.InputFloat("Intensity", ref intensity)) { Intensity = System.Math.Max(intensity, 0.01f); Changed = true; } } if (Changed) { Global.StateManager.GetCurrentState().SceneRenderData.UpdateLight(ToRenderLight(), RenderId); Changed = false; } }
public override void UpdateEntities(float dt) { if (!base.Changed()) { return; } MovedMouseSinceStart = true; EditMovementDelta += MovementRawDelta * dt; EditRotationDelta += RotationDelta * dt; EditScaleDelta += ScaleDelta * dt; for (var i = 0; i < ControlledEntities.Count; i++) { var entity = ControlledEntities[i]; var startingTransform = StartingTransforms[i]; if (RotationDelta.Length() > Constants.Epsilon) { var rotation = startingTransform.Rotation.ToRotator().ToFloat4() + EditRotationDelta;//transform.Rotation.ToRotator().ToFloat4(); if (AngleAlignment > 0) { rotation -= RyneMath.Mod(rotation, new Float4(AngleAlignment)); } entity.Transform.Rotation = new Rotator(rotation).ToQuaternion(); if (SharedPivotRotationMode) { var vector = startingTransform.GetLocation() - SharedPivot; // Unrotate with starting rotation vector = startingTransform.Rotation.Inverse().RotateVector(vector); // Rotate to new rotation vector = entity.Transform.Rotation.RotateVector(vector); entity.Transform.SetLocation(SharedPivot + vector); } } if (MovementRawDelta.Length() > Constants.Epsilon) { var position = startingTransform.Position + EditMovementDelta; if (GridAlignment > 0) { position -= RyneMath.Mod(position, new Float4(GridAlignment)); } entity.Transform.Position = position; } if (ScaleDelta.Length() > Constants.Epsilon) { var scale = startingTransform.Scale + EditScaleDelta; if (ScaleAlignment > 0) { scale -= RyneMath.Mod(scale, new Float4(ScaleAlignment)); } entity.Transform.Scale = scale; } } OnEntitiesChanged?.Invoke(); }
public override void Update(float dt) { // TODO: only handle entities with id > own id? foreach (var entity in GetEntitiesWithMask()) { if (entity.Collision.Static) { continue; } ref var transform = ref entity.Transform; // If moved, collision detect/resolve if ((transform.Position - transform.PreviousPosition).Length() > Constants.Epsilon) { ref var collision = ref entity.Collision; // Query StaticBVH var overlappingIds = Global.EntityManager.CollisionBvh.Query(transform, collision); // For each id: Collision resolve foreach (var id in overlappingIds) { if (id == entity.EntityId) { continue; } var otherEntity = Global.EntityManager.Entities[id]; var collisionData = CheckIntersection(entity, otherEntity); if (collisionData.Intersecting) { //if (!entity.Collision.Static) //{ // Move mesh back out of the static mesh transform.Position += new Float4(collisionData.Normal * collisionData.Depth); // Remove velocity in the direction of the collision normal ref var physicsComponent = ref entity.Physics; var counterVelocity = RyneMath.Project(physicsComponent.Velocity, new Float4(collisionData.Normal)); physicsComponent.Velocity -= counterVelocity; //} var collisionEvent = new CollisionEvent(entity.EntityId, id, collisionData); Events.PushEvent(collisionEvent); } }
public override void Update(float dt) { PlayerController.Update(dt); if (PlayerController.Changed()) { var rotation = PlayerCamera.GetRotation(); rotation += new Float3(PlayerController.RotationDelta) * dt; float rotationY = RyneMath.Clamp(rotation.Y, -89.0f, 89.0f); PlayerCamera.SetRotation(new Float3(rotation.X, rotationY, 0)); // We only want the player entity to rotate horizontally Transform.Rotation = new Rotator(new Float3(rotation.X, 0, 0)).ToQuaternion(); } PlayerCamera.SetPosition(Transform.GetLocation()); PlayerCamera.Update(dt); }
public virtual void UpdateEntities(float dt) { if (!Changed()) { return; } foreach (var entity in ControlledEntities) { // Update entity transform ref var transform = ref entity.Transform; if (RotationDelta.Length() > Constants.Epsilon) { var rotation = transform.Rotation.ToRotator().ToFloat4(); rotation += RotationDelta * dt; if (ClampVerticalRotation) { rotation.Y = RyneMath.Clamp(rotation.Y, -89.0f, 89.0f); } transform.Rotation = new Rotator(rotation).ToQuaternion(); } if (MovementRawDelta.Length() > Constants.Epsilon) { if (AddMovementAsForce) { ref var physics = ref entity.Physics; physics.Acceleration += MovementNormalizedDelta * dt; physics.Velocity += MovementDirectDelta * dt; } else { transform.Position += MovementRawDelta * dt; } }
public Quaternion GetQuaternion(float sizeMultiplier) { return(new Quaternion(new Float3(GetDirection()), RyneMath.DegreesToRadians(Length) * sizeMultiplier)); }
public void Expand(Float4 position) { Max = RyneMath.Max(Max, position); Min = RyneMath.Min(Min, position); }
public void Expand(AABB bounds) { Max = RyneMath.Max(Max, bounds.Max); Min = RyneMath.Min(Min, bounds.Min); }