private float UpdateSelectedBlock() // return the distance with the selected block { Vector3 relBlockPos; Block actBlock; float distance = VanillaBlock.getBlockOnRay(this.mWorld.getIsland(), this.mStateMgr.Camera.GetCameraToViewportRay(0.5f, 0.5f), DIST_MAX_SELECTION, DIST_MIN_SELECTION, out relBlockPos, out actBlock); if (distance > DIST_MAX_SELECTION) { this.SelectedBlockPos = Vector3.ZERO; this.SelectedBlock = null; this.mWireCube.SetVisible(false); return(0); } this.SelectedBlockPos = relBlockPos; this.SelectedBlock = actBlock; this.mWireCube.SetVisible(true); this.mWireCube.Position = (this.SelectedBlockPos + Vector3.NEGATIVE_UNIT_Z) * Cst.CUBE_SIDE; if (!this.mStateMgr.GameInfo.IsInEditorMode) { ConstructionBlock constr = this.SelectedBlock as ConstructionBlock; if (constr != null) { this.BuildingMgr.ActConsBlockPos = this.SelectedBlockPos; } else if (!this.mIsBuilderOpen && this.BuildingMgr.ActConsBlockPos != -Vector3.UNIT_SCALE) { this.BuildingMgr.ActConsBlockPos = -Vector3.UNIT_SCALE; } } return(distance); }
public bool AddBulletAndHit(VanillaCharacter source, Vector3 decalage, VanillaCharacter target) { Vector3 sourcePoint = source.FeetPosition + (source.Size.y / 2) * Vector3.UNIT_Y + decalage; Vector3 targetPoint = target.FeetPosition + target.Size.y / 2 * Vector3.UNIT_Y; Vector3 diff = targetPoint - sourcePoint; if (Math.Abs(diff.y / Cst.CUBE_SIDE) > 6) { return(false); } Degree pitch = -Math.ATan2(diff.y, diff.z); Degree yaw = source.GetYaw(); if (yaw.ValueAngleUnits > 90 && yaw.ValueAngleUnits < 270) { yaw *= -1; yaw += new Degree(180); } float targetDistance = diff.Length; Ray ray = new Ray(sourcePoint + Vector3.NEGATIVE_UNIT_Z, diff.NormalisedCopy); float blockDistance = VanillaBlock.getBlockOnRay(source.getIsland(), ray, Bullet.DEFAULT_RANGE, 30); if (targetDistance > blockDistance) { return(false); } SceneNode pitchNode = this.SceneMgr.RootSceneNode.CreateChildSceneNode(); pitchNode.Position = sourcePoint; pitchNode.Pitch(pitch); SceneNode yawNode = pitchNode.CreateChildSceneNode(); yawNode.Yaw(yaw); yawNode.AttachObject(StaticRectangle.CreateLine(this.SceneMgr, Vector3.ZERO, new Vector3(0, 0, 15), ColoredMaterials.YELLOW)); this.mBullets.Add(new Bullet(source, target, pitchNode, yawNode)); return(true); }