public void Relocate(TGCVector4 newPosition) { this.posicion = new TGCVector3(newPosition.X, newPosition.Y, newPosition.Z); this.rotacion = new TGCVector3(0, newPosition.W, 0); posicionArma.TryGetValue(new Tuple <string, float>(this.Scene.SceneName, newPosition.W), out posicionInicialArma); arma.Move(this.posicion + posicionInicialArma); }
private TGCVector4 GetTowerPosition() { TGCVector4 temp = posicionesTorres[new Random().Next(posicionesTorres.Count)]; temp.Z += this.GetOffsetVectorMoved().Z; return(temp); }
/// <summary> /// Convierte los weights del vertice en dos Vector4, uno con los valores de los weights y otro con los indices de los /// huesos. /// Si tiene menos de 4 weights completa con 0. /// </summary> /// <param name="blendWeights">Valores de Weights</param> /// <param name="blendIndices">Indices de huesos</param> public void createVector4WeightsAndIndices(out TGCVector4 blendWeights, out TGCVector4 blendIndices) { blendWeights = new TGCVector4( getBlendWeight(0), getBlendWeight(1), getBlendWeight(2), getBlendWeight(3) ); blendIndices = new TGCVector4( getBlendIndex(0), getBlendIndex(1), getBlendIndex(2), getBlendIndex(3) ); }
public override void Render() { PreRender(); //Habilitar luz var lightEnable = lightEnableModifier.Value; Effect currentShader; string currentTechnique; if (lightEnable) { //Shader personalizado de iluminacion currentShader = effect; currentTechnique = "MultiDiffuseLightsTechnique"; } else { //Sin luz: Restaurar shader default currentShader = TGCShaders.Instance.TgcMeshShader; currentTechnique = TGCShaders.Instance.GetTGCMeshTechnique(TgcMesh.MeshRenderType.DIFFUSE_MAP); } //Aplicar a cada mesh el shader actual foreach (var mesh in scene.Meshes) { mesh.Effect = currentShader; mesh.Technique = currentTechnique; } //Configurar los valores de cada luz var move = new TGCVector3(0, 0, lightMoveModifier.Value ? interp.update(ElapsedTime) : 0); var lightColors = new ColorValue[lightMeshes.Length]; var pointLightPositions = new TGCVector4[lightMeshes.Length]; var pointLightIntensity = new float[lightMeshes.Length]; var pointLightAttenuation = new float[lightMeshes.Length]; for (var i = 0; i < lightMeshes.Length; i++) { var lightMesh = lightMeshes[i]; lightMesh.Position = origLightPos[i] + TGCVector3.Scale(move, i + 1); lightMesh.Transform = TGCMatrix.Translation(lightMesh.Position); lightColors[i] = ColorValue.FromColor(lightMesh.Color); pointLightPositions[i] = TGCVector3.TGCVector3ToTGCVector4(lightMesh.Position); pointLightIntensity[i] = lightIntensityModifier.Value; pointLightAttenuation[i] = lightAttenuationModifier.Value; } //Renderizar meshes foreach (var mesh in scene.Meshes) { mesh.UpdateMeshTransform(); if (lightEnable) { //Cargar variables de shader mesh.Effect.SetValue("lightColor", lightColors); mesh.Effect.SetValue("lightPosition", TGCVector4.TGCVector4ArrayToVector4Array(pointLightPositions)); mesh.Effect.SetValue("lightIntensity", pointLightIntensity); mesh.Effect.SetValue("lightAttenuation", pointLightAttenuation); mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(mEmissiveModifier.Value)); mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(mDiffuseModifier.Value)); } //Renderizar modelo mesh.Render(); } //Renderizar meshes de luz for (var i = 0; i < lightMeshes.Length; i++) { var lightMesh = lightMeshes[i]; lightMesh.Render(); } PostRender(); }
public override void Render() { PreRender(); //Habilitar luz var lightEnable = lightEnableModifier.Value; Effect currentShader; string currentTechnique; if (lightEnable) { //Shader personalizado de iluminacion currentShader = effect; currentTechnique = "ThreeLightsTechnique"; } else { //Sin luz: Restaurar shader default currentShader = TGCShaders.Instance.TgcMeshShader; currentTechnique = TGCShaders.Instance.GetTGCMeshTechnique(TgcMesh.MeshRenderType.DIFFUSE_MAP); } //Aplicar a cada mesh el shader actual foreach (var meshData in meshesWithLight) { meshData.mesh.Effect = currentShader; meshData.mesh.Technique = currentTechnique; } var eyePosition = Camera.Position; //Renderizar meshes con BumpMapping foreach (var meshData in meshesWithLight) { var mesh = meshData.mesh; if (true) //FIXME da error cuando se desabilitan las luces.) (lightEnable) { mesh.Effect.SetValue("eyePosition", TGCVector3.TGCVector3ToFloat4Array(eyePosition)); mesh.Effect.SetValue("bumpiness", bumpinessModifier.Value); mesh.Effect.SetValue("reflection", reflectionModifier.Value); //Cargar variables de shader del Material mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(mEmissiveModifier.Value)); mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(mAmbientModifier.Value)); mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(mDiffuseModifier.Value)); mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(mSpecularModifier.Value)); mesh.Effect.SetValue("materialSpecularExp", specularExModifier.Value); //CubeMap mesh.Effect.SetValue("texCubeMap", cubeMap); //Cargar variables de shader de las 3 luces //Intensidad y atenuacion deberian ser atributos propios de cada luz var lightIntensity = lightIntensityModifier.Value; var lightAttenuation = lightAttenuationModifier.Value; mesh.Effect.SetValue("lightIntensity", new[] { lightIntensity, lightIntensity, lightIntensity }); mesh.Effect.SetValue("lightAttenuation", new[] { lightAttenuation, lightAttenuation, lightAttenuation }); mesh.Effect.SetValue("lightColor", new[] { ColorValue.FromColor(meshData.lights[0].color), ColorValue.FromColor(meshData.lights[1].color), ColorValue.FromColor(meshData.lights[2].color) }); mesh.Effect.SetValue("lightPosition", TGCVector4.TGCVector4ArrayToVector4Array( new[] { TGCVector3.TGCVector3ToTGCVector4(meshData.lights[0].pos), TGCVector3.TGCVector3ToTGCVector4(meshData.lights[1].pos), TGCVector3.TGCVector3ToTGCVector4(meshData.lights[2].pos) })); } //Renderizar modelo mesh.Render(); } //Renderizar meshes comunes foreach (var mesh in commonMeshes) { mesh.Render(); } PostRender(); }