예제 #1
0
        public override bool collides(Object3D obj)
        {
            if (obj.GetType() == typeof(LandscapeGeomipmap))
            {
                float t1 = ((LandscapeGeomipmap)obj).getHeight(oldPos) + ((LandscapeGeomipmap)obj).getPosition().Y;
                float t2 = ((LandscapeGeomipmap)obj).getHeight(pos) + ((LandscapeGeomipmap)obj).getPosition().Y;
                if ((t1 <= oldPos.Y && t2 >= pos.Y) || (t1 >= oldPos.Y && t2 <= pos.Y))
                {
                    return(true);
                }

                /*
                 * if (pos.Y <= ((LandscapeGeomipmap)obj).getHeight(pos) + ((LandscapeGeomipmap)obj).getPosition().Y)
                 * {
                 *  return true;
                 * }
                 */
            }
            return(false);
        }
예제 #2
0
파일: Camera.cs 프로젝트: pr3luder/water3d
 public void setObjective(Object3D objective)
 {
     this.objective = objective;
 }
예제 #3
0
 public void setRefraction(String where, List <Object3D> what, Object3D obj)
 {
     refractionsList[where]    = what;
     objectsRefractList[where] = obj;
 }
예제 #4
0
 public void setReflection(String where, List <Object3D> what, Object3D obj)
 {
     // projection matrix for clipping away everything under water in mirrored texture
     reflectionsList[where]   = what;
     objectsMirrorList[where] = obj;
 }
예제 #5
0
 public void addRefraction(String where, Object3D what)
 {
     refractionsList[where] = what;
 }
예제 #6
0
 public void setRefractionObject(String where, Object3D obj)
 {
     objectsRefractList[where] = obj;
 }
예제 #7
0
 public void setReflectionObject(String where, Object3D obj)
 {
     objectsMirrorList[where] = obj;
 }
