public BoneData(Segment segment) { this.mCurrentSegment = segment; this.mLastSegment = segment; this.mVelocityX1 = 0.0; this.mVelocityY1 = 0.0; this.mVelocityX2 = 0.0; this.mVelocityY2 = 0.0; this.mTimeLastUpdated = DateTime.Now; }
private void UpdateSegmentPosition(JointType joint1, JointType joint2, Segment segment) { Bone bone = new Bone(joint1, joint2); if (this.mSegments.ContainsKey(bone)) { BoneData boneData = this.mSegments[bone]; boneData.UpdateSegment(segment); this.mSegments[bone] = boneData; } else { this.mSegments.Add(bone, new BoneData(segment)); } }
public void UpdateJointPosition(JointCollection joints, JointType joint) { // セグメントの開始位置と終了位置を設定 Segment segment = new Segment( joints[joint].Position.X * this.mPlayerScale + this.mPlayerCenterPosition.X, this.mPlayerCenterPosition.Y - joints[joint].Position.Y * this.mPlayerScale); // セグメントの半径を設定 segment.mRadius = this.mPlayerBounds.Height * ((joint == JointType.Head) ? Player.HeadSize : Player.HandSize) / 2.0; this.UpdateSegmentPosition(joint, joint, segment); }
public void UpdateBonePosition(JointCollection joints, JointType joint1, JointType joint2) { // セグメントの開始位置と終了位置を設定 Segment segment = new Segment( joints[joint1].Position.X * this.mPlayerScale + this.mPlayerCenterPosition.X, this.mPlayerCenterPosition.Y - joints[joint1].Position.Y * this.mPlayerScale, joints[joint2].Position.X * this.mPlayerScale + this.mPlayerCenterPosition.X, this.mPlayerCenterPosition.Y - joints[joint2].Position.Y * this.mPlayerScale); // セグメントの線の太さを設定 segment.mRadius = Math.Max(3.0, this.mPlayerBounds.Height * Player.BoneSize) / 2.0; this.UpdateSegmentPosition(joint1, joint2, segment); }
public void UpdateSegment(Segment segment) { this.mLastSegment = this.mCurrentSegment; this.mCurrentSegment = segment; DateTime currentTime = DateTime.Now; double deltaTime = currentTime.Subtract(this.mTimeLastUpdated).TotalMilliseconds; if (deltaTime < 10.0) { deltaTime = 10.0; } double currentFps = 1000.0 / deltaTime; this.mTimeLastUpdated = currentTime; if (this.mCurrentSegment.IsCircle()) { this.mVelocityX1 = (this.mVelocityX1 * BoneData.Smoothing) + (1.0 - BoneData.Smoothing) * (this.mCurrentSegment.mX1 - this.mLastSegment.mX1) * currentFps; this.mVelocityY1 = (this.mVelocityY1 * BoneData.Smoothing) + (1.0 - BoneData.Smoothing) * (this.mCurrentSegment.mY1 - this.mLastSegment.mY1) * currentFps; } else { this.mVelocityX1 = (this.mVelocityX1 * BoneData.Smoothing) + (1.0 - BoneData.Smoothing) * (this.mCurrentSegment.mX1 - this.mLastSegment.mX1) * currentFps; this.mVelocityY1 = (this.mVelocityY1 * BoneData.Smoothing) + (1.0 - BoneData.Smoothing) * (this.mCurrentSegment.mY1 - this.mLastSegment.mY1) * currentFps; this.mVelocityX2 = (this.mVelocityX2 * BoneData.Smoothing) + (1.0 - BoneData.Smoothing) * (this.mCurrentSegment.mX2 - this.mLastSegment.mX2) * currentFps; this.mVelocityY2 = (this.mVelocityY2 * BoneData.Smoothing) + (1.0 - BoneData.Smoothing) * (this.mCurrentSegment.mY2 - this.mLastSegment.mY2) * currentFps; } }
public bool Hit(Segment segment, ref Point hitCenterPosition, ref double lineHitLocation) { double minDeltaXSquared = Math.Pow(this.mSize + segment.mRadius, 2.0); if (segment.IsCircle()) { // 円とアイテムとの衝突 if (FallingItemsManager.DistanceSquared( this.mCenterPosition.X, this.mCenterPosition.Y, segment.mX1, segment.mX2) <= minDeltaXSquared) { hitCenterPosition.X = segment.mX1; hitCenterPosition.Y = segment.mY1; lineHitLocation = 0.0; return true; } } else { // ボーンとアイテムとの衝突 double lineLengthSquared = FallingItemsManager.DistanceSquared( segment.mX1, segment.mY1, segment.mX2, segment.mY2); if (lineLengthSquared < 0.5) { return (FallingItemsManager.DistanceSquared( this.mCenterPosition.X, this.mCenterPosition.Y, segment.mX1, segment.mY1) < minDeltaXSquared); } double u = ((this.mCenterPosition.X - segment.mX1) * (segment.mX2 - segment.mX1)) + (((this.mCenterPosition.Y - segment.mY1) * (segment.mY2 - segment.mY1)) / lineLengthSquared); if ((u >= 0.0) && (u <= 1.0)) { double intersectX = segment.mX1 + ((segment.mX2 - segment.mX1) * u); double intersectY = segment.mY1 + ((segment.mY2 - segment.mY1) * u); if (FallingItemsManager.DistanceSquared( this.mCenterPosition.X, this.mCenterPosition.Y, intersectX, intersectY) < minDeltaXSquared) { lineHitLocation = u; hitCenterPosition.X = intersectX; hitCenterPosition.Y = intersectY; return true; } } else { if (u < 0.0) { if (FallingItemsManager.DistanceSquared( this.mCenterPosition.X, this.mCenterPosition.Y, segment.mX1, segment.mY1) < minDeltaXSquared) { lineHitLocation = 0.0; hitCenterPosition.X = segment.mX1; hitCenterPosition.Y = segment.mY1; return true; } } else { if (FallingItemsManager.DistanceSquared( this.mCenterPosition.X, this.mCenterPosition.Y, segment.mX2, segment.mY2) < minDeltaXSquared) { lineHitLocation = 1.0; hitCenterPosition.X = segment.mX2; hitCenterPosition.Y = segment.mY2; return true; } } } return false; } return false; }