public void DOFPostEffectautoFocus(coPostEffect thisobj) { try { coGameConnection serverconnection = "ServerConnection"; coCamera camera = serverconnection.getCameraObject(); uint mask = (uint)(WinterLeaf.Enums.SceneObjectTypesAsUint.StaticObjectType | WinterLeaf.Enums.SceneObjectTypesAsUint.TerrainObjectType); //string control = GameConnection.getCameraObject("ServerConnection"); //console.Call("ServerConnection", "getCameraObject"); Point3F fvec = camera.getEyeVector(); Point3F start = camera.getEyePoint(); //Point3F fvec = ShapeBase.getEyeVector(control); // console.Call(control, "getEyeVector"); //Point3F start = ShapeBase.getEyePoint(control); // console.Call(control, "getEyePoint"); Point3F end = Util.VectorAdd(start, Util.VectorScale(fvec, fGlobal["$Param::FarDist"])); string result = Util.containerRayCast(start, end, mask, camera, true); string hitPos = Util.getWords(result, 1, 3); string focDist = sGlobal["$Param::FarDist"]; if (hitPos != "") { focDist = Util.VectorDist(new Point3F(hitPos), start).AsString(); } thisobj["focalDist"] = focDist; } catch (Exception) { //Do nothing, this only gets hit when it can't find the serverconnection or the camera. } }
public void PlayerSetDamageDirection(coPlayer player, coPlayer sourceObject, TransformF damagePos) { if (sourceObject.isObject()) { damagePos = console.isField(sourceObject, "initialPosition") ? new TransformF(sourceObject["initialPosition"]) : sourceObject.getTransform(); } TransformF dp = damagePos; Point3F wbc = player.getWorldBoxCenter(); TransformF damagevec = dp - new TransformF(wbc); damagevec = damagevec.normalizeSafe(); coGameConnection client = player["client"]; if (!client.isObject()) { return; } coCamera cameraobject = client.getCameraObject(); TransformF inverseTransform = cameraobject.getInverseTransform(); damagevec = math.MatrixMulVector(inverseTransform, damagevec.MPosition); float[] components = new float[6]; string[] directions = new string[6]; directions[0] = "Left"; directions[1] = "Right"; directions[2] = "Bottom"; directions[3] = "Front"; directions[4] = "Bottom"; directions[5] = "Top"; components[0] = -damagevec.MPosition.x; components[1] = damagevec.MPosition.x; components[2] = -damagevec.MPosition.y; components[3] = damagevec.MPosition.y; components[4] = -damagevec.MPosition.z; components[5] = damagevec.MPosition.z; string damagedirection = string.Empty; float max = 0; for (int i = 0; i < 6; i++) { if (components[i] <= max) { continue; } damagedirection = directions[i]; max = components[i]; } if (console.isObject(client)) { console.commandToClient(client, console.addTaggedString("setDamageDirection"), new[] { damagedirection }); } }