public static Rot RotBetween(Vector3 v1, Vector3 v2) { Rot rResult = new Rot(); Vector3 VectorNorm1 = new Vector3(v1).Normalize(); Vector3 VectorNorm2 = new Vector3(v2).Normalize(); Vector3 RotationAxis = Vector3.CrossProduct(VectorNorm1, VectorNorm2); //Test.Debug( "math: " << RotationAxis ); // Test.Debug //Test.Debug( Math.Abs( RotationAxis.x ) << " " << Math.Abs( RotationAxis.y ) << " " << Math.Abs( RotationAxis.z ) ); // Test.Debug if (Math.Abs(RotationAxis.x) < 0.0005 && Math.Abs(RotationAxis.y) < 0.0005 && Math.Abs(RotationAxis.z) < 0.0005) { Vector3 RandomVector = new Vector3(VectorNorm1); RandomVector.x += 0.5; RandomVector.Normalize(); RotationAxis = Vector3.CrossProduct(VectorNorm1, RandomVector); rResult = mvMath.AxisAngle2Rot(RotationAxis, Math.PI); } else { double DotProduct = Vector3.DotProduct(VectorNorm1, VectorNorm2); Diag.Debug("DotProduct: " + DotProduct.ToString()); // Test.Debug double Vangle = Math.Acos(DotProduct); Diag.Debug("math: " + Vangle.ToString()); // Test.Debug rResult = AxisAngle2Rot(RotationAxis, Vangle); } return(rResult); }
// based on http://nehe.gamedev.net public void RenderHeightMap(int[,] HeightMap, int iMapSize) // This Renders The Height Map As Quads { int X = 0, Y = 0; int x, y, z; if (HeightMap == null) { Diag.Debug("Error: no height map data available"); // Test.Debug return; } Gl.glBegin(Gl.GL_QUADS); // Test.Debug( "drawing quads..." ); // Test.Debug for (X = 2; X < (iMapSize - 3); X += 1) { // Test.Debug( "X " << X ); // Test.Debug for (Y = 2; Y < (iMapSize - 3); Y += 1) { Vector3 Normal = new Vector3();; // = VectorNormals[ X + 128 * Y ]; Normal.z = 1; Normal.x = (HeightMap[X + 10, Y] - HeightMap[X, Y]) / 10.0f; Normal.y = (HeightMap[X, Y + 10] - HeightMap[X, Y]) / 10.0f; x = X; y = Y; z = HeightMap[X, Y]; Gl.glNormal3d(Normal.x, Normal.y, Normal.z); Gl.glTexCoord2d((double)X / (double)iMapSize, (double)Y / (double)iMapSize); Gl.glVertex3i(x, y, z); x = X + 1; y = Y; z = HeightMap[X + 1, Y]; Gl.glNormal3d(Normal.x, Normal.y, Normal.z); Gl.glTexCoord2d((double)(X + 1) / (double)iMapSize, (double)(Y) / (double)iMapSize); Gl.glVertex3i(x, y, z); x = X + 1; y = Y + 1; z = HeightMap[X + 1, Y + 1]; Gl.glNormal3d(Normal.x, Normal.y, Normal.z); Gl.glTexCoord2d((double)(X + 1) / (double)iMapSize, (double)(Y + 1) / (double)iMapSize); Gl.glVertex3i(x, y, z); x = X; y = Y + 1; z = HeightMap[X, Y + 1]; Gl.glNormal3d(Normal.x, Normal.y, Normal.z); Gl.glTexCoord2d((double)(X) / (double)iMapSize, (double)(Y + 1) / (double)iMapSize); Gl.glVertex3i(x, y, z); } } //Test.Debug( "Quads done" << X ); // Test.Debug Gl.glEnd(); }
public void RefreshConfig() { configdoc = XmlHelper.OpenDom(sFilePath); Diag.Debug("reading config.xml ..."); XmlElement systemnode = (XmlElement)configdoc.DocumentElement.SelectSingleNode("config"); iDebugLevel = GetInt(systemnode, "debuglevel"); Diag.Debug("DebugLevel " + iDebugLevel.ToString()); clientconfig = (XmlElement)configdoc.DocumentElement.SelectSingleNode("client"); XmlElement displaynode = clientconfig.SelectSingleNode("display") as XmlElement; windowwidth = GetInt(displaynode, "width"); windowheight = GetInt(displaynode, "height"); XmlElement mapconfig = clientconfig.SelectSingleNode("map") as XmlElement; iMapDefaultWidth = GetInt(mapconfig, "defaultwidth"); iMapDefaultHeight = GetInt(mapconfig, "defaultheight"); XmlElement heightmapconfig = clientconfig.SelectSingleNode("heightmap") as XmlElement; defaultHeightMapFilename = heightmapconfig.GetAttribute("defaultfilename"); minheight = GetInt(heightmapconfig, "minheight"); maxheight = GetInt(heightmapconfig, "maxheight"); XmlElement heighteditingconfig = clientconfig.SelectSingleNode("heightediting") as XmlElement; HeightEditingDefaultBrushSize = GetInt(heighteditingconfig, "defaultbrushsize"); HeightEditingSpeed = GetDouble(heighteditingconfig, "speed"); XmlElement slopemapconfig = clientconfig.SelectSingleNode("slopemap") as XmlElement; defaultSlopeMapFilename = slopemapconfig.GetAttribute("defaultfilename"); SlopemapExportMaxSlope = GetDouble(slopemapconfig, "exportmaxslope"); foreach (XmlElement movementareanode in slopemapconfig.SelectNodes("movementareas/movementarea")) { double maxslope = Convert.ToDouble(movementareanode.GetAttribute("maxslope")); string colorstring = movementareanode.GetAttribute("color"); Color color = new Color(1, 1, 1); if (colorstring == "red") { color = new Color(1, 0, 0); } else if (colorstring == "green") { color = new Color(0, 1, 0); } else if (colorstring == "blue") { color = new Color(0, 0, 1); } movementareas.Add(new MovementAreaConfig(maxslope, color)); } XmlElement movementconfig = clientconfig.SelectSingleNode("movement") as XmlElement; cameratranslatespeed = GetDouble(movementconfig, "translatespeed"); camerarotatespeed = GetDouble(movementconfig, "rotatespeed"); foreach (XmlElement mappingnode in clientconfig.SelectNodes("keymappings/key")) { string sCommand = mappingnode.GetAttribute("command"); string sKeyCodes = mappingnode.GetAttribute("keycode"); string[] KeyCodes = sKeyCodes.Split("-".ToCharArray()); List <string> keycodelist = new List <string>(KeyCodes); CommandCombos.Add(new CommandCombo(sCommand, keycodelist)); } foreach (XmlElement mousemovenode in clientconfig.SelectNodes("mousemoveconfigs/mousemove")) { string name = mousemovenode.GetAttribute("name"); string vertical = mousemovenode.GetAttribute("vertical"); string horizontal = mousemovenode.GetAttribute("horizontal"); string zoom = mousemovenode.GetAttribute("zoom"); bool invertvertical = false; bool invertscroll = false; if (mousemovenode.HasAttribute("invertvertical") && mousemovenode.GetAttribute("invertvertical") == "yes") { invertvertical = true; } if (mousemovenode.HasAttribute("invertscroll") && mousemovenode.GetAttribute("invertscroll") == "yes") { invertscroll = true; } if (!MouseMoveConfigsByName.ContainsKey(name)) { MouseMoveConfigsByName.Add(name, new MouseMoveConfig(vertical, horizontal, zoom, invertvertical, invertscroll)); } } Diag.Debug("... config.xml read"); }