// "Respawns" the player at a specific spawn point. Passing -1 will move the player to the next spawn point. public void RespawnPlayer(int index) { if (q3bsp.entities != null && camera != null && camera.playerMover != null) { String spawn_point_param_name; List <Q3Entity> spawns; spawn_point_param_name = "info_player_deathmatch"; // Quake 3 bsp file spawns = q3bsp.entities.Where(e => e.name == spawn_point_param_name || e.classname == spawn_point_param_name).ToList(); if (!spawns.Any()) { spawn_point_param_name = "info_player_start"; // TREMULOUS bsp file spawns = q3bsp.entities.Where(e => e.name == spawn_point_param_name || e.classname == spawn_point_param_name).ToList(); } if (index == -1) { index = (lastIndex + 1) % spawns.Count; } lastIndex = index; Q3Entity spawnPoint = spawns[index]; //spawns.First(e => e.Index == index); //Entity spawnPoint = q3bsp.entities[spawn_point_param_name]; float zAngle; float xAngle; if (spawnPoint.Fields.ContainsKey("angle")) { zAngle = (float)((double)(spawnPoint.Fields["angle"])); } else { zAngle = 0.0f; } zAngle = -(zAngle); zAngle *= ((float)Math.PI / 180.0f) + ((float)Math.PI * 0.5f); // Negative angle in radians + 90 degrees xAngle = 0.0f; xAngle = (xAngle / 360f) * MathHelper.TwoPi; zAngle = (zAngle / 360f) * MathHelper.TwoPi + MathHelper.PiOver2 + MathHelper.PiOver4; Vector3 rotation = new Vector3(xAngle, 0.0f, zAngle); Vector3 origin = (Vector3)spawnPoint.Fields["origin"]; origin.Z += 30; // Start a little ways above the floor camera.Reset(); camera.SetOrigin(origin, rotation); camera.velocity = Vector3.Zero; } }