Code Help please :)
Blitz3D Forums/Blitz3D Beginners Area/Code Help please :)
| ||
Graphics3D 800,600,0,2 SetBuffer BackBuffer() camera=CreateCamera() CameraViewport camera,0,0,800,600 light=CreateLight() col=8 : row=11 : total_cube=col*row : num=0 : spacer_cube=4 : xoffset#=24.1 : yoffset#=17.7 total_hexa=9 : spacer_hexa#=2.5 Dim cube(total_cube) Dim hexa(total_hexa) x#=0 : y#=0 : depth=22 For columns = 1 To col For rows = 1 To row num=num+1 x#=rows*spacer_cube-xoffset# y#=columns*spacer_cube-yoffset# cube(num)=CreateCube() PositionEntity cube(num),x#,y#,depth EntityColor cube(num),100,255,255 Next Next x#=-5.5 : y#=0 : depth=8 : offset_hex=8 For hexs=1 To total_hexa hexa(hexs)=CreateCube() y#=hexs*spacer_hexa#-offset_hex PositionEntity hexa(hexs),x#,y#,depth EntityColor hexa(hexs),100,100,255 Next speed#=.03 While Not KeyHit(1) For reps=1 To total_cube TurnEntity cube(reps),.5,1.2,1.3 Next For reps=1 To total_hexa TurnEntity hexa(reps),0,1,0 MoveEntity hexa(reps),0,-speed#,0 If EntityY(hexa(reps)) <-10 Then PositionEntity hexa(reps),x#,12.5,depth Next RenderWorld Flip Wend End Can some one please help me a little with demo, I am in the process of making a graphic demo. It is a conversion from one of my Amiga creations way back in 1993!!! :) I am having a little trouble in one part that I am trying to do. I am trying to create a plane (square panel) in the background to cover the whole area so you can't see any of the black part of the screen. It is to be further in the background than the small cubes so that when I move the light source about you will see shadows from the cubes on it, everytime I use the create plane command it doesn't show on the screen????? Any ideas please :) Retro rulez :)) |
| ||
Maybe it's a rotation or positioning problem? try moving the plane downwards a bit (MoveEntity plane,0,-3,0) |
| ||
create a plane and rotate it 180,0,0 [edit] or not depends where the camera is ^^ maybe move it away from the camera 0,0,+Z |
| ||
Graphics3D 800,600,0,2 SetBuffer BackBuffer() camera=CreateCamera() CameraViewport camera,0,0,800,600 light=CreateLight() col=8 : row=11 : total_cube=col*row : num=0 : spacer_cube=4 : xoffset#=24.1 : yoffset#=17.7 total_hexa=9 : spacer_hexa#=2.5 Dim cube(total_cube) Dim hexa(total_hexa) plane=CreatePlane() MoveEntity plane,0,-3,30 RotateEntity plane,-90,0,0 EntityColor plane,0,50,255 x#=0 : y#=0 : depth=22 For columns = 1 To col For rows = 1 To row num=num+1 x#=rows*spacer_cube-xoffset# y#=columns*spacer_cube-yoffset# cube(num)=CreateCube() PositionEntity cube(num),x#,y#,depth EntityColor cube(num),0,120,255 Next Next x#=-4.7 : y#=0 : depth=8 : offset_hex=8 : alpha#=.9 : hexa_scale#=1.5 For hexs=1 To total_hexa hexa(hexs)=CreateCube() y#=hexs*spacer_hexa#-offset_hex PositionEntity hexa(hexs),x#,y#,depth RotateEntity hexa(hexs),0,hexs*(90/total_hexa),0 ScaleEntity hexa(hexs),hexa_scale#,1,hexa_scale# EntityColor hexa(hexs),100,100,255 EntityAlpha hexa(hexs),alpha# Next speed#=.03 While Not KeyHit(1) For reps=1 To total_cube TurnEntity cube(reps),.5,1.2,1.3 Next For reps=1 To total_hexa TurnEntity hexa(reps),0,1,0 MoveEntity hexa(reps),0,-speed#,0 If EntityY(hexa(reps)) <-10 Then PositionEntity hexa(reps),x#,12.5,depth Next RenderWorld Flip Wend End Heres the code guys, thanks for the help!! :) By the way I've not decided on colours yet :))) |
| ||
Graphics3D 800,600,0,2 SetBuffer BackBuffer() camera=CreateCamera() CameraViewport camera,0,0,800,600 light=CreateLight() col=8 : row=11 : total_cube=col*row : num=0 : spacer_cube=4 : xoffset#=24.1 : yoffset#=17.7 total_hexa=9 : spacer_hexa#=2.5 Dim cube(total_cube) Dim hexa(total_hexa) plane=CreatePlane() MoveEntity plane,0,0,25 RotateEntity plane,-90,0,0 EntityColor plane,0,50,255 ball=CreateSphere() PositionEntity ball,0,0,35 PointEntity light,ball PositionEntity light,0,0,0 ; remove ball 2 later ball2=CreateSphere() PositionEntity ball2,0,0,5 ScaleEntity ball2,.5,.5,.5 ; end of remove section Dim sinetable#(360),costable#(360) light_spacer=4 For angle = 0 To 359 sinetable#(angle)=light_spacer*Sin(angle) costable#(angle)=light_spacer*Cos(angle) Next x#=0 : y#=0 : depth=22 For columns = 1 To col For rows = 1 To row num=num+1 x#=rows*spacer_cube-xoffset# y#=columns*spacer_cube-yoffset# cube(num)=CreateCube() PositionEntity cube(num),x#,y#,depth EntityColor cube(num),0,120,255 Next Next x#=-4.7 : y#=0 : depth=8 : offset_hex=8 : alpha#=.9 : hexa_scale#=1.5 For hexs=1 To total_hexa hexa(hexs)=CreateCube() y#=hexs*spacer_hexa#-offset_hex PositionEntity hexa(hexs),x#,y#,depth RotateEntity hexa(hexs),0,hexs*(90/total_hexa),0 ScaleEntity hexa(hexs),hexa_scale#,1,hexa_scale# EntityColor hexa(hexs),100,100,255 EntityAlpha hexa(hexs),alpha# Next speed#=.03 : angle=0 : angle2=34 While Not KeyHit(1) For reps=1 To total_cube TurnEntity cube(reps),.5,1.2,1.3 Next For reps=1 To total_hexa TurnEntity hexa(reps),0,1,0 MoveEntity hexa(reps),0,-speed#,0 If EntityY(hexa(reps)) <-10 Then PositionEntity hexa(reps),x#,12.5,depth Next ; ball2 to remove after PositionEntity ball2,sinetable#(angle),costable#(angle2),5 ; end of remove section PositionEntity light,sinetable#(angle),costable#(angle2),5 PointEntity light,ball angle=angle+1 angle2=angle2+1 If angle>359 Then angle=0 If angle2>359 Then angle2=0 RenderWorld Flip Wend End Hi again !! :) My demo is coming along nice now, got light source moving to a sine/cos wave and got plane sorted, one problem now though!! How do I get shadows???? |
| ||
If you want to change the colour of the backround from black, you can do this by:CameraClsColor camera,Red,Green,Blue Sorry, if this is not what your after, just thought i'd mention it :) |
| ||
Thanks for the info, not what I wanted but will come in handy as I didn't know that :)) I want to make shadows onto the background plane from the cubes in the foreground using my moving light sorce :)) Any help welcome, thanks :) |
| ||
Look at jfk's "Realtime Shadow" code under the Code Archives/3D Graphics - Misc. |
| ||
Or (if you have it) take a look at "halo's" shadow demo - in 'Samples/Blitz 3D Samples/Halo/Shadows' |
| ||
Wow that looks complicated!! Is there no command to just turn shadows on?? |
| ||
No - Blitz doesn't have a shadow system built-in - you have to make your own, or use someone else's (such as "sswift's"). |
| ||
Jesus that looks like my demo won't have shadows in then :( Way too complicated to do that!!! :) Unless anyone can help put it in my code??? |
| ||
It really isn't that hard. Without going into the gritty details, it's really as simple as the following: 1) Hide all entities except the ones to be "shadowed". 2) Set the shown entities to a grey color. 3) Move the camera to the light source and point it towards your "wall". You should store off where the camera was. 4) Render this scene and capture it to a texture. (You should set up your wall to use this shadow texture at initialization.) 5) Reset the shown entities to their proper color/texture. 6) Show all entities. 7) Move the camera back to where it was. |
| ||
???? Example please on my code if possible as I am new to Blitz3D. Thankyou :) |
| ||
Here is my attempt... I tried to modify your code as little as possible. Just compare the code side by side and you can see the changes I made. Just follow my comments and after a few minutes (hours?) you should see the general pattern. As you get better at Blitz Basic, you can encapsulate this into functions and use "structs" (Blitz's Types) to better organize. (Good luck to me... I've never posted code before!) Graphics3D 800,600,0,2 SetBuffer BackBuffer() camera=CreateCamera() CameraViewport camera,0,0,800,600 ; Changed this to a point light for more dramatic effect. light=CreateLight(2) LightRange light, 5 col=8 : row=11 : total_cube=col*row : num=0 : spacer_cube=4 : xoffset#=24.1 : yoffset#=17.7 total_hexa=9 : spacer_hexa#=2.5 Dim cube(total_cube) Dim hexa(total_hexa) plane=CreateSprite() SpriteViewMode plane, 2 EntityFX plane, 1 ScaleSprite plane, 25, 25 PositionEntity plane,0,0,23 ; Sets up the detail of the shadow Const shadowDetail = 512 ; or 128, 256, or 512 (no more than this, though!) ; Creates the shadow texture ; I normally would do this differently, but ; I want to do the minimalist effort so you ; can see how this done. shadowTexture = CreateTexture( shadowDetail, shadowDetail, 256 ) EntityTexture plane, shadowTexture ; Create the camera which will take a snapshot of the shadows. shadowCamera = CreateCamera() CameraClsColor shadowCamera, 0, 50, 255 CameraProjMode shadowCamera, 0 CameraViewport shadowCamera, 0, 0, shadowDetail, shadowDetail CameraZoom shadowCamera, 0.9 ; remove ball 2 later ball2=CreateSphere(3) PositionEntity ball2,0,0,5 ScaleEntity ball2,.25,.25,.25 ; end of remove section Dim sinetable#(360),costable#(360) light_spacer=4 For angle = 0 To 359 sinetable#(angle)=light_spacer*Sin(angle) costable#(angle)=light_spacer*Cos(angle) Next x#=0 : y#=0 : depth=22 For columns = 1 To col For rows = 1 To row num=num+1 x#=rows*spacer_cube-xoffset# y#=columns*spacer_cube-yoffset# cube(num)=CreateCube() PositionEntity cube(num),x#,y#,depth EntityColor cube(num),0,120,255 Next Next x#=-4.7 : y#=0 : depth=8 : offset_hex=8 : alpha#=.9 : hexa_scale#=1.5 For hexs=1 To total_hexa hexa(hexs)=CreateCube() y#=hexs*spacer_hexa#-offset_hex PositionEntity hexa(hexs),x#,y#,depth RotateEntity hexa(hexs),0,hexs*(90/total_hexa),0 ScaleEntity hexa(hexs),hexa_scale#,1,hexa_scale# EntityColor hexa(hexs),100,100,255 EntityAlpha hexa(hexs),alpha# Next speed#=.03 : angle=0 : angle2=34 While Not KeyHit(1) For reps=1 To total_cube TurnEntity cube(reps),.5,1.2,1.3 Next For reps=1 To total_hexa TurnEntity hexa(reps),0,1,0 MoveEntity hexa(reps),0,-speed#,0 If EntityY(hexa(reps)) <-10 Then PositionEntity hexa(reps),x#,12.5,depth Next ; ball2 to remove after PositionEntity ball2,sinetable#(angle),costable#(angle2),5 ; end of remove section PositionEntity light,sinetable#(angle),costable#(angle2),5 ; SHADOW TIME! ; Hide the real camera CameraProjMode camera, 0 ; Show the shadow camera CameraProjMode shadowCamera, 1 ; Position the shadow camera where the light is PositionEntity shadowCamera, sinetable#(angle),costable#(angle2),5 ; Hide the background, textured plane HideEntity plane ; Hide the big squares For hexs = 1 To total_hexa HideEntity hexa(hexs) Next ; Color the cubes like shadows. ; Plus, make them unaffected by light! ; This will cause them to be flat colored. For cubs = 1 To total_cube EntityColor cube(cubs), 64, 64, 64 EntityFX cube(cubs), 1 Next ; Render this shadow world. RenderWorld() ; Reset the cubes to their original state. For cubs = 1 To total_cube EntityFX cube(cubs), 0 EntityColor cube(cubs), 0, 120, 255 Next ; Reset the big squares to their original state. For hexs = 1 To total_hexa ShowEntity hexa(hexs) Next ; Reset the plane to its original state. ShowEntity plane ; Copy the shadow world to the texture that is on the plane. ; This updates the plane at the same time. It's like magic! CopyRect 0, 0, shadowDetail, shadowDetail, 0, 0, BackBuffer(), TextureBuffer(shadowTexture) ; Hide the shadow camera CameraProjMode shadowCamera, 0 ; Show the real camera CameraProjMode camera, 1 angle=angle+1 angle2=angle2+1 If angle>359 Then angle=0 If angle2>359 Then angle2=0 ; COMMENT THIS OUT TO SEE THE SHADOW WORLD! RenderWorld Flip Wend End |
| ||
:)) Thanks a lot m8, just checking it now, looks very cool!! Just how I needed it that m8y :)) Can get on with the demo now and modify it to suite!! :) |