Creating a spot light

Posted on 2006-04-27
Last Modified: 2013-12-26
I am trying to create a spotlight to highlight a area on my floor

 Private Sub RenderFloor()
        Dim m As Mesh = Mesh.Box(mDevice, 20.0F, 0.1F, 20.0F)
        Dim mtrl As Material = New Material
        mtrl.Ambient = System.Drawing.Color.Gray
        mtrl.Diffuse = mtrl.Ambient
        mDevice.Material = mtrl
        mDevice.Transform.World = Matrix.Identity
    End Sub

so it's creating it at 0,0,0

my camera position is currently set as 0,20,20 with my target being 0,0,0

With mDevice.Lights(0)
                .Type = LightType.Spot
                .Ambient = System.Drawing.Color.White
                .Diffuse = System.Drawing.Color.White
                .Attenuation0 = 1.0F
                .Falloff = 1.0F
                .Range = 50.0F
                .InnerConeAngle = 0.5F
                .OuterConeAngle = 1.0F
                .Position = New Vector3(0.0F, 20.0F, 20.0F)
                .Direction = New Vector3(0.0F, 0.0F, 0.0F)
                .Enabled = True
            End With

would this not set the spot light to be above my floor, and pointing at it?

i really don't have a clue why this doesn't work, any help would be appreciated.

thank you
Question by:sileacan
    LVL 17

    Accepted Solution

    I assume this is direct3d under VB?  I'll try to remember my VB (and my D3D!)...

    first, I think your light position wants to be (0, 20, 0), and your direction wants to be (0, -1, 0).  That is, if the floor is at (0,0,0), and is 20 units x and z, the light wants to be 20 units up in Y only, and the direction of the light needs to be pointing down along Y.

    second, note that you won't get a nice falloff/corona if the box created is 6 quads -- hardware lighting will only light at the vertices, so you need a box that is a reasonably fine mesh for each face in order to pick up on the lighting 'shifts' across each face.

    LVL 1

    Author Comment

    this is managed direct3d under yes.

    thanks for the tip of the spotlight.

    as for the floor i have created, i should avoid using a mesh and draw one out manually with a vertexbuffer to get better results?

    i am going to award you full points as you have answered my original question, just curious on the way it lights it up now that you have mentioned it.. I'll try both methods out myself and see how it goes.

    thanks alot, i'm sure i'll be awarding you more points in the near future!
    LVL 17

    Expert Comment

    I don't know the Mesh object interface. If there's a way to tell it to tessellate edges to some level, certainly easy to use.  Otherwise, yeah, just create a vb with a tessellated quad.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Android App Development

    This course will involve creating widgets, customize list view, grid view, spinners, etc. Creating applications using audio, video, and SQLite database. Ending with publication on Google Play.

    What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
    Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now