예제 #8
0
        /// <summary>
        /// here we do text parsing of console and if we have a function
        /// we compile it and assign the function value to y coordinate
        /// of wave
        /// </summary>
        /// <param name="funDef">definition of function, source code or command</param>
        public void compile(String funDef)
        {
            //text parsing
            // first own commands
            bool ownCommandExecuted = false;

            /*
             * if (obj.getCurrentEffect() != null)
             * {
             *  foreach (DictionaryEntry de in engine.getCurrentEffect().getContainer().getCommands())
             *  {
             *      try
             *      {
             *          if (funDef.StartsWith((String)de.Key))
             *          {
             *              obj.getCurrentEffect().updateUniformData((String)de.Value, funDef.Substring(((String)de.Key).Length + 1));
             *              ownCommandExecuted = true;
             *          }
             *      }
             *      catch (Exception e)
             *      {
             *          statusWindow.loadString(e.Message);
             *          statusWindow.showStatusWindow();
             *      }
             *  }
             * }
             */
            if (!ownCommandExecuted)
            {
                // then build in commands
                if (funDef.StartsWith("help"))
                {
                    RenderEngine.Status.loadText("Readme.txt");
                    RenderEngine.Status.IsVisible = true;
                }

                /*
                 * insert own command code here
                 */
                /* for exercise
                 * else if (funDef.StartsWith("landscape"))
                 * {
                 *      if (funDef.Length > 9)
                 *      {
                 *              if (funDef.Substring(10).Equals("on"))
                 *              {
                 *                      engine.showLandscape(true);
                 *              }
                 *              else if (funDef.Substring(10).Equals("off"))
                 *              {
                 *                      engine.showLandscape(false);
                 *              }
                 *              else
                 *              {
                 *                      statusWindow.loadString("Error: not a valid command");
                 *                      statusWindow.showStatusWindow();
                 *              }
                 *      }
                 * }*/
                else if (funDef.StartsWith("fullscreen"))
                {
                    if (funDef.Length > 10)
                    {
                        if (funDef.Substring(11).Equals("on"))
                        {
                            engine.fullscreen(true);
                        }
                        else if (funDef.Substring(11).Equals("off"))
                        {
                            engine.fullscreen(false);
                        }
                        else
                        {
                            RenderEngine.Status.loadString("Error: not a valid command");
                            RenderEngine.Status.IsVisible = true;
                        }
                    }
                }
                else if (funDef.StartsWith("time"))
                {
                    if (funDef.Length > 4)
                    {
                        if (funDef.Substring(5).Equals("on"))
                        {
                            water.changeTimerProperty(true);
                        }
                        else if (funDef.Substring(5).Equals("off"))
                        {
                            water.changeTimerProperty(false);
                        }
                        else
                        {
                            RenderEngine.Status.loadString("Error: not a valid command");
                            RenderEngine.Status.IsVisible = true;
                        }
                    }
                }
                else if (funDef.StartsWith("quads"))
                {
                    try
                    {
                        water.changeQuadNumber(Convert.ToUInt16(funDef.Substring(6)));
                    }
                    catch (Exception e)
                    {
                        RenderEngine.Status.loadString(e.Message);
                        RenderEngine.Status.IsVisible = true;
                    }
                }
                else if (funDef.StartsWith("xgrid"))
                {
                    try
                    {
                        water.changeXGrid(Convert.ToSingle(funDef.Substring(6)));
                    }
                    catch (Exception e)
                    {
                        RenderEngine.Status.loadString(e.Message);
                        RenderEngine.Status.IsVisible = true;
                    }
                }
                else if (funDef.StartsWith("zgrid"))
                {
                    try
                    {
                        water.changeZGrid(Convert.ToSingle(funDef.Substring(6)));
                    }
                    catch (Exception e)
                    {
                        RenderEngine.Status.loadString(e.Message);
                        RenderEngine.Status.IsVisible = true;
                    }
                }
                else if (funDef.StartsWith("xstep"))
                {
                    try
                    {
                        water.changeXStep(Convert.ToSingle(funDef.Substring(6)));
                    }
                    catch (Exception e)
                    {
                        RenderEngine.Status.loadString(e.Message);
                        RenderEngine.Status.IsVisible = true;
                    }
                }
                else if (funDef.StartsWith("zstep"))
                {
                    try
                    {
                        water.changeZStep(Convert.ToSingle(funDef.Substring(6)));
                    }
                    catch (Exception e)
                    {
                        RenderEngine.Status.loadString(e.Message);
                        RenderEngine.Status.IsVisible = true;
                    }
                }
                else if (funDef.StartsWith("loadEffect"))
                {
                    try
                    {
                        String[]        paramLoadEffect = funDef.Split(' ');
                        Object3D        obj             = (Object3D)RenderEngine.ObjectList[paramLoadEffect[1]];
                        EffectContainer ec = new EffectContainer(RenderEngine.Game, engine.TextureManager, paramLoadEffect[2], true);
                        obj.setEffect(ec);
                        updateEffectStatus();
                    }
                    catch (Exception e)
                    {
                        RenderEngine.Status.loadString(e.Message);
                        RenderEngine.Status.IsVisible = true;
                    }
                }
                else if (funDef.StartsWith("deleteEffect"))
                {
                    try
                    {
                        String[] paramLoadEffect = funDef.Split(' ');
                        Object3D obj             = (Object3D)RenderEngine.ObjectList[paramLoadEffect[1]];
                        obj.setEffect(null);
                        updateEffectStatus();
                    }
                    catch (Exception e)
                    {
                        RenderEngine.Status.loadString(e.Message);
                        RenderEngine.Status.IsVisible = true;
                    }
                }
                else if (funDef.StartsWith("status"))
                {
                    if (funDef.Length > 6)
                    {
                        if (funDef.Substring(7).Equals("effects"))
                        {
                            updateEffectStatus();
                            RenderEngine.Status.IsVisible = true;
                        }
                        else if (funDef.Substring(7).Equals("functions"))
                        {
                            RenderEngine.Status.loadList(funString, funShort);
                            RenderEngine.Status.IsVisible = true;
                        }
                    }
                }
                else if (funDef.StartsWith("remove"))
                {
                    if (funDef.Length > 6)
                    {
                        if (funDef.Substring(7).Equals("all"))
                        {
                            funActive.Clear();
                            funString.Clear();
                            RenderEngine.Status.loadList(funString, funShort);
                        }
                        else if (funDef.Substring(7, 1).Equals("A"))
                        {
                            try
                            {
                                funActive.RemoveAt(Convert.ToInt32(funDef.Substring(8)));
                                funString.RemoveAt(Convert.ToInt32(funDef.Substring(8)));
                                RenderEngine.Status.loadList(funString, funShort);
                            }
                            catch (Exception e)
                            {
                                RenderEngine.Status.loadString(e.Message);
                                RenderEngine.Status.IsVisible = true;
                            }
                        }
                        else
                        {
                            RenderEngine.Status.loadString("Error: not a valid command");
                            RenderEngine.Status.IsVisible = true;
                        }
                    }
                }
                else
                {
                    String sourceCode = "";
                    // code for function compiling
                    if (funDef.Contains("F")) // replace shortkeys with real function name
                    {
                        String help = funDef;
                        while (help.Contains("F"))
                        {
                            if ((String)funShort[help.Substring(help.IndexOf("F"), 2)] != null) // F - String is real shortcut
                            {
                                funDef = funDef.Replace(help.Substring(help.IndexOf("F"), 2), (String)funShort[help.Substring(help.IndexOf("F"), 2)]);
                                help   = help.Substring(help.IndexOf("F") + 1);
                            }
                            else
                            {
                                help = help.Substring(help.IndexOf("F") + 1);
                            }
                        }
                    }
                    // code for source compiling
                    if (funDef.Contains("C")) // replace shortkeys with real function name
                    {
                        int    codeCount = 0;
                        String help      = funDef;
                        while (help.Contains("C"))
                        {
                            if ((String)funShort[help.Substring(help.IndexOf("C"), 2)] != null) // C - String is real shortcut
                            {
                                funDef = funDef.Replace(help.Substring(help.IndexOf("C"), 2), (String)funShort[help.Substring(help.IndexOf("C"), 2)]);
                                help   = help.Substring(help.IndexOf("C") + 1);
                                codeCount++;
                            }
                            else
                            {
                                help = help.Substring(help.IndexOf("C") + 1);
                            }
                        }
                        // String contains shortkey for source code
                        if (codeCount > 0)
                        {
                            sourceCode = funDef;
                            funDef     = "0.0";
                        }
                    }

                    if (funDef.Equals("compile"))
                    {
                        sourceCode = RenderEngine.Code.getSourceCode();
                        funDef     = "0.0"; // indicates that we must compile source code
                    }
                    // remove whitespaces for functions, so Math.Sin(x) is the same as Math.Sin( x )
                    funDef = funDef.Replace(" ", "");

                    // Chapter 4.6, Listing 4.6.2
                    // code for function and source compiling
                    //funTable cant contain "" or "0.0" so this is allowed
                    if (!funTable.ContainsKey(funDef) && !funTable.ContainsKey(sourceCode))
                    {
                        // Template code including dummies for function and code string
                        String source = "using System; using OwnFunctions; namespace Water3D {public class CompiledExpression {public static double f(double x, double z, double t) {###s###; return ###f###;}}}";

                        // replace dummy with function
                        source = source.Replace("###s###", sourceCode);
                        source = source.Replace("###f###", funDef);

                        // generate c# code provider to create the compiler
                        CSharpCodeProvider provider = new CSharpCodeProvider();

                        // set compiler parameters
                        CompilerParameters cps = new CompilerParameters();
                        cps.GenerateInMemory = true;
                        cps.ReferencedAssemblies.Add("System.dll");
                        cps.ReferencedAssemblies.Add("OwnFunctions.dll");

                        //compile code
                        CompilerResults cr = provider.CompileAssemblyFromSource(cps, source);

                        //look for compile errors
                        if (cr.Errors.Count > 0)
                        {
                            String text = "Compile Errors:\n";
                            for (int i = 0; i < cr.Errors.Count; i++)
                            {
                                text += cr.Errors[i].ErrorText + "\n";
                            }

                            RenderEngine.Status.loadString(text);
                            RenderEngine.Status.IsVisible = true;
                            f = null;
                        }
                        else
                        {
                            Type cet = cr.CompiledAssembly.GetType("Water3D.CompiledExpression");

                            f = (fDelegate)System.Delegate.CreateDelegate(typeof(fDelegate), cet.GetMethod("f", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static));

                            // normal function
                            if (!funDef.Equals("0.0") && sourceCode.Equals(""))
                            {
                                funActive.Add(f);
                                funString.Add(funDef);
                                funShort.Add("F" + shortFunIt, funDef);
                                funTable.Add(funDef, f);
                                shortFunIt++;
                            }
                            // code snippet
                            if (funDef.Equals("0.0") && !sourceCode.Equals(""))
                            {
                                funActive.Add(f);
                                funString.Add(sourceCode);
                                funShort.Add("C" + shortCodeIt, sourceCode);
                                funTable.Add(sourceCode, f);
                                shortCodeIt++;
                            }
                            RenderEngine.Status.loadList(funString, funShort);
                        }
                    }
                    else // we dont need to compile
                    {
                        if (!funDef.Equals("0.0") && sourceCode.Equals(""))
                        {
                            funActive.Add((fDelegate)funTable[funDef]);
                            funString.Add(funDef);
                            RenderEngine.Status.loadList(funString, funShort);
                        }
                        if (funDef.Equals("0.0") && !sourceCode.Equals(""))
                        {
                            funActive.Add((fDelegate)funTable[sourceCode]);
                            funString.Add(sourceCode);
                            RenderEngine.Status.loadList(funString, funShort);
                        }
                    }
                }
            }
        }