omnidirectional light

Sep 4, 2010 at 10:51 PM

i'm following your tutorial http://www.ingebrigtsen.info/post/2010/08/01/Balder-Tutorial-Creating-a-Mesh-programatically.aspx#comment . it's really good even for a newbie like me but i cant get the light rendering. the color of the box is always the same even if i change the light color to black for istance. 

i'm using sl4 , vs2010 and balder 0.8.8.8

my xaml:

(i copyed a little from comments :D )

<UserControl x:Class="baldertest2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Execution="clr-namespace:Balder.Execution;assembly=Balder"
    xmlns:View="clr-namespace:Balder.View;assembly=Balder"
    xmlns:Custom="clr-namespace:baldertest2"
    xmlns:Lighting="clr-namespace:Balder.Lighting;assembly=Balder" 
    xmlns:Materials="clr-namespace:Balder.Materials;assembly=Balder" 
    xmlns:Geometries="clr-namespace:Balder.Objects.Geometries;assembly=Balder" 
    xmlns:Animation="clr-namespace:Balder.Animation.Silverlight;assembly=Balder" 
    mc:Ignorable="d"
    d:DesignHeight="484" d:DesignWidth="644">

    <Grid x:Name="LayoutRoot" Background="White">
        <Execution:Game Width="640" Height="480">
            <Execution:Game.Camera>
                <View:Camera Position="-10,0,-20"></View:Camera>
            </Execution:Game.Camera>
            <Lighting:OmniLight Position="0,2,-10" Strength="0.6" Diffuse="Green" />
            <Custom:MyBox Color="Blue"/>
                           

            
        </Execution:Game>
    </Grid>
</UserControl>

my c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Balder.Objects.Geometries;
using Balder.Display;
using Balder.Math;
using Balder.Materials;

namespace baldertest2
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            
        }
    }

    public class MyBox : Balder.Objects.Geometries.Geometry
    {
        public override void Prepare(Viewport viewport)
        {
            PrepareFR();
            GeometryHelper.CalculateFaceNormals(FullDetailLevel);
            GeometryHelper.CalculateVertexNormals(FullDetailLevel);
        } 
        public void PrepareFR()
        {
            GenerateVertices();
            GenerateLines();
            GenerateFaces();
            
            //Face f = null; 
            //for (int i = 0; i < FullDetailLevel.FaceCount; i++)
            //{
            //    f = FullDetailLevel.GetFace(i);
            //    f.Material = new Material();
            //    f.Material.Ambient = Colors.Orange;
            //    f.Material.Diffuse = Colors.Orange;
            //    f.Material.Opacity = 1;
            //}
        }

        private void GenerateVertices()
        {
            var dimensionAsVector = new Vector(5f, 5f, 5f);
            var halfDimension = dimensionAsVector / 2f;
            var frontUpperLeft = new Vertex(-halfDimension.X, halfDimension.Y, -halfDimension.Z);
            var frontUpperRight = new Vertex(halfDimension.X, halfDimension.Y, -halfDimension.Z);
            var frontLowerLeft = new Vertex(-halfDimension.X, -halfDimension.Y, -halfDimension.Z);
            var frontLowerRight = new Vertex(halfDimension.X, -halfDimension.Y, -halfDimension.Z);
            var backUpperLeft = new Vertex(-halfDimension.X, halfDimension.Y, halfDimension.Z);
            var backUpperRight = new Vertex(halfDimension.X, halfDimension.Y, halfDimension.Z);
            var backLowerLeft = new Vertex(-halfDimension.X, -halfDimension.Y, halfDimension.Z);
            var backLowerRight = new Vertex(halfDimension.X, -halfDimension.Y, halfDimension.Z);
            FullDetailLevel.AllocateVertices(8);
            FullDetailLevel.SetVertex(0, frontUpperLeft);
            FullDetailLevel.SetVertex(1, frontUpperRight);
            FullDetailLevel.SetVertex(2, frontLowerLeft);
            FullDetailLevel.SetVertex(3, frontLowerRight);
            FullDetailLevel.SetVertex(4, backUpperLeft);
            FullDetailLevel.SetVertex(5, backUpperRight);
            FullDetailLevel.SetVertex(6, backLowerLeft);
            FullDetailLevel.SetVertex(7, backLowerRight);
        }
        private void GenerateLines()
        {
            FullDetailLevel.AllocateLines(12);
            FullDetailLevel.SetLine(0, new Balder.Objects.Geometries.Line(0, 1));
            FullDetailLevel.SetLine(1, new Balder.Objects.Geometries.Line(2, 3));
            FullDetailLevel.SetLine(2, new Balder.Objects.Geometries.Line(0, 2));
            FullDetailLevel.SetLine(3, new Balder.Objects.Geometries.Line(1, 3));
            FullDetailLevel.SetLine(4, new Balder.Objects.Geometries.Line(4, 5));
            FullDetailLevel.SetLine(5, new Balder.Objects.Geometries.Line(6, 7));
            FullDetailLevel.SetLine(6, new Balder.Objects.Geometries.Line(4, 6));
            FullDetailLevel.SetLine(7, new Balder.Objects.Geometries.Line(5, 7));
            FullDetailLevel.SetLine(8, new Balder.Objects.Geometries.Line(0, 4));
            FullDetailLevel.SetLine(9, new Balder.Objects.Geometries.Line(1, 5));
            FullDetailLevel.SetLine(10, new Balder.Objects.Geometries.Line(2, 6));
            FullDetailLevel.SetLine(11, new Balder.Objects.Geometries.Line(3, 7));
        }
        private void GenerateFaces()
        {
            FullDetailLevel.AllocateFaces(12);
            FullDetailLevel.SetFace(0, new Face(2, 1, 0));
            FullDetailLevel.SetFace(1, new Face(1, 2, 3));
            FullDetailLevel.SetFace(2, new Face(4, 5, 6));
            FullDetailLevel.SetFace(3, new Face(7, 6, 5));
            FullDetailLevel.SetFace(4, new Face(0, 4, 2));
            FullDetailLevel.SetFace(5, new Face(6, 2, 4));
            FullDetailLevel.SetFace(6, new Face(3, 5, 1));
            FullDetailLevel.SetFace(7, new Face(5, 3, 7));
            FullDetailLevel.SetFace(8, new Face(0, 1, 4));
            FullDetailLevel.SetFace(9, new Face(5, 4, 1));
            FullDetailLevel.SetFace(10, new Face(6, 3, 2));
            FullDetailLevel.SetFace(11, new Face(3, 6, 7));
        }

    }
}

source:
http://rapidshare.com/files/417107533/baldertest2.rar

        
            
                
            
            
            
                           

            
        
    

Coordinator
Sep 6, 2010 at 9:22 PM

Hi,

sorry about the relay slow answer on this one. 

There is a couple of bugs in the 0.8.8.8 version that was introduced in that version, one is the coloring and Materials, it defaults to a material that doesn't reflect anything from lighting.

You can fix it by specifying a Material that has the Shade property set to Flat or Gouraud, so in your Xaml you could do something like this : 

			<Custom:MyBox>
				<Custom:MyBox.Material>
					<Materials:Material Diffuse="Green" Specular="White" Shade="Gouraud"/>
				</Custom:MyBox.Material>
			</Custom:MyBox>

This is fixed in the source under the Source Code tab, if you download the latest from there - and you open up a Visual Studio CMD and change folder to the Balder source folder. Then you enter the following in the CMD : 

build All

There should now be a Drops folder with the binaries you need, update with those.

 

Hope this helps