Code archives/3D Graphics - Effects/Spacesphere

This code has been declared by its author to be Public Domain code.

Download source code

Spacesphere by Chroma
(Posted 20 years ago)
Play around with the sptex scale a bit to suit your tastes.
;Spacesphere

;Create the Texture
sptex = CreateTexture(1024,1024,1+8)
SetBuffer TextureBuffer(sptex)
For a = 1 To 200
	Plot Rand(0,1023),Rand(0,1023)
Next
SetBuffer BackBuffer()
TextureBlend sptex,5

;Create the Sphere
spbox = CreateSphere(5)
ScaleEntity spbox,10000,10000,10000
EntityTexture spbox,sptex
ScaleTexture sptex,.25,.5
EntityFX spbox,1
FlipMesh spbox
EntityOrder spbox,99999

Comments

markcw
(Posted 20 years ago)
Here is a working example.

;Spacesphere
Graphics3D 640,480,0,2
camera=CreateCamera()
light=CreateLight()
RotateEntity light,45,45,0

;Create the Texture
width=1024
sptex = CreateTexture(width,width,1+8)
SetBuffer TextureBuffer(sptex)
For a = 1 To 200
	Plot Rand(0,width-1),Rand(0,width-1)
Next
SetBuffer BackBuffer()
TextureBlend sptex,5

;Create the Sphere
spbox = CreateSphere(5)
ScaleEntity spbox,1000,1000,1000
EntityTexture spbox,sptex
ScaleTexture sptex,.25,.5
EntityFX spbox,1
FlipMesh spbox
EntityOrder spbox,99999

ball=CreateSphere(5)

While Not KeyHit(1)
 RenderWorld

 sincos#=sincos#+0.2
 PositionEntity ball,50*Sin(sincos#),25*Cos(sincos#),200*Cos(sincos#)

 If KeyDown(200) Then TurnEntity camera,-0.25,0,0 ;up key
 If KeyDown(208) Then TurnEntity camera,0.25,0,0 ;down key
 If KeyDown(203) Then TurnEntity camera,0,0.25,0 ;left key
 If KeyDown(205) Then TurnEntity camera,0,-0.25,0 ;right key
 If KeyHit(17) Then wf=Not wf : WireFrame wf ;W key
 Text 0,0,"Arrow keys=move camera, W=wireframe"

 Flip
Wend


Boiled Sweets
(Posted 20 years ago)
Stars get dimmer when you move - shame.

Andres
(Posted 20 years ago)
I see only one ball circling around me and a big white sphere around the camera.

Rook Zimbabwe
(Posted 20 years ago)
ANDRES you probably have nVidia graphics card yes?

Why does the LEFT arrow mess this (slightly more complicated) example up?

;Spacesphere
Graphics3D 640,480,0,2
camera=CreateCamera()
light=CreateLight()
RotateEntity light,45,45,0

;Create the Texture
width=1024
sptex = CreateTexture(width,width,1+8)
SetBuffer TextureBuffer(sptex)
For a = 1 To 200
	Plot Rand(0,width-1),Rand(0,width-1)
Next
SetBuffer BackBuffer()
TextureBlend sptex,5

;Create the Sphere
spbox = CreateSphere(5)
ScaleEntity spbox,1000,1000,1000
EntityTexture spbox,sptex
ScaleTexture sptex,.25,.5
EntityFX spbox,1
FlipMesh spbox
EntityOrder spbox,99999

;Create the Sphere2
spbox2 = CreateSphere(5)
ScaleEntity spbox2,900,900,900
EntityTexture spbox2,sptex
ScaleTexture sptex,.35,.5
EntityAlpha spbox2,.5
FlipMesh spbox2
EntityOrder spbox2,999

ball=CreateSphere(5)

While Not KeyHit(1)
 

 sincos#=sincos#+0.2
 PositionEntity ball,50*Sin(sincos#),25*Cos(sincos#),200*Cos(sincos#)

 If KeyDown(200) Then 
	TurnEntity camera,-0.35,0,0 ;up key
	TurnEntity spbox2,-0.30,0,0 ;up key
	EndIf
 If KeyDown(208) Then 
	TurnEntity camera,0.35,0,0 ;down key
	TurnEntity spbox2,0.30,0,0 ;down key
	EndIf
 If KeyDown(203) Then 
	TurnEntity camera,0,0,35,0 ;left key
	TurnEntity spbox2,0,0,30,0 ;left key
	EndIf
 If KeyDown(205) Then 
	TurnEntity camera,0,-0.35,0 ;right key
	TurnEntity spbox2,0,-0.30,0 ;right key
	EndIf

 If KeyHit(17) Then wf=Not wf : WireFrame wf ;W key

RenderWorld

 Text 0,0,"Arrow keys=move camera, W=wireframe"

 Flip
Wend


I don't get it... trying to do the double starfield effect like on Trek... The LEFT ARROW seems to spin madly... all else works!

Stevie G
(Posted 20 years ago)
Rook - you've left out the decimal points in the 35 & 30 ... there's an extra ", 0" there instead ;)

Rook Zimbabwe
(Posted 20 years ago)
yipes!!! Thanks Stevie!

Andres
(Posted 20 years ago)
Rook Zimbabwe: Nope, I have ATI Radeon 9600se

TextureBlend sptex,5 ruined the texture, i can't use third (add)blend mode, but it works with second (multiply)

Code Archives Forum