public override void Initialize() { // Compute the Eye position into the entity _entityEyeOffset = new Vector3(0, Player.DefaultSize.Y / 100 * 80, 0); // Set Position // Set the entity world position following the position received from server _worldPosition = Player.Position; // Compute the initial Player world bounding box VisualVoxelEntity.RefreshWorldBoundingBox(ref _worldPosition); // Init Velret physic simulator _physicSimu = new VerletSimulator(ref VisualVoxelEntity.LocalBBox) { WithCollisionBouncing = false }; _physicSimu.ConstraintFct += _entityCollisionManager.IsCollidingWithEntity; //Check against entities first _physicSimu.ConstraintFct += _landscapeManager.IsCollidingWithTerrain; //Landscape checking after _entityRotations = new EntityRotations(_inputsManager, _physicSimu); _entityRotations.EntityRotationSpeed = Player.RotationSpeed; _entityRotations.SetOrientation(Player.HeadRotation, _worldPosition + _entityEyeOffset); // Set displacement mode _playerCharacter.DisplacementMode = Player.DisplacementMode; }
public PlayerEntityManager(CameraManager <ICameraFocused> cameraManager, InputsManager inputsManager, SingleArrayChunkContainer cubesHolder, ServerComponent server, VoxelModelManager voxelModelManager, VisualWorldParameters visualWorldParameters, EntityFactory factory, LandscapeBufferManager bufferManager, ILandscapeManager landscapeManager, ChatComponent chatComponent, PostEffectComponent postEffectComponent, GuiManager guiManager, ISoundEngine soundEngine, TimerManager timerManager ) { _cameraManager = cameraManager; _inputsManager = inputsManager; _soundEngine = soundEngine; _cubesHolder = cubesHolder; _visualWorldParameters = visualWorldParameters; _factory = factory; _bufferManager = bufferManager; _landscapeManager = landscapeManager; _chatComponent = chatComponent; _postEffectComponent = postEffectComponent; OnLanding += PlayerEntityManager_OnLanding; _guiManager = guiManager; PlayerCharacter = (PlayerCharacter)server.Player; ShowDebugInfo = true; // Create a visualVoxelEntity (== Assign a voxel body to the PlayerCharacter) VisualVoxelEntity = new VisualVoxelEntity(PlayerCharacter, voxelModelManager); //Add a new Timer trigger _energyUpdateTimer = timerManager.AddTimer(1000); //A timer that will be raised every second _energyUpdateTimer.OnTimerRaised += energyUpdateTimer_OnTimerRaised; HasMouseFocus = Updatable; UpdateOrder = 0; // create "real" random var entropySource = RNGCryptoServiceProvider.Create(); var bytes = new byte[4]; entropySource.GetBytes(bytes); random = new Random(BitConverter.ToInt32(bytes, 0)); }
public override void FTSUpdate(GameTime timeSpend) { EnergyFTSUpdate(timeSpend); // wait until landscape being loaded if (!WorldChunks.IsInitialLoadCompleted) { return; } Player.EntityState.Entropy = random.Next(); // Input handling inputHandler(); _entityCollisionManager.Update(); // Refresh player Movement + rotation UpdateEntityMovementAndRotation(ref timeSpend); CheckAfterNewPosition(); // Refresh the player Bounding box VisualVoxelEntity.RefreshWorldBoundingBox(ref _worldPosition); }
private void AddVoxelEntity(EntityCollectionEventArgs e) { var voxelEntity = e.Entity as IVoxelEntity; if (voxelEntity == null) { return; //My static entity is not a Voxel Entity => Not possible to render it so !!! } //Create the Voxel Model Instance for the Item VisualVoxelModel model = null; if (!string.IsNullOrEmpty(voxelEntity.ModelName)) { model = _voxelModelManager.GetModel(voxelEntity.ModelName, false); } if (model != null && voxelEntity.ModelInstance == null) //The model blueprint is existing, and I need to create an instance of it ! { var treeGrowing = e.Entity as TreeGrowingEntity; if (treeGrowing != null) { if (treeGrowing.Scale > 0) { // we need to use generated voxel model TreeBpSeed key; key.TreeTypeId = treeGrowing.TreeTypeId; key.TreeSeed = treeGrowing.TreeRndSeed; VisualVoxelModel treeModel; if (_cachedTrees.TryGetValue(key, out treeModel)) { model = treeModel; } else { var voxelModel = VoxelModel.GenerateTreeModel(treeGrowing.TreeRndSeed, _visualWorldParameters.WorldParameters.Configuration.TreeBluePrintsDico[ treeGrowing.TreeTypeId]); model = new VisualVoxelModel(voxelModel, _voxelModelManager.VoxelMeshFactory); model.BuildMesh(); _cachedTrees.Add(key, model); } } } var treeSoul = e.Entity as TreeSoul; if (treeSoul != null) { TreeBpSeed key; key.TreeTypeId = treeSoul.TreeTypeId; key.TreeSeed = treeSoul.TreeRndSeed; _cachedTrees.Remove(key); } voxelEntity.ModelInstance = new VoxelModelInstance(model.VoxelModel); //Assign state in case of growing entity ! var growingEntity = e.Entity as PlantGrowingEntity; if (growingEntity != null) { voxelEntity.ModelInstance.SetState(growingEntity.GrowLevels[growingEntity.CurrentGrowLevelIndex].ModelState); } var visualVoxelEntity = new VisualVoxelEntity(voxelEntity, _voxelModelManager); //Get default world translation Matrix instanceTranslation = Matrix.Translation(voxelEntity.Position.AsVector3()); //Apply special rotation to the creation instance Quaternion instanceRotation = Quaternion.Identity; if (voxelEntity is IRndYRotation && ((IRndYRotation)voxelEntity).RndRotationAroundY) { instanceRotation = Quaternion.RotationAxis(Vector3.UnitY, (float)(_rnd.NextDouble() * MathHelper.TwoPi)); } else if (voxelEntity is IItem) { var item = voxelEntity as IItem; instanceRotation = item.Rotation; } //Apply special scaling to created entity (By default all blue print are 16 times too big. Matrix instanceScaling = Matrix.Scaling(1.0f / 16.0f); if (treeGrowing != null && treeGrowing.Scale > 0) { instanceScaling = Matrix.Scaling(treeGrowing.Scale); } //Create the World transformation matrix for the instance. //We take the Model instance world matrix where we add a Rotation and scaling proper to the instance visualVoxelEntity.VoxelEntity.ModelInstance.World = instanceScaling * instanceTranslation; visualVoxelEntity.VoxelEntity.ModelInstance.Rotation = instanceRotation; var result = GetCube(visualVoxelEntity.VoxelEntity.Position.ToCubePosition()); if (result.IsValid) { visualVoxelEntity.BlockLight = result.Cube.EmissiveColor; } else { visualVoxelEntity.BlockLight = new ByteColor(255, 255, 255, 255); } if (visualVoxelEntity.VisualVoxelModel.Initialized == false) { visualVoxelEntity.VisualVoxelModel.BuildMesh(); } if (voxelEntity.ModelInstance.CanPlay("Idle")) { voxelEntity.ModelInstance.Play("Idle", true); } lock (_syncRoot) { List <VisualVoxelEntity> list; if (_visualVoxelEntities.TryGetValue(voxelEntity.ModelName, out list)) { list.Add(visualVoxelEntity); } else { _visualVoxelEntities.Add(voxelEntity.ModelName, new List <VisualVoxelEntity> { visualVoxelEntity }); } } var lightEntity = e.Entity as ILightEmitterEntity; if (e.AtChunkCreationTime == false && lightEntity != null) { //Get the Cube where is located the entity var entityWorldPosition = lightEntity.Position; var entityBlockPosition = new Vector3I(MathHelper.Floor(entityWorldPosition.X), MathHelper.Floor(entityWorldPosition.Y), MathHelper.Floor(entityWorldPosition.Z)); //new TerraCubeWithPosition(entityBlockPosition, WorldConfiguration.CubeId.Air, _visualWorldParameters.WorldParameters.Configuration), this.UpdateOrder = 1; var cubeRange = new Range3I { Position = new Vector3I(entityBlockPosition.X, 0, entityBlockPosition.Z), Size = Vector3I.One }; _chunkEntityImpactManager.CheckImpact(this, cubeRange); } } }