/// <summary> /// Add object to render /// </summary> /// <param name="modelName">Model name</param> /// <param name="rotation">Rotation</param> /// <param name="trackPos">Track position</param> /// <param name="trackRight">Track right</param> /// <param name="distance">Distance</param> public void AddObjectToRender(string modelName, float rotation, Vector3 trackPos, Vector3 trackRight, float distance) { // Find out size float objSize = 1; // Search for combos for (int num = 0; num < combos.Length; num++) { TrackCombiModels combi = combos[num]; //slower: if (StringHelper.Compare(combi.Name, modelName)) if (combi.Name == modelName) { objSize = combi.Size; break; } } // Search model by name! for (int num = 0; num < landscapeModels.Length; num++) { Model model = landscapeModels[num]; //slower: if (StringHelper.Compare(model.Name, modelName)) if (model.Name == modelName) { objSize = model.Size; break; } } // Make sure it is away from the road. if (distance > 0 && distance - 10 < objSize) { distance += objSize; } if (distance < 0 && distance + 10 > -objSize) { distance -= objSize; } AddObjectToRender(modelName, Matrix.CreateRotationZ(rotation) * Matrix.CreateTranslation( trackPos + trackRight * distance + new Vector3(0, 0, -100)), false); }
/// <summary> /// Add object to render /// </summary> /// <param name="modelName">Model name</param> /// <param name="renderMatrix">Render matrix</param> /// <param name="isNearTrack">Is near track</param> public void AddObjectToRender(string modelName, Matrix renderMatrix, bool isNearTrackForShadowGeneration) { // Fix wrong model names if (modelName == "OilWell") { modelName = "OilPump"; } else if (modelName == "PalmSmall") { modelName = "AlphaPalmSmall"; } else if (modelName == "AlphaPalm4") { modelName = "AlphaPalmSmall"; } else if (modelName == "Palm") { modelName = "AlphaPalm"; } else if (modelName == "Casino") { modelName = "Casino01"; } else if (modelName == "Combi") { modelName = "CombiPalms"; } // Always include windmills and buildings for shadow generation if (modelName.ToLower() == "windmill" || modelName.ToLower().Contains("hotel") || modelName.ToLower().Contains("building") || modelName.ToLower().Contains("casino01")) { isNearTrackForShadowGeneration = true; } // Search for combos for (int num = 0; num < combos.Length; num++) { TrackCombiModels combi = combos[num]; //slower: if (StringHelper.Compare(combi.Name, modelName)) if (combi.Name == modelName) { // Add all combi objects (calls this method for each model) combi.AddAllModels(this, renderMatrix); // Thats it. return; } } Model foundModel = null; // Search model by name! for (int num = 0; num < landscapeModels.Length; num++) { Model model = landscapeModels[num]; //slower: if (StringHelper.Compare(model.Name, modelName)) if (model.Name == modelName) { foundModel = model; break; } } // Only add if we found the model if (foundModel != null) { // Fix z position to be always ABOVE the landscape Vector3 modelPos = renderMatrix.Translation; // Get landscape height here float landscapeHeight = GetMapHeight(modelPos.X, modelPos.Y); // And make sure we are always above it! if (modelPos.Z < landscapeHeight) { modelPos.Z = landscapeHeight; // Fix render matrix renderMatrix.Translation = modelPos; } // Check if another object is nearby, then skip this one! // Don't skip signs or banners! if (modelName.StartsWith("Banner") == false && modelName.StartsWith("Sign") == false && modelName.StartsWith("StartLight") == false) { for (int num = 0; num < landscapeObjects.Count; num++) { if (Vector3.DistanceSquared( landscapeObjects[num].Position, modelPos) < foundModel.Size * foundModel.Size / 4) { // Don't add return; } } } LandscapeObject newObject = new LandscapeObject(foundModel, // Scale all objects up a little (else world is not filled enough) Matrix.CreateScale(1.2f) * renderMatrix); // Add landscapeObjects.Add(newObject); // Add again to the nearTrackObjects list if near the track if (isNearTrackForShadowGeneration) { nearTrackObjects.Add(newObject); } if (modelName.StartsWith("StartLight")) { startLightObject = newObject; } } #if DEBUG else if (modelName.Contains("Track") == false) { // Add warning in log file Log.Write("Landscape model " + modelName + " is not supported and " + "can't be added for rendering!"); } #endif }