void initSceneObstacles() { GameConst.sceneObstacles = new AABBox[GameConst.height, GameConst.width]; foreach (Transform obstacleLayer in GameConst.obstacleLayers) { foreach (Transform obstacle in obstacleLayer) { AABBox box = obstacle.gameObject.GetComponent <AABBox>(); int col = (int)box.Center.x / GameConst.tileWidth; int row = (int)-box.Center.y / GameConst.tileHeight; GameConst.sceneObstacles[row, col] = box; } } foreach (Transform staticLayer in GameConst.staticLayers) { foreach (Transform staticOb in staticLayer) { if (staticOb.name == "Collision") { AABBox[] aabboxs = staticOb.gameObject.GetComponents <AABBox>(); foreach (AABBox box in aabboxs) { int col = (int)box.Center.x / GameConst.tileWidth; int row = (int)-box.Center.y / GameConst.tileHeight; GameConst.sceneObstacles[row, col] = box; } } } } }
public void RepositionAtCursor() { Vector3 vector3 = UICamera.lastMousePosition; Ray ray = this.uiCamera.ScreenPointToRay(vector3); float single = 0f; if (this.planeTest.Raycast(ray, out single)) { base.transform.position = ray.GetPoint(single); AABBox aABBox = NGUIMath.CalculateRelativeWidgetBounds(base.transform); float single1 = base.transform.localPosition.x; Vector3 vector31 = aABBox.size; float single2 = single1 + vector31.x - (float)Screen.width; if (single2 > 0f) { Transform transforms = base.transform; Vector3 vector32 = base.transform.localPosition; transforms.SetLocalPositionX(vector32.x - single2); } float single3 = base.transform.localPosition.y; Vector3 vector33 = aABBox.size; float single4 = single3 + vector33.y - (float)Screen.height; if (single4 > 0f) { Transform transforms1 = base.transform; Vector3 vector34 = base.transform.localPosition; transforms1.SetLocalPositionY(vector34.y - single4); } Transform transforms2 = base.transform; float single5 = base.transform.localPosition.x; Vector3 vector35 = base.transform.localPosition; transforms2.localPosition = new Vector3(single5, vector35.y, -180f); } }
public static BoxCollider AddWidgetCollider(GameObject go) { if (go == null) { return(null); } Collider component = go.GetComponent <Collider>(); BoxCollider collider2 = component as BoxCollider; if (collider2 == null) { if (component != null) { if (Application.isPlaying) { UnityEngine.Object.Destroy(component); } else { UnityEngine.Object.DestroyImmediate(component); } } collider2 = go.AddComponent <BoxCollider>(); } int num = CalculateNextDepth(go); AABBox box = NGUIMath.CalculateRelativeWidgetBounds(go.transform); collider2.isTrigger = true; collider2.center = box.center + ((Vector3)(Vector3.back * (num * 0.25f))); collider2.size = new Vector3(box.size.x, box.size.y, 0f); return(collider2); }
void NormalUpdateBoxTransform(int row, int col, Vector2 direct) { AABBox box = getGridBox(row, col); if (box == null) { return; } if (box.BoxInline(colliderBox)) { if (direction == PopDirection.HORIZONTAL) { offsetX(colliderBox, box, direct); if (box.BoxInline(colliderBox)) { offsetY(colliderBox, box, direct); } } else { offsetY(colliderBox, box, direct); if (box.BoxInline(colliderBox)) { offsetX(colliderBox, box, direct); } } } }
public bool ConstrainTargetToBounds(Transform target, ref AABBox targetBounds, bool immediate) { Vector3 vector = this.CalculateConstrainOffset(targetBounds.min, targetBounds.max); if (vector.magnitude <= 0f) { return(false); } if (immediate) { target.localPosition += vector; targetBounds.center += vector; SpringPosition component = target.GetComponent <SpringPosition>(); if (component != null) { component.enabled = false; } } else { SpringPosition position2 = SpringPosition.Begin(target.gameObject, target.localPosition + vector, 13f); position2.ignoreTimeScale = true; position2.worldSpace = false; } return(true); }
private void Update() { float deltaTime = base.UpdateRealTimeDelta(); if (this.mPressed) { SpringPosition component = base.GetComponent <SpringPosition>(); if (component != null) { component.enabled = false; } this.mScroll = 0f; } else { this.mMomentum += (Vector2)(this.scale * (this.mScroll * 20f)); this.mScroll = NGUIMath.SpringLerp(this.mScroll, 0f, 20f, deltaTime); if (this.mMomentum.magnitude > 0.01f) { this.mTrans.localPosition += NGUIMath.SpringDampen(ref this.mMomentum, 9f, deltaTime); this.mBounds = NGUIMath.CalculateAbsoluteWidgetBounds(this.rootForBounds); if (!this.ConstrainToBounds(this.dragEffect == UIDragObject.DragEffect.None)) { SpringPosition position2 = base.GetComponent <SpringPosition>(); if (position2 != null) { position2.enabled = false; } } return; } this.mScroll = 0f; } NGUIMath.SpringDampen(ref this.mMomentum, 9f, deltaTime); }
void RollBackPosition() { int maxCount = Mathf.Max(GameConst.width, GameConst.height); while (maxCount > 0) { maxCount--; int row = (int)getCurrentGridPos().y; int col = (int)getCurrentGridPos().x; Vector3 offset = transform.position - prePosition; BubbleNode node = null; if (RelativeDitionary.ContainsKey(row * GameConst.width + col)) { node = RelativeDitionary[row * GameConst.width + col]; } if (GameConst.sceneObstacles[row, col] != null) { AABBox box = getGridBox(row, col); RollbackPosition(getRollBackDirection(offset), colliderBox, box); } else if (node != null && (node.bubbleRow == row && node.bubbleCol == col)) { if (node.bubbleRelative == BubbleRelative.OutLine) { AABBox box = GameConst.bubbles[row, col].GetComponent <BubbleInlineBox>(); RollbackPosition(getRollBackDirection(offset), behurtBox, box); } else if (node.bubbleRelative == BubbleRelative.OutEdge) { AABBox box = GameConst.bubbles[row, col].GetComponent <BubbleOutlineBox>(); RollbackPosition(getRollBackDirection(offset), colliderBox, box); } else { Vector2 grid = checkRoadObstacle(); if (grid.Equals(Vector2.zero)) { break; } Vector2 center = getCenter((int)grid.y, (int)grid.x); transform.position = new Vector3(center.x, center.y, transform.position.z); resetColliderBox(); resetBeHurtBox(); } } else { Vector2 grid = checkRoadObstacle(); if (grid.Equals(Vector2.zero)) { break; } Vector2 center = getCenter((int)grid.y, (int)grid.x); transform.position = new Vector3(center.x, center.y, transform.position.z); resetColliderBox(); resetBeHurtBox(); } } }
public void InitBlockTransform(Vector3 pos, int width, int height) { transform.position = pos; this.width = width; this.height = height; aabbox = GetComponent <AABBox>(); aabbox.resetAABBox(new Vector2(pos.x, pos.y), new Vector2(pos.x + width, pos.y + height)); }
// Use this for initialization void Start() { m_renderer = GetComponent <SpriteRenderer>(); fade = 1.0f; aabbox = GetComponent <AABBox>(); width = (int)aabbox.Center.x / GameConst.tileWidth; height = (int)-aabbox.Center.y / GameConst.tileHeight; }
private void OnPressForeground(GameObject go, bool isPressed) { if (isPressed) { this.mCam = UICamera.currentCamera; AABBox aABBox = NGUIMath.CalculateAbsoluteWidgetBounds(this.mFG.cachedTransform); this.mScreenPos = this.mCam.WorldToScreenPoint(aABBox.center); } }
private void LateUpdate() { float single = base.UpdateRealTimeDelta(); if (this.target == null) { return; } if (!this.mPressed) { UIDragObject uIDragObject = this; uIDragObject.mMomentum = uIDragObject.mMomentum + (this.scale * (-this.mScroll * 0.05f)); this.mScroll = NGUIMath.SpringLerp(this.mScroll, 0f, 20f, single); if (this.mMomentum.magnitude <= 0.0001f) { this.mScroll = 0f; } else { if (this.mPanel == null) { this.FindPanel(); } if (this.mPanel != null) { Transform transforms = this.target; transforms.position = transforms.position + NGUIMath.SpringDampen(ref this.mMomentum, 9f, single); if (this.restrictWithinPanel && this.mPanel.clipping != UIDrawCall.Clipping.None) { this.mBounds = NGUIMath.CalculateRelativeWidgetBounds(this.mPanel.cachedTransform, this.target); if (!this.mPanel.ConstrainTargetToBounds(this.target, ref this.mBounds, this.dragEffect == UIDragObject.DragEffect.None)) { SpringPosition component = this.target.GetComponent <SpringPosition>(); if (component != null) { component.enabled = false; } } } return; } } } else { SpringPosition springPosition = this.target.GetComponent <SpringPosition>(); if (springPosition != null) { springPosition.enabled = false; } this.mScroll = 0f; } NGUIMath.SpringDampen(ref this.mMomentum, 9f, single); }
public void offsetY(AABBox colliderBox, AABBox box, Vector2 direct) { Vector2 offset = getOffsetY(colliderBox, box, direct); if (offset != Vector2.zero) { resetTransform(offset); resetColliderBox(); resetBeHurtBox(); } }
public bool BoxInline(AABBox aabb) { if (min.x >= aabb.max.x || max.x <= aabb.min.x) { return(false); } if (min.y >= aabb.max.y || max.y <= aabb.min.y) { return(false); } return(true); }
public bool intersects(AABBox aabb) { if (min.x > aabb.max.x || max.x < aabb.min.x) { return(false); } if (min.y > aabb.max.y || max.y < aabb.min.y) { return(false); } return(true); }
// Use this for initialization void Start() { animator = GetComponent <Animator>(); animator.SetInteger("Type", (int)type); animator.SetTrigger("Change"); AABBox box = GetComponent <AABBox>(); Vector2 min = new Vector2(transform.position.x - 20, transform.position.y - 20); Vector2 max = new Vector2(transform.position.x + 20, transform.position.y + 20); box.resetAABBox(min, max); createTime = TimeUtils.GetTimeStampNow(); }
public AABBox getGridBox(int row, int col) { AABBox box = GameConst.sceneObstacles[row, col]; if (box == null) { if (GameConst.bubbles[row, col] != null) { box = GameConst.bubbles[row, col].GetComponent <BubbleOutlineBox>(); } } return(box); }
public Entity(World world, Vector3 pos, float pitch, float yaw) { this.world = world; Position = pos; this.yaw = yaw; this.pitch = pitch; BoundingBox = new AABBox(Vector3.Zero) { CenterXZ = Position }; UseGravity = true; UpdateRotation(); }
private void LateUpdate() { float deltaTime = base.UpdateRealTimeDelta(); if (this.target != null) { if (this.mPressed) { SpringPosition component = this.target.GetComponent <SpringPosition>(); if (component != null) { component.enabled = false; } this.mScroll = 0f; } else { this.mMomentum += (Vector3)(this.scale * (-this.mScroll * 0.05f)); this.mScroll = NGUIMath.SpringLerp(this.mScroll, 0f, 20f, deltaTime); if (this.mMomentum.magnitude > 0.0001f) { if (this.mPanel == null) { this.FindPanel(); } if (this.mPanel != null) { this.target.position += NGUIMath.SpringDampen(ref this.mMomentum, 9f, deltaTime); if (this.restrictWithinPanel && (this.mPanel.clipping != UIDrawCall.Clipping.None)) { this.mBounds = NGUIMath.CalculateRelativeWidgetBounds(this.mPanel.cachedTransform, this.target); if (!this.mPanel.ConstrainTargetToBounds(this.target, ref this.mBounds, this.dragEffect == DragEffect.None)) { SpringPosition position2 = this.target.GetComponent <SpringPosition>(); if (position2 != null) { position2.enabled = false; } } } return; } } else { this.mScroll = 0f; } } NGUIMath.SpringDampen(ref this.mMomentum, 9f, deltaTime); } }
public static AABBox CalculateRelativeWidgetBounds(Transform root, Transform child) { Vector2 vector2; Vector2 vector21; Vector3 vector3 = new Vector3(); Vector3 vector31 = new Vector3(); AABBox aABBox; AABBox aABBox1; using (NGUIMath.WidgetList widgetsInChildren = NGUIMath.GetWidgetsInChildren(child)) { if (!widgetsInChildren.empty) { bool flag = true; AABBox aABBox2 = new AABBox(); Matrix4x4 matrix4x4 = root.worldToLocalMatrix; foreach (UIWidget widgetsInChild in widgetsInChildren) { widgetsInChild.GetPivotOffsetAndRelativeSize(out vector21, out vector2); vector3.x = (vector21.x + 0.5f) * vector2.x; vector3.y = (vector21.x - 0.5f) * vector2.y; vector3.z = 0f; vector31.x = vector3.x + vector2.x * 0.5f; vector31.y = vector3.y + vector2.y * 0.5f; vector31.z = 0f; vector3.x = vector3.x - vector2.x * 0.5f; vector3.y = vector3.y - vector2.y * 0.5f; Matrix4x4 matrix4x41 = matrix4x4 * widgetsInChild.cachedTransform.localToWorldMatrix; AABBox aABBox3 = new AABBox(ref vector3, ref vector31); aABBox3.TransformedAABB3x4(ref matrix4x41, out aABBox); if (!flag) { aABBox2.Encapsulate(ref aABBox); } else { aABBox2 = aABBox; flag = false; } } aABBox1 = aABBox2; } else { aABBox1 = new AABBox(); } } return(aABBox1); }
public void SetDragAmount(float x, float y, bool updateScrollbars) { this.DisableSpring(); AABBox aABBox = this.bounds; if (aABBox.min.x == aABBox.max.x || aABBox.min.y == aABBox.max.x) { return; } Vector4 vector4 = this.mPanel.clipRange; float single = vector4.z * 0.5f; float single1 = vector4.w * 0.5f; float single2 = aABBox.min.x + single; float single3 = aABBox.max.x - single; float single4 = aABBox.min.y + single1; float single5 = aABBox.max.y - single1; if (this.mPanel.clipping == UIDrawCall.Clipping.SoftClip) { single2 = single2 - this.mPanel.clipSoftness.x; single3 = single3 + this.mPanel.clipSoftness.x; single4 = single4 - this.mPanel.clipSoftness.y; single5 = single5 + this.mPanel.clipSoftness.y; } float single6 = Mathf.Lerp(single2, single3, x); float single7 = Mathf.Lerp(single5, single4, y); if (!updateScrollbars) { Vector3 vector3 = this.mTrans.localPosition; if (this.scale.x != 0f) { vector3.x = vector3.x + (vector4.x - single6); } if (this.scale.y != 0f) { vector3.y = vector3.y + (vector4.y - single7); } this.mTrans.localPosition = vector3; } vector4.x = single6; vector4.y = single7; this.mPanel.clipRange = vector4; if (updateScrollbars) { this.UpdateScrollbars(false); } }
public static AABBox CalculateAbsoluteWidgetBounds(Transform trans) { Vector2 vector2; Vector2 vector21; AABBox aABBox; Vector3 vector3 = new Vector3(); Vector3 vector31 = new Vector3(); AABBox aABBox1; using (NGUIMath.WidgetList widgetsInChildren = NGUIMath.GetWidgetsInChildren(trans)) { if (!widgetsInChildren.empty) { AABBox aABBox2 = new AABBox(); bool flag = true; foreach (UIWidget widgetsInChild in widgetsInChildren) { widgetsInChild.GetPivotOffsetAndRelativeSize(out vector21, out vector2); vector3.x = (vector21.x + 0.5f) * vector2.x; vector3.y = (vector21.y - 0.5f) * vector2.y; vector31.x = vector3.x + vector2.x * 0.5f; vector31.y = vector3.y + vector2.y * 0.5f; vector3.x = vector3.x - vector2.x * 0.5f; vector3.y = vector3.y - vector2.y * 0.5f; vector3.z = 0f; vector31.z = 0f; AABBox aABBox3 = new AABBox(ref vector3, ref vector31); Matrix4x4 matrix4x4 = widgetsInChild.cachedTransform.localToWorldMatrix; aABBox3.TransformedAABB3x4(ref matrix4x4, out aABBox); if (!flag) { aABBox2.Encapsulate(ref aABBox); } else { aABBox2 = aABBox; flag = false; } } aABBox1 = (!flag ? aABBox2 : new AABBox(trans.position)); } else { aABBox1 = new AABBox(); } } return(aABBox1); }
private void SetBounds(bool moved, Bounds bounds, bool worldEquals) { if (this.configuredInLocalSpace) { if ((this._lastBoundsEntered != bounds) || !worldEquals) { this._lastBoundsEntered = bounds; AABBox.Transform3x4(ref bounds, ref this.toWorld, out this._bounds); } } else { this._lastBoundsEntered = bounds; this._bounds = bounds; } }
//如果当前的bubble跟player有关系就不关联进去 public AABBox getGridBox(int row, int col) { AABBox box = GameConst.sceneObstacles[row, col]; if (box == null) { if (!boxUpdate.ContainsInlineBubbleRelative(row, col) && !boxUpdate.ContainsOutlineBubbleRelative(row, col)) { if (GameConst.bubbles[row, col] != null) { box = GameConst.bubbles[row, col].GetComponent <BubbleOutlineBox>(); } } } return(box); }
public void updateMovement() { if (this.state == PlayerState.Movement) { Vector2 center = colliderBox.Center; int col = (int)center.x / GameConst.tileWidth; int row = (int)-center.y / GameConst.tileHeight; Vector2 GridCenter = new Vector2(col * GameConst.tileWidth + GameConst.tileWidth / 2, -(row * GameConst.tileHeight + GameConst.tileHeight / 2)); Vector2 offset = center - GridCenter; Vector2[] direct = new Vector2[2]; if (isNormalMovement(offset, ref direct, row, col)) { NormalMovement(); } else { if (!OutOfEdge(direct)) { int col1 = (int)direct[0].x + col; int row1 = (int)direct[0].y + row; int col2 = (int)direct[1].x + col; int row2 = (int)direct[1].y + row; AABBox box1 = getGridBox(row1, col1); AABBox box2 = getGridBox(row2, col2); if (box1 != null && box2 == null) { SpecialMovement(direct[1], true); } else if (box1 == null && box2 != null) { SpecialMovement(-direct[1], false); } else { NormalMovement(); } } else { //Debug.Log("Player Out Out Out Out Edge"); NormalMovement(); } } } resetPlayerZ(); }
private static UIHotSpot ColliderToHotSpot(Collider collider, bool nullChecked) { Bounds bounds; if (!nullChecked && (collider == null)) { return(null); } if (collider is BoxCollider) { return(ColliderToHotSpot((BoxCollider)collider)); } if (collider is SphereCollider) { return(ColliderToHotSpot((SphereCollider)collider)); } if (collider is TerrainCollider) { Debug.Log("Sorry not going to convert a terrain collider.. that sounds destructive.", collider); return(null); } Bounds boundsSrc = collider.bounds; Matrix4x4 worldToLocalMatrix = collider.transform.worldToLocalMatrix; AABBox.Transform3x4(ref boundsSrc, ref worldToLocalMatrix, out bounds); bool enabled = collider.enabled; GameObject gameObject = collider.gameObject; ColliderDestroy(collider); Vector3 size = bounds.size; if (size.z <= 0.001f) { UIRectHotSpot spot = gameObject.AddComponent <UIRectHotSpot>(); spot.size = size; spot.center = bounds.center; spot.enabled = enabled; return(spot); } UIBoxHotSpot spot2 = gameObject.AddComponent <UIBoxHotSpot>(); spot2.size = size; spot2.center = bounds.center; spot2.enabled = enabled; return(spot2); }
public static AABBox CalculateAbsoluteWidgetBounds(Transform trans) { using (WidgetList list = GetWidgetsInChildren(trans)) { if (list.empty) { return(new AABBox()); } AABBox box = new AABBox(); bool flag = true; foreach (UIWidget widget in list) { Vector2 vector; Vector2 vector2; AABBox box2; Vector3 vector3; Vector3 vector4; widget.GetPivotOffsetAndRelativeSize(out vector2, out vector); vector3.x = (vector2.x + 0.5f) * vector.x; vector3.y = (vector2.y - 0.5f) * vector.y; vector4.x = vector3.x + (vector.x * 0.5f); vector4.y = vector3.y + (vector.y * 0.5f); vector3.x -= vector.x * 0.5f; vector3.y -= vector.y * 0.5f; vector3.z = 0f; vector4.z = 0f; AABBox box3 = new AABBox(ref vector3, ref vector4); Matrix4x4 localToWorldMatrix = widget.cachedTransform.localToWorldMatrix; box3.TransformedAABB3x4(ref localToWorldMatrix, out box2); if (flag) { box = box2; flag = false; } else { box.Encapsulate(ref box2); } } if (flag) { return(new AABBox(trans.position)); } return(box); } }
private static UIHotSpot ColliderToHotSpot(Collider collider, bool nullChecked) { Bounds bound; if (!nullChecked && !collider) { return(null); } if (collider is BoxCollider) { return(NGUITools.ColliderToHotSpot((BoxCollider)collider)); } if (collider is SphereCollider) { return(NGUITools.ColliderToHotSpot((SphereCollider)collider)); } if (collider is TerrainCollider) { Debug.Log("Sorry not going to convert a terrain collider.. that sounds destructive.", collider); return(null); } Bounds bound1 = collider.bounds; Matrix4x4 matrix4x4 = collider.transform.worldToLocalMatrix; AABBox.Transform3x4(ref bound1, ref matrix4x4, out bound); bool flag = collider.enabled; GameObject gameObject = collider.gameObject; NGUITools.ColliderDestroy(collider); Vector3 vector3 = bound.size; if (vector3.z > 0.001f) { UIBoxHotSpot uIBoxHotSpot = gameObject.AddComponent <UIBoxHotSpot>(); uIBoxHotSpot.size = vector3; uIBoxHotSpot.center = bound.center; uIBoxHotSpot.enabled = flag; return(uIBoxHotSpot); } UIRectHotSpot uIRectHotSpot = gameObject.AddComponent <UIRectHotSpot>(); uIRectHotSpot.size = vector3; uIRectHotSpot.center = bound.center; uIRectHotSpot.enabled = flag; return(uIRectHotSpot); }
public void Draw(uint time, Vector3Df cameraPosition, AABBox cameraViewBox) { if (cameraViewBox.IsInside(d1) || cameraViewBox.IsInside(d2) || cameraViewBox.IsInside(d3) || cameraViewBox.IsInside(d4) || cameraViewBox.IsInside(d5) || cameraViewBox.IsInside(d6) || cameraViewBox.IsInside(d7) || cameraViewBox.IsInside(d8)) { for (int i = 0; i < lodItems.Count; i++) { lodItems[i].Draw(time, cameraPosition); } } }
public void SetDragAmount(float x, float y, bool updateScrollbars) { this.DisableSpring(); AABBox bounds = this.bounds; if ((bounds.min.x != bounds.max.x) && (bounds.min.y != bounds.max.x)) { Vector4 clipRange = this.mPanel.clipRange; float num = clipRange.z * 0.5f; float num2 = clipRange.w * 0.5f; float from = bounds.min.x + num; float to = bounds.max.x - num; float num5 = bounds.min.y + num2; float num6 = bounds.max.y - num2; if (this.mPanel.clipping == UIDrawCall.Clipping.SoftClip) { from -= this.mPanel.clipSoftness.x; to += this.mPanel.clipSoftness.x; num5 -= this.mPanel.clipSoftness.y; num6 += this.mPanel.clipSoftness.y; } float num7 = Mathf.Lerp(from, to, x); float num8 = Mathf.Lerp(num6, num5, y); if (!updateScrollbars) { Vector3 localPosition = this.mTrans.localPosition; if (this.scale.x != 0f) { localPosition.x += clipRange.x - num7; } if (this.scale.y != 0f) { localPosition.y += clipRange.y - num8; } this.mTrans.localPosition = localPosition; } clipRange.x = num7; clipRange.y = num8; this.mPanel.clipRange = clipRange; if (updateScrollbars) { this.UpdateScrollbars(false); } } }
public static LODSector Create(AABBox dimension) { LODSector s = new LODSector(); s.dimension = dimension; s.d1 = dimension.MinEdge; s.d2 = new Vector3Df(dimension.MinEdge.X, dimension.MinEdge.Y, dimension.MaxEdge.Z); s.d3 = new Vector3Df(dimension.MinEdge.X, dimension.MaxEdge.Y, dimension.MinEdge.Z); s.d4 = new Vector3Df(dimension.MinEdge.X, dimension.MaxEdge.Y, dimension.MaxEdge.Z); s.d5 = dimension.MaxEdge; s.d6 = new Vector3Df(dimension.MaxEdge.X, dimension.MinEdge.Y, dimension.MinEdge.Z); s.d7 = new Vector3Df(dimension.MaxEdge.X, dimension.MinEdge.Y, dimension.MaxEdge.Z); s.d8 = new Vector3Df(dimension.MaxEdge.X, dimension.MaxEdge.Y, dimension.MinEdge.Z); s.lodItems = new List <LODItem>(); return(s); }
public bool ConstrainTargetToBounds(Transform target, ref AABBox targetBounds, bool immediate) { Vector3 vector3 = this.CalculateConstrainOffset(targetBounds.min, targetBounds.max); if (vector3.magnitude <= 0f) { return false; } if (!immediate) { SpringPosition springPosition = SpringPosition.Begin(target.gameObject, target.localPosition + vector3, 13f); springPosition.ignoreTimeScale = true; springPosition.worldSpace = false; } else { Transform transforms = target; transforms.localPosition = transforms.localPosition + vector3; targetBounds.center = targetBounds.center + vector3; SpringPosition component = target.GetComponent<SpringPosition>(); if (component != null) { component.enabled = false; } } return true; }
public void Press(bool isPressed) { if (this.rootForBounds != null) { this.mPressed = isPressed; if (isPressed) { this.mBounds = NGUIMath.CalculateAbsoluteWidgetBounds(this.rootForBounds); this.mMomentum = Vector2.zero; this.mScroll = 0f; SpringPosition component = base.GetComponent<SpringPosition>(); if (component != null) { component.enabled = false; } } else if (this.dragEffect == UIDragObject.DragEffect.MomentumAndSpring) { this.ConstrainToBounds(false); } } }
private void Update() { float single = base.UpdateRealTimeDelta(); if (!this.mPressed) { UIDraggableCamera uIDraggableCamera = this; uIDraggableCamera.mMomentum = uIDraggableCamera.mMomentum + (this.scale * (this.mScroll * 20f)); this.mScroll = NGUIMath.SpringLerp(this.mScroll, 0f, 20f, single); if (this.mMomentum.magnitude > 0.01f) { Transform transforms = this.mTrans; transforms.localPosition = transforms.localPosition + NGUIMath.SpringDampen(ref this.mMomentum, 9f, single); this.mBounds = NGUIMath.CalculateAbsoluteWidgetBounds(this.rootForBounds); if (!this.ConstrainToBounds(this.dragEffect == UIDragObject.DragEffect.None)) { SpringPosition component = base.GetComponent<SpringPosition>(); if (component != null) { component.enabled = false; } } return; } this.mScroll = 0f; } else { SpringPosition springPosition = base.GetComponent<SpringPosition>(); if (springPosition != null) { springPosition.enabled = false; } this.mScroll = 0f; } NGUIMath.SpringDampen(ref this.mMomentum, 9f, single); }
public static LODSector Create(AABBox dimension) { LODSector s = new LODSector(); s.dimension = dimension; s.d1 = dimension.MinEdge; s.d2 = new Vector3Df(dimension.MinEdge.X, dimension.MinEdge.Y, dimension.MaxEdge.Z); s.d3 = new Vector3Df(dimension.MinEdge.X, dimension.MaxEdge.Y, dimension.MinEdge.Z); s.d4 = new Vector3Df(dimension.MinEdge.X, dimension.MaxEdge.Y, dimension.MaxEdge.Z); s.d5 = dimension.MaxEdge; s.d6 = new Vector3Df(dimension.MaxEdge.X, dimension.MinEdge.Y, dimension.MinEdge.Z); s.d7 = new Vector3Df(dimension.MaxEdge.X, dimension.MinEdge.Y, dimension.MaxEdge.Z); s.d8 = new Vector3Df(dimension.MaxEdge.X, dimension.MaxEdge.Y, dimension.MinEdge.Z); s.lodItems = new List<LODItem>(); return s; }
static void Main(string[] args) { int lodItemCount = AskUserForLODItemCount(); DriverType driverType; if (!AskUserForDriver(out driverType)) return; device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(800, 600)); if (device == null) return; device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.SetWindowCaption("Simple LOD - Irrlicht Lime"); device.CursorControl.Visible = false; VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; // generate all LODs of mesh List<Mesh> lodMesh = new List<Mesh>(); Material meshMaterial = null; List<int> lodTriangleCount = new List<int>(); int[] p = new int[] { 100, 50, 32, 20, 12, 6, 3 }; for (int i = 0; i < p.Length; i++) { Mesh m = scene.GeometryCreator.CreateSphereMesh(50, p[i], p[i]); MeshBuffer mb = m.GetMeshBuffer(0); mb.Material.Type = MaterialType.Solid; mb.Material.SetTexture(0, driver.GetTexture("../../media/earth.jpg")); m.SetMaterialFlag(MaterialFlag.Lighting, false); lodMesh.Add(m); if (meshMaterial == null) meshMaterial = m.GetMeshBuffer(0).Material; lodTriangleCount.Add(mb.IndexCount / 3); } // generate world, // we generate a lot of objects with random positions in huge virtual cube int virtualCubeSide = 20000; LODItem[] lodItems = new LODItem[lodItemCount]; Random r = new Random(12345000); for (int i = 0; i < lodItemCount; i++) { Matrix tmat = new Matrix( new Vector3Df( // translation r.Next(virtualCubeSide) - virtualCubeSide / 2, r.Next(virtualCubeSide) - virtualCubeSide / 2, r.Next(virtualCubeSide) - virtualCubeSide / 2)); Vector3Df rvect = new Vector3Df( (float)r.NextDouble() / 200.0f, (float)r.NextDouble() / 200.0f, (float)r.NextDouble() / 200.0f); lodItems[i] = LODItem.Create(device, lodMesh, tmat, rvect); } // split world on virtual sectors (cubes) for faster visibility check int lodSectorSide = 6; // total number of sectors will be lodSectorSide^3, so for 6 it is 216 int lodSectorSize = virtualCubeSide / lodSectorSide; LODSector[,,] lodSectors = new LODSector[lodSectorSide, lodSectorSide, lodSectorSide]; for (int i = 0; i < lodSectorSide; i++) { for (int j = 0; j < lodSectorSide; j++) { for (int k = 0; k < lodSectorSide; k++) { AABBox dimension = new AABBox( new Vector3Df(i * lodSectorSize, j * lodSectorSize, k * lodSectorSize), new Vector3Df((i + 1) * lodSectorSize, (j + 1) * lodSectorSize, (k + 1) * lodSectorSize)); dimension.MinEdge -= virtualCubeSide / 2; dimension.MaxEdge -= virtualCubeSide / 2; LODSector s = LODSector.Create(dimension); lodSectors[i, j, k] = s; } } } for (int i = 0; i < lodItems.Length; i++) { Vector3Df pos = lodItems[i].Position; pos += virtualCubeSide / 2; pos /= lodSectorSize; int ix = (int)pos.X; int iy = (int)pos.Y; int iz = (int)pos.Z; if (ix < 0) ix = 0; if (ix > lodSectorSide - 1) ix = lodSectorSide - 1; if (iy < 0) ix = 0; if (iy > lodSectorSide - 1) iy = lodSectorSide - 1; if (iz < 0) iz = 0; if (iz > lodSectorSide - 1) iz = lodSectorSide - 1; lodSectors[ix, iy, iz].AddLODItem(lodItems[i]); } // camera CameraSceneNode camera = scene.AddCameraSceneNodeFPS(); camera.FarValue = 30000; // font, which we are going to use to show any text we need IrrlichtLime.GUI.GUIFont font = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); // render loop while (device.Run()) { driver.BeginScene(); scene.DrawAll(); if (isLabelMode) { LODItem.LabelPositions = new List<Vector2Di>(); LODItem.LabelTexts = new List<string>(); } else { LODItem.LabelPositions = null; LODItem.LabelTexts = null; } meshMaterial.Wireframe = isWireframeMode; device.VideoDriver.SetMaterial(meshMaterial); uint timer = device.Timer.Time; Vector3Df cameraPosition = camera.AbsolutePosition; AABBox cameraViewBox = camera.ViewFrustum.BoundingBox; for (int i = 0; i < lodSectorSide; i++) { for (int j = 0; j < lodSectorSide; j++) { for (int k = 0; k < lodSectorSide; k++) { lodSectors[i, j, k].Draw(timer, cameraPosition, cameraViewBox); } } } if (isLabelMode) { for (int i = 0; i < LODItem.LabelPositions.Count; i++) { driver.Draw2DLine( LODItem.LabelPositions[i] - new Vector2Di(10, 0), LODItem.LabelPositions[i] + new Vector2Di(50, 0), Color.OpaqueGreen); driver.Draw2DLine( LODItem.LabelPositions[i] - new Vector2Di(0, 10), LODItem.LabelPositions[i] + new Vector2Di(0, 50), Color.OpaqueGreen); font.Draw(LODItem.LabelTexts[i], LODItem.LabelPositions[i], Color.OpaqueGreen); } } if (isStatsMode) { // show LOD stats int[] lodCount = new int[7] { 0, 0, 0, 0, 0, 0, 0 }; for (int i = 0; i < lodItems.Length; i++) lodCount[lodItems[i].CurrentLOD]++; string f = ""; for (int i = 0; i < lodCount.Length; i++) { int n = lodCount[i]; f += "LOD" + i.ToString() + ": " + n.ToString() + " [" + ((n * 100) / lodItemCount).ToString() + "%] objects\n"; } string l = "------------------------"; font.Draw( string.Format("Stats\n{0}\n{1}{2}\nTotal: {3} [100%] objects", l, f, l, lodItemCount), new Vector2Di(10, 140), Color.OpaqueMagenta); } // show general stats font.Draw(string.Format( "Camera position: {0}\nTotal LOD 0 triangles: {1}\nTriangles currently drawn: {2}\nDriver: {3}\nFPS: {4}", camera.AbsolutePosition, lodTriangleCount[0] * lodItemCount, driver.PrimitiveCountDrawn, driver.Name, driver.FPS), 10, 10, Color.OpaqueYellow); // show active keys font.Draw( "[S] Toggle stats\n[W] Toggle wireframe\n[L] Toggle labels (only for LODs from 0 to 4)\n[Esc] Exit application", 10, driver.ScreenSize.Height - 80, Color.OpaqueCyan); driver.EndScene(); } // drop device.Drop(); }
private void LateUpdate() { float single = base.UpdateRealTimeDelta(); if (this.target == null) { return; } if (!this.mPressed) { UIDragObject uIDragObject = this; uIDragObject.mMomentum = uIDragObject.mMomentum + (this.scale * (-this.mScroll * 0.05f)); this.mScroll = NGUIMath.SpringLerp(this.mScroll, 0f, 20f, single); if (this.mMomentum.magnitude <= 0.0001f) { this.mScroll = 0f; } else { if (this.mPanel == null) { this.FindPanel(); } if (this.mPanel != null) { Transform transforms = this.target; transforms.position = transforms.position + NGUIMath.SpringDampen(ref this.mMomentum, 9f, single); if (this.restrictWithinPanel && this.mPanel.clipping != UIDrawCall.Clipping.None) { this.mBounds = NGUIMath.CalculateRelativeWidgetBounds(this.mPanel.cachedTransform, this.target); if (!this.mPanel.ConstrainTargetToBounds(this.target, ref this.mBounds, this.dragEffect == UIDragObject.DragEffect.None)) { SpringPosition component = this.target.GetComponent<SpringPosition>(); if (component != null) { component.enabled = false; } } } return; } } } else { SpringPosition springPosition = this.target.GetComponent<SpringPosition>(); if (springPosition != null) { springPosition.enabled = false; } this.mScroll = 0f; } NGUIMath.SpringDampen(ref this.mMomentum, 9f, single); }
private void OnPress(bool pressed) { if (base.enabled && base.gameObject.activeInHierarchy && this.target != null) { this.mPressed = pressed; if (pressed) { if ((this.restrictWithinPanel || this.restrictToScreen) && this.mPanel == null) { this.FindPanel(); } if (this.restrictWithinPanel) { this.mBounds = NGUIMath.CalculateRelativeWidgetBounds(this.mPanel.cachedTransform, this.target); } if (this.restrictToScreen) { UICamera uICamera = UICamera.FindCameraForLayer(base.gameObject.layer); Rect rect = UIDragObject.screenBorder.Add(uICamera.camera.pixelRect); this.mBounds = AABBox.CenterAndSize(rect.center, new Vector3(rect.width, rect.height, 0f)); } this.mMomentum = Vector3.zero; this.mScroll = 0f; SpringPosition component = this.target.GetComponent<SpringPosition>(); if (component != null) { component.enabled = false; } this.mLastPos = UICamera.lastHit.point; Transform transforms = UICamera.currentCamera.transform; this.mPlane = new Plane((this.mPanel == null ? transforms.rotation : this.mPanel.cachedTransform.rotation) * Vector3.back, this.mLastPos); } else if (this.restrictWithinPanel && this.mPanel.clipping != UIDrawCall.Clipping.None && this.dragEffect == UIDragObject.DragEffect.MomentumAndSpring) { this.mPanel.ConstrainTargetToBounds(this.target, ref this.mBounds, false); } } }
public void Draw(uint time) { removeDead(time); Material mat = new Material(); mat.Type = MaterialType.TransparentVertexAlpha; mat.Lighting = false; sceneManager.VideoDriver.SetMaterial(mat); sceneManager.VideoDriver.SetTransform(TransformationState.World, Matrix.Identity); Random random = new Random(); Color[] colors = new Color[11]; // 11 colors (line count + 1, since each line has 2 points) for (int i = 0; i < colors.Length; i++) colors[i] = new Color(255, 255, 255, 255 - (10 - i) * 25); vertexBuffer.SetCount(0); foreach (var shot in shots) { Vector3Df pos = shot.node.Position; AABBox box = new AABBox(pos - new Vector3Df(shotRadius), pos + new Vector3Df(shotRadius)); List<Triangle3Df> tris = worldTriangles.GetTriangles(box, 1000); if (tris.Count == 0) continue; Dictionary<float, Vector3Df> uniquePoints = new Dictionary<float, Vector3Df>(); foreach (var t in tris) { Vector3Df p = t.GetClosestPointOnTriangle(pos); float k = p.X + p.Y * 1000 + p.Z * 1000000; uniquePoints[k] = p; } foreach (var point in uniquePoints.Values) { BillboardSceneNode n = sceneManager.AddBillboardSceneNode(null, new Dimension2Df(7.5f)); n.SetMaterialFlag(MaterialFlag.Lighting, false); n.SetMaterialType(MaterialType.TransparentAddColor); n.SetMaterialTexture(0, sceneManager.VideoDriver.GetTexture("../../media/particlewhite.bmp")); n.Position = point; n.AddAnimator(sceneManager.CreateDeleteAnimator(0.1f)); n.AnimatorList[0].Drop(); Vertex3D v1 = new Vertex3D(point); Vertex3D v2 = new Vertex3D(); for (int i = 0; i < 10; i++) { v1.Color = colors[i]; v2.Color = colors[i + 1]; v2.Position = pos.GetInterpolated(point, i * 0.111); if (i != 0 && i != 9) // do not displace first and last points v2.Position += new Vector3Df((random.Next() % 10) - 5, (random.Next() % 10) - 5, (random.Next() % 10) - 5); vertexBuffer.Add(v1); vertexBuffer.Add(v2); v1.Position = v2.Position; } } } indexBuffer.SetCount(vertexBuffer.Count); sceneManager.VideoDriver.DrawVertexPrimitiveList(vertexBuffer, indexBuffer, PrimitiveType.Lines); }
ClockNode(SceneNode parent, SceneManager smgr) : base(parent, smgr) { OnGetBoundingBox += new GetBoundingBoxEventHandler(ClockNode_OnGetBoundingBox); OnGetMaterialCount += new GetMaterialCountEventHandler(ClockNode_OnGetMaterialCount); OnGetMaterial += new GetMaterialEventHandler(ClockNode_OnGetMaterial); OnRegisterSceneNode += new RegisterSceneNodeEventHandler(ClockNode_OnRegisterSceneNode); OnRender += new RenderEventHandler(ClockNode_OnRender); OnAnimate += new AnimateEventHandler(ClockNode_OnAnimate); // add clock face Mesh mesh = SceneManager.GeometryCreator.CreateCylinderMesh(100, 32, 6, new Color(180, 180, 180)); MeshSceneNode clockFace = SceneManager.AddMeshSceneNode(mesh, this); clockFace.Rotation = new Vector3Df(90, 0, 0); clockFace.Position = new Vector3Df(0, 0, 10); mesh.Drop(); clockFace.UpdateAbsolutePosition(); boundingBox = clockFace.BoundingBoxTransformed; for (int i = 0; i < clockFace.MaterialCount; i++) materialList.Add(clockFace.GetMaterial(i)); // add clock center mesh = SceneManager.GeometryCreator.CreateCylinderMesh(10, 24, 16, new Color(255, 255, 255), false); MeshSceneNode clockCenter = SceneManager.AddMeshSceneNode(mesh, this); clockCenter.Rotation = new Vector3Df(90, 0, 0); clockCenter.Position = new Vector3Df(0, 0, -14); mesh.Drop(); clockCenter.UpdateAbsolutePosition(); boundingBox.AddInternalBox(clockCenter.BoundingBoxTransformed); for (int i = 0; i < clockCenter.MaterialCount; i++) materialList.Add(clockCenter.GetMaterial(i)); // add clock ticks for (int j = 0; j < 12; j++) { mesh = SceneManager.GeometryCreator.CreateCylinderMesh(5, 10, 16, new Color(255, 255, 255), false); MeshSceneNode clockTick = SceneManager.AddMeshSceneNode(mesh, this); clockTick.Rotation = new Vector3Df(90, 0, 0); float s = (float)Math.Sin((j * (360 / 12)) / (180 / Math.PI)); float c = (float)Math.Cos((j * (360 / 12)) / (180 / Math.PI)); clockTick.Position = new Vector3Df(s * 80, c * 80, 0); if ((j % 3) == 0) clockTick.Scale = new Vector3Df(2, 1, 2); mesh.Drop(); clockTick.UpdateAbsolutePosition(); boundingBox.AddInternalBox(clockTick.BoundingBoxTransformed); for (int i = 0; i < clockTick.MaterialCount; i++) materialList.Add(clockTick.GetMaterial(i)); } // add hour arrow mesh = SceneManager.GeometryCreator.CreateArrowMesh(12, 12, 40, 35, 4, 4, new Color(40, 40, 255), new Color(40, 40, 255)); arrowHours = SceneManager.AddMeshSceneNode(mesh, this); arrowHours.GetMaterial(0).EmissiveColor = new Color(0, 0, 255); arrowHours.GetMaterial(1).EmissiveColor = new Color(0, 0, 255); arrowHours.Position = new Vector3Df(0, 0, 3); mesh.Drop(); arrowHours.UpdateAbsolutePosition(); boundingBox.AddInternalBox(arrowHours.BoundingBoxTransformed); for (int i = 0; i < arrowHours.MaterialCount; i++) materialList.Add(arrowHours.GetMaterial(i)); // add minute arrow mesh = SceneManager.GeometryCreator.CreateArrowMesh(12, 12, 60, 50, 4, 4, new Color(40, 255, 40), new Color(40, 255, 40)); arrowMinutes = SceneManager.AddMeshSceneNode(mesh, this); arrowMinutes.GetMaterial(0).EmissiveColor = new Color(0, 255, 0); arrowMinutes.GetMaterial(1).EmissiveColor = new Color(0, 255, 0); arrowMinutes.Position = new Vector3Df(0, 0, -5); mesh.Drop(); arrowMinutes.UpdateAbsolutePosition(); boundingBox.AddInternalBox(arrowMinutes.BoundingBoxTransformed); for (int i = 0; i < arrowMinutes.MaterialCount; i++) materialList.Add(arrowMinutes.GetMaterial(i)); // add second arrow mesh = SceneManager.GeometryCreator.CreateArrowMesh(12, 12, 70, 60, 2, 2, new Color(255, 40, 40), new Color(255, 40, 40)); arrowSeconds = SceneManager.AddMeshSceneNode(mesh, this); arrowSeconds.GetMaterial(0).EmissiveColor = new Color(255, 0, 0); arrowSeconds.GetMaterial(1).EmissiveColor = new Color(255, 0, 0); arrowSeconds.Position = new Vector3Df(0, 0, -11); mesh.Drop(); arrowSeconds.UpdateAbsolutePosition(); boundingBox.AddInternalBox(arrowSeconds.BoundingBoxTransformed); for (int i = 0; i < arrowSeconds.MaterialCount; i++) materialList.Add(arrowSeconds.GetMaterial(i)); SceneManager.AddLightSceneNode(arrowSeconds, new Vector3Df(0, 70, 0), new Colorf(arrowSeconds.GetMaterial(0).EmissiveColor), 80); SceneManager.AddLightSceneNode(arrowMinutes, new Vector3Df(0, 60, 0), new Colorf(arrowMinutes.GetMaterial(0).EmissiveColor), 60); SceneManager.AddLightSceneNode(arrowHours, new Vector3Df(0, 40, 0), new Colorf(arrowHours.GetMaterial(0).EmissiveColor), 40); }