Problem with lights

Blitz3D Forums/Blitz3D Programming/Problem with lights

PowerPC603(Posted 2005) [#1]
Hi,

I'm trying to create a 3D maze generator and I already wrote some functions to create 2 kinds of pathways.

I create a new mesh, add a surface to it.
After this, I add vertexes and triangles via functions.
This all works perfectly, but the mesh isn't affected by lights.

I placed a light in the scene, disabled ambient light, but no lighting effect on my mesh.
I even painted a brush onto my mesh, but still nothing.
I added a plane beneath the mesh and this is affect by the light.

How can I make my mesh light-sensitive?

Graphics3D 800, 600
SetBuffer BackBuffer()



plane = CreatePlane()
EntityColor plane, 255, 0, 0

camera = CreateCamera()
MoveEntity camera, 0, 8, 0

brush = CreateBrush(0, 255, 0)

AmbientLight 0,0,0
light = CreateLight(2)
MoveEntity light, 0, 15, 0
LightColor light, 255, 255, 255



Global MazeMesh = CreateMesh()
Global MazeSurf = CreateSurface(MazeMesh, brush)

CreateUpDown(0, 20)
CreateLeftRight(0, 20)



While Not KeyHit(1)
	If KeyDown(200) TurnEntity camera, -1, 0, 0 ; Up arrow
	If KeyDown(208) TurnEntity camera, 1, 0, 0 ; Down arrow
	If KeyDown(203) TurnEntity camera, 0, -1, 0 ; Left arrow
	If KeyDown(205) TurnEntity camera, 0, 1, 0 ; Right arrow

	If KeyDown(75) MoveEntity camera, -1, 0, 0 ; Num4
	If KeyDown(77) MoveEntity camera, 1, 0, 0 ; Num6
	If KeyDown(72) MoveEntity camera, 0, 0, 1 ; Num8
	If KeyDown(80) MoveEntity camera, 0, 0, -1 ; Num2

	RenderWorld
	Flip
Wend



Function CreateUpDown(x, z)
	; Create the left wall
	v0 = AddVertex(MazeSurf, x - 9, 0, z - 10)
	v1 = AddVertex(MazeSurf, x - 9, 0, z + 10)
	v2 = AddVertex(MazeSurf, x - 9, 5, z - 10)
	v3 = AddVertex(MazeSurf, x - 9, 5, z + 10)

	t0 = AddTriangle(MazeSurf, v0, v2, v1)
	t1 = AddTriangle(MazeSurf, v1, v2, v3)

	; Create the right wall
	v0 = AddVertex(MazeSurf, x + 9, 0, z + 10)
	v1 = AddVertex(MazeSurf, x + 9, 0, z - 10)
	v2 = AddVertex(MazeSurf, x + 9, 5, z + 10)
	v3 = AddVertex(MazeSurf, x + 9, 5, z - 10)

	t0 = AddTriangle(MazeSurf, v0, v2, v1)
	t1 = AddTriangle(MazeSurf, v1, v2, v3)
End Function

Function CreateLeftRight(x, z)
	; Create the bottom wall
	v0 = AddVertex(MazeSurf, x - 10, 0, z - 9)
	v1 = AddVertex(MazeSurf, x + 10, 0, z - 9)
	v2 = AddVertex(MazeSurf, x - 10, 5, z - 9)
	v3 = AddVertex(MazeSurf, x + 10, 5, z - 9)

	t0 = AddTriangle(MazeSurf, v0, v1, v3)
	t1 = AddTriangle(MazeSurf, v0, v3, v2)

	; Create the top wall
	v0 = AddVertex(MazeSurf, x - 10, 0, z + 9)
	v1 = AddVertex(MazeSurf, x + 10, 0, z + 9)
	v2 = AddVertex(MazeSurf, x - 10, 5, z + 9)
	v3 = AddVertex(MazeSurf, x + 10, 5, z + 9)

	t0 = AddTriangle(MazeSurf, v0, v2, v1)
	t1 = AddTriangle(MazeSurf, v1, v2, v3)
End Function



_Skully(Posted 2005) [#2]
You need to update norms


Andy(Posted 2005) [#3]
http://www.blitzbasic.com/b3ddocs/command.php?name=UpdateNormals&ref=3d_a-z


Andy


PowerPC603(Posted 2005) [#4]
Oh, thanks, it works now.

I've never done this before, and wanted to start with something easy (walls are just rectangular planes, merged together).

Making a spaceship with Addvertex and stuff is beyond my skills right now.


PowerPC603(Posted 2005) [#5]
My 3D maze is coming along nicely.

The entire maze (10x10 structure) is defined within the file Maze001.dat (standard txt-file, written in Notepad).
The 3D model is generated via code (based on the data in the file Maze001.dat), also the UV-coords for each wall-section are applied via code.

Movement:
Arrow-Up and Arrow-Down: move forward and backwards.
MouseX and MouseY are for turning.
Keys Z and S are for moving up and down (so you can see the entire maze from high in the sky).
Spacebar: toggel gravity on/off.

Beware: the resolution is set to 1280x1024.

The entire source-code is included in the zip-file:
http://users.pandora.be/vge/downloads/Maze3DComplete.zip