public CharacterController(GenericCamera _camera, World _containingWorld, float _characterHeight = 1.85f, float _bodyDiameter = 0.45f, float _bodyMass = 70f) { camera = _camera; ContainingWorld = _containingWorld; CharacterHeight = _characterHeight; CharacterDiameter = _bodyDiameter; // Initialize default values for auto properties IsRunning = false; WalkSpeed = 2.7f; WalkSpeedRunning = 6f; // Create a capsule shaped rigid body representing the character in the physics world. Body = new RigidBody(_bodyMass, mat4.Identity, new CapsuleShape(CharacterDiameter / 2f, BodyHeight)); ContainingWorld.Physics.AddRigidBody(Body); // Prevent the rigid body from falling to the ground by simply disabling any rotation Body.SetAngularFactor(vec3.Zero); // Register the required callbacks. // This update function is called 20 - 60 times per second to update the character position. Scripting.RegisterUpdateFunction(Update, 1 / 60f, 1 / 20f); // This event handler is used to catch the keyboard input that steers the character. Input.OnPressInput += HandleInput; }
public Player(GenericCamera _camera) { Direction = new vec3(1, 0, 0); camera = _camera; CurrentDiggingShape = DiggingShape.Sphere; CurrentDiggingAlignment = DiggingAlignment.AxisAligned; Input.OnPressInput += HandlePressInput; Input.OnAxisInput += HandleAxisInput; Inventory = new Inventory(this); }
public void Load() { logics = new List <ILogical>(); jobs = new List <IRenderJob>(); lCache = new List <ILogical>(); jCache = new List <IRenderJob>(); lToRemove = new List <ILogical>(); jToRemove = new List <IRenderJob>(); Camera = new GenericCamera(); OnLoad(); Loaded = true; }
/// <summary> /// Initializes the local part of the mod. /// </summary> public static void Startup(IntPtr _unmanagedModule) { if (!Scripting.IsHost) { Universe.CreateWorld("UpvoidMinerWorld", new UpvoidMinerNetworkWorldReceiver()); } // Create a simple camera that allows free movement. Camera = new GenericCamera (); Camera.FarClippingPlane = 3500.0; CameraControl = new FreeCameraControl (-10f, Camera); // Get the world (created by the host script) World world = Universe.GetWorldByName ("UpvoidMinerWorld"); // Place the camera in the world world.AttachCamera (Camera); if (Rendering.ActiveMainPipeline != null) Rendering.ActiveMainPipeline.SetCamera (Camera); GC.KeepAlive (Camera); if (!Scripting.IsHost) { ivec3 refPos = new ivec3 (0, 0, 0); float activeRadius = 10; float sleepingRadius = 20; float minLODRange = 10; float falloff = 5; world.AddActiveRegion (refPos, activeRadius, sleepingRadius, minLODRange, falloff); } // Configure the camera to receive user input Input.RootGroup.AddListener (CameraControl); // Registers the update callback that updates the camera position. Scripting.RegisterUpdateFunction(Update, 1 / 60.0f, 3 / 60.0f); }
/// <summary> /// This is called by the engine at mod startup and initializes the local part of the UpvoidMiner mod. /// </summary> public static void Startup(IntPtr _unmanagedModule) { // Get and save the resource domain of the mod, needed for loading resources. UpvoidMiner.Mod = Module.FromHandle(_unmanagedModule); UpvoidMiner.ModDomain = UpvoidMiner.Mod.ResourceDomain; // Get the world (created by the host script). world = Universe.GetWorldByName("UpvoidMinerWorld"); // No loading screen for clients (since the server generates the world) if (Scripting.IsHost) { // Register a callback for the terrain generation so the GUI can be notified when the world is ready. world.Terrain.AddVolumeUpdateCallback(VolumeCallback, false, 0, 4); // Show a splash screen in the GUI client. WebGui.DefaultUI.LoadURL("http://localhost:" + Webserver.DefaultWebserver.Port + "/Mods/Upvoid/UpvoidMiner/0.0.1/SplashScreen.html"); // Register a socket for sending progress updates to the loading screen generationProgressSocket = new WebSocketHandler(); Webserver.DefaultWebserver.RegisterWebSocketHandler(UpvoidMiner.ModDomain, "GenerationProgressSocket", generationProgressSocket); Webserver.DefaultWebserver.RegisterDynamicContent(UpvoidMiner.ModDomain, "ActivatePlayer", (WebRequest request, WebResponse response) => ActivatePlayer()); Webserver.DefaultWebserver.RegisterDynamicContent(UpvoidMiner.ModDomain, "IsPlayerActivated", (WebRequest request, WebResponse response) => response.AppendBody((player != null).ToString())); Webserver.DefaultWebserver.RegisterDynamicContent(UpvoidMiner.ModDomain, "GenerationProgressQuery", webGenerationProgress); Webserver.DefaultWebserver.RegisterDynamicContent(UpvoidMiner.ModDomain, "OpenSiteInBrowser", (WebRequest request, WebResponse response) => Process.Start(request.GetQuery("url"))); } // Create a simple camera that allows free movement. camera = new GenericCamera(); camera.Position = new vec3(0, 10, 0); camera.FarClippingPlane = 1750.0; // Client-only: register terrain materials if (!Scripting.IsHost) { TerrainResource.RegisterResources(world.Terrain); } // Place the camera in the world. world.AttachCamera(camera); Rendering.SetupDefaultPipeline(camera); // Create an active region around the player spawn // Active regions help the engine to decide which parts of a world are important (to generate, render, etc.) // In near future it will be updated when the player moves out of it //world.AddActiveRegion(new ivec3(), 100f, 400f, 40f, 40f); Settings.InitSettingsHandlers(); Webserver.DefaultWebserver.RegisterDynamicContent(UpvoidMiner.ModDomain, "QuitGame", (WebRequest request, WebResponse response) => Scripting.ShutdownEngine()); // Register for input press events. Input.OnPressInput += HandlePressInput; // Register sockets for resource downloading progress bar resourceDownloadProgressSocket = new WebSocketHandler(); Webserver.DefaultWebserver.RegisterWebSocketHandler(UpvoidMiner.ModDomain, "ResourceDownloadProgress", resourceDownloadProgressSocket); if (!Scripting.IsHost) { ActivatePlayer(); } }
/// <summary> /// This sets the camera of the context. /// </summary> /// <param name="camera"></param> public void SetCamera(GenericCamera camera) { UseCamera = camera; camera.CalculateViewMatrix(Window); }