public override void update() { base.update(); if (Parent.tool == this) { ghost.isVisible = true; grid.isVisible = true; 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); Vector3 hitCoords = Position + PointingDirection * frac; if (result && ghost != null) { float smoothness = 0.9f; //Matrix4 newOri = Matrix4.Mult(Matrix4.CreateRotationX((float)Math.PI / 2), Conversion.MatrixFromVector(normal)); Matrix4 newOri = GenericMethods.MatrixFromVector(normal); Vector3 newPos = hitCoords + GenericMethods.ToOpenTKVector(normal) * template.positionOffset; grid.Position = smoothness * grid.Position + (1 - smoothness) * hitCoords; grid.Orientation = GenericMethods.BlendMatrix(grid.Orientation, newOri, smoothness); ghost.Position = smoothness * ghost.Position + (1 - smoothness) * newPos; if (template.normal) { ghost.Orientation = newOri; } } } else { ghost.isVisible = false; grid.isVisible = false; } }
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; }