Hey Rob how about posting the source for your Demo1 ?

Blitz3D Forums/Blitz3D Programming/Hey Rob how about posting the source for your Demo1 ?

CyBeRGoth(Posted 2003) [#1]
So we can see how its done

Go on :)


Gabriel(Posted 2003) [#2]
Didn't he already? I thought the new version he put in his sig included source. I'm sure I saw him tell someone that in regards to a particle system.


Rob(Posted 2003) [#3]
Yeah I gave it to Mark for inclusion with the latest update. If it's not there, I will up it and slap it in my siggy for all to play with.


Mathieu A(Posted 2003) [#4]
I don't find the demo Rob. Is it inclued or not?
THX


jhocking(Posted 2003) [#5]
Yeah, I don't see your demo included in the latest update. Upload your source code (and maybe lose the compiled version since that makes the download bigger.)


Rogue Vector(Posted 2003) [#6]
The code for Robs demo would really help me out.

At the moment, I've got a very basic cube mapped surface working, but it doesn't look anything like as good as Robs stuff.

Cheers,

RV


John Blackledge(Posted 2003) [#7]
Yes please Rob.
How the hell do you get the reflections on/under the water?!


SopiSoft(Posted 2003) [#8]
I would like to see the code too! please Rob!!! :-)


darklordz(Posted 2003) [#9]
Nice Water code Jummy.....


CSauer(Posted 2003) [#10]
Please post the source for demo1.
This would really help me out, too.

Regards
Christian


SoggyP(Posted 2003) [#11]
Hi Rob,

DON'T post the code, make 'em sweat ;0)

Later,

Jes


Rob(Posted 2003) [#12]
I am :)


HNPhan(Posted 2003) [#13]
so cruel *sob sob*


Rogue Vector(Posted 2003) [#14]
Why?

What's the point of holding back?

These forums are supposed to help people use Blitz 3D.

Cheers,

RV


Rob(Posted 2003) [#15]
Yes but *I* am not solely supposed to help people use Blitz 3D.

And I already explained I am going to release it. I was merely pulling legs... it will be released when I get five mins to tidy up the code in human readable form :)


SopiSoft(Posted 2003) [#16]
take your time to do so m8 !!!


Anthony Flack(Posted 2003) [#17]

These forums are supposed to help people use Blitz 3D.


I thought these forums were supposed to help people avoid using Blitz 3D.


SoggyP(Posted 2003) [#18]
Hi Folks,

Hurrah for cans of worms :0)

Later,

Jes


Robert(Posted 2003) [#19]
I too would love to see the source, but rogue vector, you aren't going the right way about it. Personally I don't really mind whether or not the source is commented, though it would be helpful.


Neo Genesis10(Posted 2003) [#20]
Ive heard a bit about this demo but never actually seen it in action. Any tips for mastering cubemapping would be a great aid.


wmaass(Posted 2003) [#21]
Hey Rob, bump :)


Robert(Posted 2003) [#22]
While 1
bump
Wend


Bot Builder(Posted 2003) [#23]
F_Rob_hasn't_posted_code=checkforums("Programming/Blitz3D/Hey Rob how about posting the source for your Demo1 ?","Rob","Code")

While F_Rob_hasn't_posted_code
sendemail("Rob","Cummon give us da code")
wend


wmaass(Posted 2003) [#24]
Well in the interest of bugging Rob and trying to keep the thread semi useful at the same time, how about some discussion about the problem.

First of all I'm an amateur so be kind :).

I'm really only interested initially in trying to get the reflection correct on a plane (water). Obviously it can be done as Rob's demo is evidence of that. However simply cube mapping a plane does not cut it. Perhaps some corrections need to be done as the POV moves -- but I think the hardware is supposed to handle that. I think perhaps that straight cube mapping does not work well with flat objects without some magic (Rob). The way I understand it the hardware uses a vector to sample part of the cube mapped object to set up the texture coordinates. Is that right? If so that could explain the problem with flat objects.


Robert(Posted 2003) [#25]
The problem is that a camera pointing vertically upwards has a field of view, and only "sees" from one position. This means that if you try to texture a plane with the object either objects are distorted (stretched), OR they just don't line up with the original.


Dock(Posted 2003) [#26]
I think Rob really made that demo in Dark Basic Pro. ;)

I would imagine the inaccuracies of reflection would become only apparent when you can see both the bottom of the object lined up with the water. For example, if you put a tree at the edge of a pool. However, with Rob's demo the statue was large and some distance away/over the pool, so inaccuracies would be more tricky to notice, especially with the water ripples.


fredborg(Posted 2003) [#27]
You can play around with this, until the good Rob comes around to cleaning up his code :)
; SetCubeFace Example
; -------------------

path$ = "F:\Programmer\Blitz3D\help\commands\3d_examples\media\"

width=640
height=480
depth=0
mode=2

Graphics3D width,height,depth,mode
SetBuffer BackBuffer()

; If user's graphics card does not support cubic mapping then quit example
If GfxDriverCaps3D()<110 Then RuntimeError "Sorry, your graphics card does not support cubic environemnt maps."

cam=CreateCamera()
PositionEntity cam,0,10,-10

; Create separate camera for updating cube map - this allows us to manipulate main camera and cube camera which avoids any confusion
cube_cam=CreateCamera()

light=CreateLight()
RotateEntity light,90,0,0

; Load object we will apply cubemap to - the classic teapot
teapot=LoadMesh(path+"teapot.x")
ScaleEntity teapot,3,3,3
PositionEntity teapot,0,10,0

; Create some scenery

; ground
ground=CreateFace(10)
ScaleEntity ground,20,20,20
;EntityColor ground,168,133,55
ground_tex=LoadTexture(path+"sand.bmp")
ScaleTexture ground_tex,10,10
EntityTexture ground,ground_tex
;FlipMesh ground
EntityFX ground,1
; sky
sky=CreateSphere(24)
ScaleEntity sky,500,500,500
FlipMesh sky
EntityFX sky,1
sky_tex=LoadTexture(path+"sky.bmp")
EntityTexture sky,sky_tex

; cactus
cactus=LoadMesh(path+"cactus2.x")
FitMesh cactus,-5,0,-5,2,6,.5

; camel
camel=LoadMesh(path+"camel.x")
FitMesh camel,5,0,-5,6,5,4

; Load ufo to give us a dynamic moving object that the cubemap will be able to reflect
ufo_piv=CreatePivot()
PositionEntity ufo_piv,0,15,0
ufo=LoadMesh(path+"green_ufo.x",ufo_piv)
PositionEntity ufo,0,0,10

 ; Create texture with color + cubic environment map + store in vram flags
tex=CreateTexture(256,256,1+128+256)

 ; Apply cubic environment map to teapot
EntityTexture ground,tex

Global waterang# = 0.0

While Not KeyDown(1)

	For i = 1 To 9
		If KeyHit(1+i)
			SetCubeMode tex,i
		End If
	Next

	; Control camera
	
	; mouse look
	
	mxs#=mxs#+(MouseXSpeed()/5.0)
	mys#=mys#+(MouseYSpeed()/5.0)

	RotateEntity cam,mys#,-mxs#,roll#

	If KeyDown(30) Then roll# = roll#+1.0
	If KeyDown(44) Then roll# = roll#-1.0

	MoveMouse width/2,height/2

	; move camera forwards/backwards/left/right with cursor keys
	
	If KeyDown(200)=True Then MoveEntity cam,0,0,.2 ; move camera forward
	If KeyDown(208)=True Then MoveEntity cam,0,0,-.2 ; move camera back

	If KeyDown(205)=True Then MoveEntity cam,.2,0,0 ; move camera left
	If KeyDown(203)=True Then MoveEntity cam,-.2,0,0 ; move camera right
	
	; Turn ufo pivot, causing child ufo mesh to spin around it (and teapot)
	TurnEntity ufo_piv,0,2,0

	Water(ground)

	; Update cubemap
	UpdateCubemap(tex,cube_cam,ground,cam)
	
	RenderWorld
	
	Text 0,0,"Use mouse to look around"
	Text 0,20,"Use cursor keys to change camera position"
	
	Flip

Wend

End 

Function Water(mesh)
	
	If Lower$(EntityClass(mesh)) = "mesh"
		n_surf = CountSurfaces(mesh)
		For s = 1 To n_surf
			surf = GetSurface(mesh,s)
			n_vert = CountVertices(surf)-1
			For v = 0 To n_vert
				VertexCoords surf,v,VertexX(surf,v),Sin(waterang+(v*60))*0.001,VertexZ(surf,v)
			Next
		Next
	
		UpdateNormals mesh
		waterang = waterang + 5.0
	End If

End Function

Function UpdateCubemap(tex,camera,entity,ocam,flat=True)

	CameraProjMode ocam,0

	tex_sz=TextureWidth(tex)

	; Show the camera we have specifically created for updating the cubemap
	ShowEntity camera
	
	; Hide entity that will have cubemap applied to it. This is so we can get cubemap from its position, without it blocking the view
	HideEntity entity

	; Position camera where the entity is - this is where we will be rendering views from for cubemap
	If flat
		PositionEntity camera,EntityX#(ocam),EntityY#(entity)-(EntityY(ocam)-EntityY(entity)),EntityZ(ocam)
	Else
		PositionEntity camera,EntityX#(entity),EntityY#(entity),EntityZ#(entity)
	End If

	CameraClsMode camera,False,True
	
	; Set the camera's viewport so it is the same size as our texture - so we can fit entire screen contents into texture
	CameraViewport camera,0,0,tex_sz,tex_sz

	; Update cubemap

	; do left view	
	SetCubeFace tex,0
	RotateEntity camera,0,90,0
	RenderWorld
	CopyRect 0,0,tex_sz,tex_sz,0,0,BackBuffer(),TextureBuffer(tex)
	
	; do forward view
	SetCubeFace tex,1
	RotateEntity camera,0,0,0
	RenderWorld
	CopyRect 0,0,tex_sz,tex_sz,0,0,BackBuffer(),TextureBuffer(tex)
	
	; do right view	
	SetCubeFace tex,2
	RotateEntity camera,0,-90,0
	RenderWorld
	CopyRect 0,0,tex_sz,tex_sz,0,0,BackBuffer(),TextureBuffer(tex)
	
	; do backward view
	SetCubeFace tex,3
	RotateEntity camera,0,180,0
	RenderWorld
	CopyRect 0,0,tex_sz,tex_sz,0,0,BackBuffer(),TextureBuffer(tex)
	
	; do up view
	SetCubeFace tex,4
	RotateEntity camera,-90,0,0
	RenderWorld
	CopyRect 0,0,tex_sz,tex_sz,0,0,BackBuffer(),TextureBuffer(tex)

	; do down view
	SetCubeFace tex,5
	RotateEntity camera,90,0,0
	RenderWorld
	CopyRect 0,0,tex_sz,tex_sz,0,0,BackBuffer(),TextureBuffer(tex)
	
	; Show entity again
	ShowEntity entity
	
	; Hide the cubemap camera
	HideEntity camera

	CameraProjMode ocam,1
	
End Function

;Creates a single sided face
;segmented
Function CreateFace(segs=1,parent=0)
	mesh=CreateMesh( parent )
	surf=CreateSurface( mesh )
	stx#=-.5
	sty#=stx
	stp#=Float(1)/Float(segs)
	y#=sty
	For a=0 To segs
		x#=stx
		v#=a/Float(segs)
		For b=0 To segs
			u#=b/Float(segs)
			AddVertex(surf,x,0,y,u,v) ; swap these for a different start orientation
			x=x+stp
		Next
		y=y+stp
	Next
	
	For a=0 To segs-1
		For b=0 To segs-1
			v0=a*(segs+1)+b:v1=v0+1
			v2=(a+1)*(segs+1)+b+1:v3=v2-1
			AddTriangle( surf,v0,v2,v1 )
			AddTriangle( surf,v0,v3,v2 )
		Next	
	Next
	UpdateNormals mesh
		
	Return mesh
End Function
Have fun!


wmaass(Posted 2003) [#28]
Lovely! Thanks for the example -- I'm curious to look at this and learn what you did.