Rotating cube

Blitz3D Forums/Blitz3D Beginners Area/Rotating cube

The Thick Brummy(Posted 2006) [#1]
Hi, everyone. After messing about for three years with another version of basic (of the dark variety), i've finally seen sense and bought Blitz. so can anyone help me with this? I want a cube spinning on 3 axes(no problem there) but I want one side coloured. In the aforementioned language I had to attach a plane to one side, which was fine until I told it to move in random directions which was when the plane went off and did its own thing. So, can I create a spinning cube with a coloured side. Hopefully this is easy because my mega game relies on the cube spinning everywhere.
Thanks in advance


b32(Posted 2006) [#2]
After creating the cube, use VertexColor to set the vertex colors for the cube:
surf = GetSurface(cube, 1)
VertexColor surf, 0, 255, 0, 0
VertexColor surf, 1, 255, 0, 0
VertexColor surf, 2, 255, 0, 0
VertexColor surf, 3, 255, 0, 0
EntityFX cube, 2

Another way is texturing the cube so, that one side is red. For this, easiest is to create the cube in a 3d editor.


IPete2(Posted 2006) [#3]
Brummy,

Look up the example in the Help section inside B3D. Look for the vertex commads.

Also don't forget to updatenormals meshname or lighting won't effect the mesh correctly.

IPete2.


The Thick Brummy(Posted 2007) [#4]
Thank you all. I'll work on it.


puki(Posted 2007) [#5]
Graphics3D 640,480,16,2 
SetBuffer BackBuffer() 

cam = CreateCamera() 
MoveEntity cam, 0,0,-12

light=CreateLight()

mesh = CreateMesh() 
surface=CreateSurface(mesh)

; this is the front face of the cube - the one initially facing you
v1=AddVertex(surface,-2,-2,-2); bottom left corner
v2=AddVertex(surface,-2, 2,-2); top left corner
v3=AddVertex(surface, 2, 2,-2); top right corner
v4=AddVertex(surface, 2,-2,-2); bottom right corner

VertexColor surface,v1,255,0,0
VertexColor surface,v2,255,0,0
VertexColor surface,v3,255,0,0
VertexColor surface,v4,255,0,0
EntityFX mesh,2  

tri1=AddTriangle(surface,v1,v2,v3); the left triangle
tri2=AddTriangle(surface,v1,v3,v4); the right triangle

; this is the left face of the cube - the one initially facing left
v1=AddVertex(surface,-2,-2, 2); bottom left corner
v2=AddVertex(surface,-2, 2, 2); top left corner
v3=AddVertex(surface,-2, 2,-2); top right corner
v4=AddVertex(surface,-2,-2,-2); bottom right corner

tri1=AddTriangle(surface,v1,v2,v3); the left triangle
tri2=AddTriangle(surface,v1,v3,v4); the right triangle

; this is the right face of the cube - the one initially facing right
v1=AddVertex(surface, 2,-2,-2); bottom left corner
v2=AddVertex(surface, 2, 2,-2); top left corner
v3=AddVertex(surface, 2, 2, 2); top right corner
v4=AddVertex(surface, 2,-2, 2); bottom right corner

tri1=AddTriangle(surface,v1,v2,v3); the left triangle
tri2=AddTriangle(surface,v1,v3,v4); the right triangle

; this is the rear face of the cube - the one initially facing the rear
v1=AddVertex(surface, 2,-2, 2); bottom left corner
v2=AddVertex(surface, 2, 2, 2); top left corner
v3=AddVertex(surface,-2, 2, 2); top right corner
v4=AddVertex(surface,-2,-2, 2); bottom right corner

tri1=AddTriangle(surface,v1,v2,v3); the left triangle
tri2=AddTriangle(surface,v1,v3,v4); the right triangle

; this is the top face of the cube - the one initially facing the up
v1=AddVertex(surface,-2, 2,-2); bottom left corner
v2=AddVertex(surface,-2, 2, 2); top left corner
v3=AddVertex(surface, 2, 2, 2); top right corner
v4=AddVertex(surface, 2, 2,-2); bottom right corner

tri1=AddTriangle(surface,v1,v2,v3); the left triangle
tri2=AddTriangle(surface,v1,v3,v4); the right triangle

; this is the bottom face of the cube - the one initially facing the down
v1=AddVertex(surface,-2,-2, 2); bottom left corner
v2=AddVertex(surface,-2,-2,-2); top left corner
v3=AddVertex(surface, 2,-2,-2); top right corner
v4=AddVertex(surface, 2,-2, 2); bottom right corner

tri1=AddTriangle(surface,v1,v2,v3); the left triangle
tri2=AddTriangle(surface,v1,v3,v4); the right triangle

UpdateNormals mesh

x#=.5
y#=.5
z#=.5 
While Not KeyHit(1)
c=c+1
If c=200
	x=Rnd(5)/10
	y=Rnd(5)/10
	z=Rnd(5)/10
	c=0
EndIf
TurnEntity mesh,x,y,z
RenderWorld
Flip 
Wend
End


I knocked that up kind of quick - but you see the point behind it.


puki(Posted 2007) [#6]
Note: before pasting this into Blitz3D, you may find it easier to paste it into Notepad (or similar) then re-copy and paste to Blitz3D.


The Thick Brummy(Posted 2007) [#7]
Thanks, Puki. That's almost exactly what I wanted. I'll change it a little and fool myself into believing that I wrote it.


GfK(Posted 2007) [#8]
Looks remarkably like Mark's skybox code, puki ;)