public override bool Compute() { Variable temp = Controller.allVars[Controller.currentZomb][output]; //create temp variable if (x != null) { temp.vec3_value.x = x.Calculate(); //if there is a mathematical equation for the x value } else { temp.vec3_value.x = Controller.allVars[Controller.currentZomb][input].vec3_value.x; //set to input x value } if (y != null) { temp.vec3_value.y = y.Calculate(); //if there is a mathematical equation for the y value } else { temp.vec3_value.y = Controller.allVars[Controller.currentZomb][input].vec3_value.y; //set to input y value } if (z != null) { temp.vec3_value.z = z.Calculate(); //if there is a mathematical equation for the z value } else { temp.vec3_value.z = Controller.allVars[Controller.currentZomb][input].vec3_value.z; //set to input z value } temp.type = Variable.VariableType.VEC3; Controller.allVars[Controller.currentZomb][output] = temp; //set output return(true); }
//Method to get LHS value private float LeftValue() { if (lhs != null) //if there is another equation on the lhs { return(lhs.Calculate()); //calculate lhs } else if (varLHS != "") //if there is a variable in the lhs { //Return a the correct value based on variable type switch (Controller.allVars[Controller.currentZomb][varLHS].type) { case Variable.VariableType.FLOAT: return(Controller.allVars[Controller.currentZomb][varLHS].flt_value); case Variable.VariableType.INT: return(Controller.allVars[Controller.currentZomb][varLHS].int_value); case Variable.VariableType.VEC3: //Return the correct vector part switch (vectorLHS) { case Code_if.VectorPart.x: return(Controller.allVars[Controller.currentZomb][varLHS].vec3_value.x); case Code_if.VectorPart.y: return(Controller.allVars[Controller.currentZomb][varLHS].vec3_value.y); case Code_if.VectorPart.z: return(Controller.allVars[Controller.currentZomb][varLHS].vec3_value.z); } break; } } return(fLHS); //return the float value of the lhs }
static void Main(string[] args) { Mathematics math = new Mathematics(); WorkDelegate work = math.Calculate; math.Calculate('+', 10, 5); work('+', 10, 5); math.Calculate('-', 10, 5); work('-', 10, 5); math.Calculate('*', 10, 5); work('*', 10, 5); math.Calculate('/', 10, 5); work('/', 10, 5); }
//get true or false value if if public bool getValue() { if (ifType == Logic.NONE) //if there is no logic for this if { return(ifLHS.getValue()); } if (compareValues == Variable.VariableType.BOOL) //compare booleans { return(CompareBools()); } else if (compareValues == Variable.VariableType.FLOAT) //compare float, int or vec3 { if (lhs != "") { nbr_lhsvalue = LhsValue(); } else if (mathLHS != null) { nbr_lhsvalue = mathLHS.Calculate(); } if (rhs != "") { nbr_rhsvalue = RhsValue(); } else if (mathRHS != null) { nbr_rhsvalue = mathRHS.Calculate(); } return(CompareFloats(nbr_lhsvalue, nbr_rhsvalue)); } else if (compareValues == Variable.VariableType.STRING) //compare strings { if (lhs != "") { str_lhsvalue = Controller.allVars[Controller.currentZomb][lhs].str_value; } if (rhs != "") { str_rhsvalue = Controller.allVars[Controller.currentZomb][rhs].str_value; } switch (ifType) { case Logic.EQUAL: return(str_lhsvalue == str_rhsvalue); case Logic.NOT: return(str_lhsvalue != str_rhsvalue); } } //if all else fails to return anything return false return(false); }
//Method to calculate result from equation public override bool Compute() { //make temp variable Variable temp = Controller.allVars[Controller.currentZomb][output]; //change variable type if (changeType) { temp.type = newType; } //Set the right part of the variable switch (temp.type) { case Variable.VariableType.FLOAT: temp.flt_value = maths.Calculate(); break; case Variable.VariableType.INT: temp.int_value = (int)maths.Calculate(); break; case Variable.VariableType.VEC3: switch (vPart) { case Code_if.VectorPart.x: temp.vec3_value.x = maths.Calculate(); break; case Code_if.VectorPart.y: temp.vec3_value.y = maths.Calculate(); break; case Code_if.VectorPart.z: temp.vec3_value.z = maths.Calculate(); break; } break; } Controller.allVars[Controller.currentZomb][output] = temp; //set variable return(true); }