protected virtual void startUsing() { //weaponModel.ModelMatrix = Matrix4.Mult(spawOffset, Matrix4.Invert(parent.viewInfo.modelviewMatrix)); weaponModel.Position = GenericMethods.Mult(new Vector4(0.3f, -0.7f, -0.7f, 1f), Matrix4.Invert(parent.viewInfo.modelviewMatrix)).Xyz; weaponModel.Orientation = Matrix4.Mult(weaponRMat, GenericMethods.MatrixFromVector(PointingDirection)); }
public override void update() { base.update(); if (Parent.tool == this) { arcModel.Position = weaponModel.Position; //arcModel.Position2 = weaponModel.Position; muzzleModel.Position = weaponModel.Position; muzzleModel.Orientation = weaponModel.Orientation; arcModel.Orientation = weaponModel.Orientation; arcModel.Orientation2 = weaponModel.Orientation; // moving model if (selectedMod != null) { JVector anchorCoords = GenericMethods.FromOpenTKVector(Position + PointingDirection * grabDist); if (mConst != null) { mConst.Anchor = anchorCoords; } else if (selectedBody.IsStatic) { selectedBody.Position = anchorCoords + selModRelPos; } selectedMod.updateMatrix(); Matrix4 globalMaker = Matrix4.Mult(selectedMod.Orientation, selectedMod.ModelMatrix); Vector4 gpos = GenericMethods.Mult(modelLocalHitCoords, globalMaker); JVector hitCoords = GenericMethods.FromOpenTKVector(gpos.Xyz); //weaponLocalHitCoords = GenericMethods.Mult(gpos, Matrix4.Invert(Parent.viewInfo.modelviewMatrix)).Xyz; //arcModel.Position2 = GenericMethods.Mult(new Vector4(weaponLocalHitCoords - new Vector3(0, 0, 5), 1f), Matrix4.Invert(Parent.viewInfo.modelviewMatrix)).Xyz; arcModel.Position2 = gpos.Xyz - 5 * Parent.viewInfo.PointingDirection; //arcModel.Orientation2 = Matrix4.CreateTranslation(weaponLocalHitCoords - new Vector3(0, 0, -5)); } } else { arcModel.isVisible = false; muzzleModel.isVisible = false; if (selectedMod != null) { //mConst.Body1.AffectedByGravity = true; if (mConst != null) { Scene.world.RemoveConstraint(mConst); } selectedBody = null; selectedMod.selected = 0; selectedMod.Forceupdate = false; selectedMod = null; mConst = null; } } }
protected override void fireDown() { RigidBody body; JVector normal; float frac; bool result = Scene.world.CollisionSystem.Raycast(GenericMethods.FromOpenTKVector(Position), GenericMethods.FromOpenTKVector(PointingDirection), raycastCallback, out body, out normal, out frac); Vector4 gpos = new Vector4(Position + PointingDirection * frac, 1); JVector hitCoords = GenericMethods.FromOpenTKVector(gpos.Xyz); weaponLocalHitCoords = GenericMethods.Mult(gpos, Matrix4.Invert(weaponModel.ModelMatrix)).Xyz; arcModel.Orientation2 = Matrix4.CreateTranslation(weaponLocalHitCoords - new Vector3(0, 0, -5)); muzzleModel.isVisible = true; if (result && body.Tag != null) { PhysModel curMod = (PhysModel)body.Tag; if (curMod.grabable) { arcModel.isVisible = true; grabDist = frac; selectedBody = body; selectedMod = (PhysModel)body.Tag; selectedMod.selected = 1; selectedMod.Forceupdate = true; Matrix4 localMaker = Matrix4.Invert(Matrix4.Mult(selectedMod.Orientation, selectedMod.ModelMatrix)); modelLocalHitCoords = GenericMethods.Mult(gpos, localMaker); if (body.IsStatic) { selModRelPos = body.Position - hitCoords; } else { JVector lanchor = hitCoords - body.Position; lanchor = JVector.Transform(lanchor, JMatrix.Transpose(body.Orientation)); body.IsActive = true; //body.SetMassProperties(JMatrix.Identity, 0.1f, false); //body.AffectedByGravity = false; mConst = new Jitter.Dynamics.Constraints.SingleBody.PointOnPoint(body, lanchor); mConst.Softness = 0.02f; mConst.BiasFactor = 0.1f; Scene.world.AddConstraint(mConst); } } } }
public override bool frustrumCheck(Drawable drawable) { Vector4 vSpacePos = GenericMethods.Mult(new Vector4(drawable.Position, 1), modelviewProjectionMatrix); float range = drawable.boundingSphere * 2f / widith; if (float.IsNaN(range) || float.IsInfinity(range)) { return(false); } vSpacePos /= vSpacePos.W; return( vSpacePos.X < (1f + range) && vSpacePos.X > -(1f + range) && vSpacePos.Y < (1f + range) && vSpacePos.Y > -(1f + range) && vSpacePos.Z < (1f) && vSpacePos.Z > -(1f) ); }
public void rotatePlayer(float pitch, float yaw, float roll) { Vector4 tmpView = new Vector4(0, 0, -1, 1); parent.rawRotation.X -= pitch; parent.rawRotation.Y += yaw; parent.rotation = parent.rawRotation * (1 - smoothing) + parent.rotation * smoothing; Matrix4 tmpA = Matrix4.CreateRotationX(parent.rotation.X); Matrix4 tmpb = Matrix4.CreateRotationY(parent.rotation.Y); tmpView = GenericMethods.Mult(tmpA, tmpView); tmpView = GenericMethods.Mult(tmpb, tmpView); parent.PointingDirection = tmpView.Xyz; parent.fwdVec = parent.getFrontVec(); parent.rightVec = parent.getRightVec(); }
public override void update() { if (parent.tool == this) { iconPos = new Vector2(-0.8f, 0.8f - slot * iconDist); icon.Color = new Vector4(0.8f, 0.3f, 0.8f, 1.0f); Position = parent.Position; //weaponModel.updateModelMatrix(); //weaponModel.ModelMatrix = Matrix4.Invert(parent.viewInfo.modelviewMatrix); weaponModel.isVisible = true; PointingDirection = parent.PointingDirection; /* * weaponModel.Position = position + * parent.viewInfo.pointingDirection * 0.7f + * parent.viewInfo.pointingDirectionUp * 0.3f + * parent.viewInfo.pointingDirectionRight * -0.3f; */ Vector3 newPos = GenericMethods.Mult(new Vector4(0.3f, -0.3f, -0.7f, 1f), Matrix4.Invert(parent.viewInfo.modelviewMatrix)).Xyz; Matrix4 newOri = Matrix4.Mult(weaponRMat, GenericMethods.MatrixFromVector(PointingDirection)); float smoothness = 0.5f; weaponModel.Position = weaponModel.Position * smoothness + newPos * (1 - smoothness); weaponModel.Orientation = GenericMethods.BlendMatrix(weaponModel.Orientation, newOri, smoothness); if (!wasActive) { startUsing(); } if (gameInput != null) { //rotation rotate(); //move move(); // fire player fire bool K = gameInput.mouse[MouseButton.Left]; if (K && !prevK && wasActive) { fireDown(); } else if (!K && prevK) { fireUp(); } prevK = K; // fire player interact bool E = gameInput.keyboard[Key.E]; if (E && !prevE) { interactDown(); } else if (!E && prevE) { interactUp(); } prevE = E; } wasActive = true; updateChilds(); } else { iconPos = new Vector2(-0.85f, 0.8f - slot * iconDist); icon.Color = new Vector4(0.1f, 0.12f, 0.2f, 1.0f); weaponModel.isVisible = false; wasActive = false; } smoothIconPos = smoothIconPos * iconWeight + iconPos * (1 - iconWeight); icon.Position = smoothIconPos; }