private static bool ReadProperty(StreamReader rdr, JObject tmp) { string key = JsonReader.ReadString(rdr); if (key != null && !tmp.properties.ContainsKey(key)) { JsonReader.SpinWhiteSpace(rdr); if (rdr.Read() == (int)':') { JsonReader.SpinWhiteSpace(rdr); JEntity value = null; bool wasNull = false; int c = rdr.Peek(); if (c == (int)'"') { value = JPrimitive.Read(rdr); //its a string! } else if (c == (int)'[') { value = JArray.Read(rdr); } else if (c == (int)'{') { value = JObject.Read(rdr); } else if (c == (int)'-' || (c >= 48 && c <= 57)) //- or ascii for 0-9 -- should be a number { value = JPrimitive.Read(rdr); } else if (c == (int)'t') //should be "true" { value = JPrimitive.Read(rdr); } else if (c == (int)'f') //should be "false" { value = JPrimitive.Read(rdr); } else if (c == (int)'n') //should be "null" { wasNull = true; if (!JsonReader.ReadNull(rdr)) { return(false); //looked like a null, but wasn't } } else { return(false); //unrecognized starting char } if (value != null || wasNull) { tmp.properties.Add(key, value); return(true); } //property wasn't "null", but we didn't get anything read - that's an error } } return(false); //didn't get a key back }
public void Select(JLoader loader) { JModelTexture texture = new JModelTexture(loader.loadTexture(SphereTexturePathSelected)); SphereTexturedModel = new JTexturedModel(SphereModel, texture); SphereEntity = new JEntity(SphereTexturedModel, SphereEntity.Position, new Vector3(0, 0, 1), 0.5f); }
public HttpResponseMessage Update_Account(JObject jsonData) { var account = JEntity <Account> .Instance().Get_Entity(jsonData); return(new HttpResponseMessage { Content = new StringContent(UserService.Update(account).JsonSerialize()) }); }
private void prepareInstance(JEntity entity) { //Matrix4 transformationMatrix = JMathUtils.createTransformationMatrix(entity.Position, entity.RotX, entity.RotY, entity.RotZ, entity.Scale); //JMathUtils.testTransformationMatrix(entity.Position, entity.Orientation, entity.Scale); Matrix4 transformationMatrix = JMathUtils.testTransformationMatrix(entity.Position, entity.Orientation, entity.Scale); Shader.LoadTransformationMatrix(transformationMatrix); }
/// <summary> /// Load the model and texture of the JBoundingSphere if we want to render it in the world. /// </summary> /// <param name="loader"></param> public void LoadSphereModel(JLoader loader) { SphereModelData = JObjFileLoader.LoadObj(SphereModelPath); SphereModel = loader.LoadToVAO(SphereModelData.Vertices, SphereModelData.TextureCoords, SphereModelData.Normals, SphereModelData.Indices); JModelTexture texture = new JModelTexture(loader.loadTexture(SphereTexturePathUnselected)); SphereTexturedModel = new JTexturedModel(SphereModel, texture); SphereEntity = new JEntity(SphereTexturedModel, new Vector3(50, 0, -50), new Vector3(0, 0, 1), 0.5f); }
private static bool ReadElement(StreamReader rdr, JArray tmp) { JsonReader.SpinWhiteSpace(rdr); JEntity element = null; int cur = rdr.Peek(); if (cur == (int)'"') { element = JPrimitive.Read(rdr); //its a string! } else if (cur == (int)'{') { element = JObject.Read(rdr); } else if (cur == (int)'[') { element = JArray.Read(rdr); } else if (cur == (int)'-' || (cur >= 48 && cur <= 57)) //- or ascii for 0-9 -- should be a number { element = JPrimitive.Read(rdr); } else if (cur == (int)'t') //should be "true" { element = JPrimitive.Read(rdr); } else if (cur == (int)'f') //should be "false" { element = JPrimitive.Read(rdr); } else if (cur == (int)'n') //should be "null" { if (JsonReader.ReadNull(rdr)) { tmp.elements.Add(null); return(true); //one off case here due to a literal null element } //looked like a null, but wasn't - so we fall through fail } if (element != null) { tmp.elements.Add(element); return(true); } return(false); }
public JCameraThirdPerson(JEntity player) { MouseWheelPreviousPosition = 0; MouseYPreviousPosition = 0; MouseXPreviousPosition = 0; Pitch = 0; Yaw = 0; Roll = 0; DistanceFromPlayer = 35; AngleAroundPlayer = 0; Player = player; Position = new Vector3(10, 10, 10); }
public void ProcessEntity(JEntity entity) { JTexturedModel texturedModel = entity.TexturedModel; try { List <JEntity> batch = Entities[texturedModel]; batch.Add(entity); } catch (KeyNotFoundException e) { List <JEntity> newBatch = new List <JEntity> { entity }; Entities.Add(texturedModel, newBatch); } }
/// <summary> /// /// </summary> /// <returns></returns> public List <JEntity> GenerateTrees() { Console.WriteLine("Generating Trees..."); List <JEntity> TreeEntities = new List <JEntity>(); string TreeTexturePath = JFileUtils.GetPathToResFile("Tree\\tree_texture_green_brown.png"); string TreeModelPath = JFileUtils.GetPathToResFile("Tree\\tree.obj"); JModelData TreeModelData = JObjFileLoader.LoadObj(TreeModelPath); JRawModel TreeModel = Loader.LoadToVAO(TreeModelData.Vertices, TreeModelData.TextureCoords, TreeModelData.Normals, TreeModelData.Indices); JModelTexture TreeTexture = new JModelTexture(Loader.loadTexture(TreeTexturePath)); JTexturedModel TreeTexturedModel = new JTexturedModel(TreeModel, TreeTexture); Random r = new Random(); for (int i = 0; i < 200; i++) { float posX = (float)r.NextDouble() * 800; float posZ = -(float)r.NextDouble() * 800; float posY = Terrain.GetHeightOfTerrain(posX, posZ); while (posY < WaterTile.Height) { posX = (float)r.NextDouble() * 800; posZ = -(float)r.NextDouble() * 800; posY = Terrain.GetHeightOfTerrain(posX, posZ); } Vector3 orientation = new Vector3((float)r.NextDouble(), 0, (float)r.NextDouble()); orientation.NormalizeFast(); JEntity entity = new JEntity(TreeTexturedModel, new Vector3(posX, posY, posZ), orientation, 0.25f); TreeEntities.Add(entity); } return(TreeEntities); }
private object BuildArray(JArray o, bool hasDecimal) { if (hasDecimal) //try float, then double, then give up { List <float> sVals = new List <float>(); for (int i = 0; i < o.Count; i++) { JEntity e = o[i]; if (e != null && e is JPrimitive) { JPrimitive p = (JPrimitive)e; if (p.Type == JType.JNumber) { try { sVals.Add(p.ToFloat()); } catch { sVals.Clear(); sVals = null; //just in case a GC run comes along List <double> kVals = new List <double>(); for (int j = 0; j < o.Count; j++) { e = o[j]; if (e != null && e is JPrimitive) { p = (JPrimitive)e; if (p.Type == JType.JNumber) { try { kVals.Add(p.ToDouble()); } catch { return(null); //not an integer type we can handle } } else { return(null); //short circuit early } } else { return(null); //short circuit early } } return(kVals.ToArray()); } } else { return(null); //short circuit early } } else { return(null); //short circuit early } } return(sVals.ToArray()); } else //try int, then long, then give up { //try ints first, then widen if needed List <int> sVals = new List <int>(); for (int i = 0; i < o.Count; i++) { JEntity e = o[i]; if (e != null && e is JPrimitive) { JPrimitive p = (JPrimitive)e; if (p.Type == JType.JNumber) { try { sVals.Add(p.ToInt()); } catch { if (p.ToString().IndexOf('.') >= 0) { return(null); //not an integer type } else //widen and try longs { sVals.Clear(); sVals = null; //just in case a GC run comes along List <long> kVals = new List <long>(); for (int j = 0; j < o.Count; j++) { e = o[j]; if (e != null && e is JPrimitive) { p = (JPrimitive)e; if (p.Type == JType.JNumber) { try { kVals.Add(p.ToLong()); } catch { return(null); //not an integer type we can handle } } else { return(null); //short circuit early } } else { return(null); //short circuit early } } return(kVals.ToArray()); } } } else { return(null); //short circuit early } } else { return(null); //short circuit early } } return(sVals.ToArray()); } }
private object BuildArray(JArray o) { JType lookType = JType.JString; if (o.Count > 0) { if (o[0] is JPrimitive) { JPrimitive p = (JPrimitive)o[0]; lookType = p.Type; } } if (lookType == JType.JString) { List <string> sVals = new List <string>(); for (int i = 0; i < o.Count; i++) { JEntity e = o[i]; if (e != null && e is JPrimitive) { JPrimitive p = (JPrimitive)e; if (p.Type == JType.JString) { sVals.Add(p.ToString()); } else { return(null); //short circuit early } } else { return(null); //short circuit early } } return(sVals.ToArray()); } else if (lookType == JType.JBool) { List <bool> sVals = new List <bool>(); for (int i = 0; i < o.Count; i++) { JEntity e = o[i]; if (e != null && e is JPrimitive) { JPrimitive p = (JPrimitive)e; if (p.Type == JType.JString) { sVals.Add(p.ToBool()); } else { return(null); //short circuit early } } else { return(null); //short circuit early } } return(sVals.ToArray()); } else //number { object res = BuildArray(o, false); if (res == null) { res = BuildArray(o, true); } if (res == null) { return(null); } } return(null); }
private object BuildDictionary(JObject o, bool hasDecimal) { if (hasDecimal) //try float, then double, then give up { Dictionary <string, float> sVals = new Dictionary <string, float>(); foreach (string key in o.Keys) { JEntity e = o[key]; if (e != null && e is JPrimitive) { JPrimitive p = (JPrimitive)e; if (p.Type == JType.JNumber) { try { sVals.Add(key, p.ToFloat()); } catch { sVals.Clear(); sVals = null; //just in case a GC run comes along Dictionary <string, double> kVals = new Dictionary <string, double>(); foreach (string key2 in o.Keys) { e = o[key2]; if (e != null && e is JPrimitive) { p = (JPrimitive)e; if (p.Type == JType.JNumber) { try { kVals.Add(key, p.ToDouble()); } catch { return(null); //not an integer type we can handle } } else { return(null); //short circuit early } } else { return(null); //short circuit early } } return(kVals); } } else { return(null); //short circuit early } } else { return(null); //short circuit early } } return(sVals); } else //try int, then long, then give up { //try ints first, then widen if needed Dictionary <string, int> sVals = new Dictionary <string, int>(); foreach (string key in o.Keys) { JEntity e = o[key]; if (e != null && e is JPrimitive) { JPrimitive p = (JPrimitive)e; if (p.Type == JType.JNumber) { try { sVals.Add(key, p.ToInt()); } catch { if (p.ToString().IndexOf('.') >= 0) { return(null); //not an integer type } else //widen and try longs { sVals.Clear(); sVals = null; //just in case a GC run comes along Dictionary <string, long> kVals = new Dictionary <string, long>(); foreach (string key2 in o.Keys) { e = o[key2]; if (e != null && e is JPrimitive) { p = (JPrimitive)e; if (p.Type == JType.JNumber) { try { kVals.Add(key, p.ToLong()); } catch { return(null); //not an integer type we can handle } } else { return(null); //short circuit early } } else { return(null); //short circuit early } } return(kVals); } } } else { return(null); //short circuit early } } else { return(null); //short circuit early } } return(sVals); } }
private object BuildDictionary(JObject o) { JType lookType = JType.JString; foreach (string s in o.Keys) { JEntity e = o[s]; if (e != null) { if (e is JPrimitive) //only thing currently supported { JPrimitive p = (JPrimitive)e; lookType = p.Type; } else { return(null); //fail fast } break; //end the loop anyway -- only needed to see the type of the first element } return(null); //got a null thing - which shouldn't be in the config } if (lookType == JType.JString) { Dictionary <string, string> sVals = new Dictionary <string, string>(); foreach (string key in o.Keys) { JEntity e = o[key]; if (e != null && e is JPrimitive) { JPrimitive p = (JPrimitive)e; if (p.Type == JType.JString) { sVals.Add(key, p.ToString()); } else { return(null); //short circuit early } } else { return(null); //short circuit early } } return(sVals); } else if (lookType == JType.JBool) { Dictionary <string, bool> sVals = new Dictionary <string, bool>(); foreach (string key in o.Keys) { JEntity e = o[key]; if (e != null && e is JPrimitive) { JPrimitive p = (JPrimitive)e; if (p.Type == JType.JBool) { sVals.Add(key, p.ToBool()); } else { return(null); //short circuit early } } else { return(null); //short circuit early } } return(sVals); } else //number { object res = BuildDictionary(o, false); if (res == null) { res = BuildDictionary(o, true); } if (res == null) { return(null); } } return(null); }
internal bool Init(string filename) { //format of file is specific for config params JsonReader r = new JsonReader(); JObject o = r.Read(filename); if (o != null) { foreach (string s in o.Keys) //types { JEntity e = o[s]; if (e != null && e is JObject) { Dictionary <string, object> parms = new Dictionary <string, object>(); if (!this.configs.ContainsKey(s)) { this.configs.Add(s, parms); } else { parms = this.configs[s]; } JObject cur = (JObject)e; foreach (string k in cur.Keys) //param names { e = cur[k]; //now it's a param object paramData = null; if (e != null) { if (e is JObject) //treat as dictionary { JObject param = (JObject)e; paramData = BuildDictionary(param); if (paramData != null) { parms[k] = paramData; } else { return(false); } } else if (e is JArray) //as array { JArray param = (JArray)e; paramData = BuildArray(param); if (paramData != null) { parms[k] = paramData; } else { return(false); } } else //JPrimitive { JPrimitive param = (JPrimitive)e; if (param != null) { if (param.Type == JType.JString) { parms[k] = param.ToString(); } else if (param.Type == JType.JNumber) { try { int i = param.ToInt(); parms[k] = i; } catch { try { long l = param.ToLong(); parms[k] = l; } catch { try { float f = param.ToFloat(); parms[k] = f; } catch { try { double d = param.ToDouble(); parms[k] = d; } catch { return(false); } } } } } else if (param.Type == JType.JBool) { parms[k] = param.ToBool(); } } else { return(false); } } } } } else { return(false); //we read it all, or none } } return(true); } return(false); }