A couple of beginner questions...

Blitz3D Forums/Blitz3D Beginners Area/A couple of beginner questions...

stevious(Posted 2004) [#1]
Hi guys! I'm a new user of Blitz3D, I'm currently reading through the command reference and trying to get an understanding of the language. I have never written anything in 3D before (I've only recently started learning 3D math from a book) and haven't written any games since the days of AMOS on the Amiga.

Anyway, I have a couple of questions:

1) I get the impression that all arrays are global. Is this correct, or can I declare an array in a local scope?

2) MoveEntity vs. TranslateEntity. From what I can gather, MoveEntity takes its coordinates from the entity's space, where TranslateEntity uses worldspace coordinates?

Sorry for such dumb questions, but I have limited time at the moment, and thus I can either read documentation or code, not enough time for both just yet :-(


electronin(Posted 2004) [#2]
Hey stevious! you can declare a local array like this:

MyArray[10]


cool trick, that :)

MoveEntity moves the entity in a certain direction depending on which way it's facing, and I don't use TranslateEntity
much, but from what I can gather, it does move an entity
based on world coordinates.

Hope that helps!


Gauge(Posted 2004) [#3]
Yes all arrays are globals (note i use types-see expl below)

Yes moveentity moves the entity whichever way its facing.
And translateentity moves the entity to world coords.

This is how I do my 3d code. I use everything as a type.
Try This to store your mesh info.

;first define the type and approx fields
type player
field model
field x
field y
field z
field rot

;then to create a new player
p.player=new player
p\model=copyentity(player_entity) ;assuming you have a model
p\x#=0; or whever the models starting
p\y#=0
p\z#=0
p\rot=0 ;starts off facing its normal position

Heres a quick little program defining collisions, mesh/model movement, keyboard controls, and bullet firing. Create image/image buffer, rotation controls, adding meshes manually, etc. I think this code is pretty well documented and easy to follow, good luck

;note i didn't use p.player in this code
Graphics3D 400,300,16,3 ;change to 1 for faster

SetBuffer BackBuffer()
;Set Collision Types as Constants
Const Type_player=1
Const Type_wall=2

light=CreateLight()
RotateEntity light,90,0,0;rotate the light, puts the light at 0,0,0 and makes stuff visible

;Create Base Bullet model and resizes it
bullx=CreateSphere()
ScaleEntity bullx,.5,.5,.5
HideEntity bullx ;hides it, this one will not be seen

;create player fighter
model=CreateCube()
EntityType model,1
EntityRadius model,1.25
PositionEntity model,40,1,5

cam=CreateCamera()
PositionEntity cam,40,3,1

;attach the camera pivot
pivot=CreatePivot()
EntityParent pivot,model
EntityParent cam,model

;create a generic checkboard texture used on walls and floor both=need some color
tex=CreateTexture( 256,256 )

;set the texturebuffer to draw on such texture and makes a checkerboard type look

SetBuffer TextureBuffer( tex ) 
Color 255,0,0
For x=0 To 256 Step 32
For y=0 To 256 Step 32
Rect x,y,16,16
Next
Next
;reset buffer
SetBuffer BackBuffer()
Cls
;create the floor by addingvertexes etc manually
Arena=CreateMesh()
Afloor=CreateSurface(Arena)
v1=AddVertex (afloor,0,0,100,0,1)
v2=AddVertex (afloor,100,0,100,1,1)
v3=AddVertex (afloor,100,0,0,1,0)
v4=AddVertex (afloor,0,0,0,0,0)
tri=AddTriangle(afloor,v1,v2,v3)
tri2=AddTriangle(afloor,v1,v3,v4)
EntityTexture  arena,tex
EntityRadius arena,1
EntityType arena,Type_floor
;and the four sequential walls
nwall=CreateMesh()
nFloor=CreateSurface(nwall)
v1=AddVertex (nFloor,0,10,0,0,1)
v2=AddVertex (nFloor,0,10,100,1,1)
v3=AddVertex (nFloor,0,0,100,1,0)
v4=AddVertex (nFloor,0,0,0,0,0)
tri=AddTriangle(nFloor,v1,v2,v3)
tri2=AddTriangle(nFloor,v1,v3,v4)
afloor=LoadTexture("c:\blitz\checker2.bmp")
EntityTexture nwall,tex
EntityRadius nwall,1
EntityType nwall,2
UpdateNormals(nwall)

swall=CreateMesh()
sFloor=CreateSurface(swall)
v1=AddVertex (sfloor,100,10,100,0,1)
v2=AddVertex (sfloor,100,10,0,1,1)
v3=AddVertex (sfloor,100,0,0,1,0)
v4=AddVertex (sfloor,100,0,100,0,0)
tri=AddTriangle(sfloor,v1,v2,v3)
tri2=AddTriangle(sfloor,v1,v3,v4)
EntityTexture swall,tex
EntityRadius  swall,1
EntityType swall,2
UpdateNormals(swall)

wwall=CreateMesh()
wfloor=CreateSurface(wwall)
v1=AddVertex (wfloor,0,10,100,0,1)
v2=AddVertex (wfloor,100,10,100,1,1)
v3=AddVertex (wfloor,100,0,100,1,0)
v4=AddVertex (wfloor,0,0,100,0,0)
tri=AddTriangle(wfloor,v1,v2,v3)
tri2=AddTriangle(wfloor,v1,v3,v4)
EntityTexture wwall,tex
EntityRadius wwall,1
EntityType wwall,2
UpdateNormals(wwall)

ewall=CreateMesh()
efloor=CreateSurface(ewall)
v1=AddVertex (efloor,100,10,0,0,1)
v2=AddVertex (efloor,0,10,0,1,1)
v3=AddVertex (efloor,0,0,0,1,0)
v4=AddVertex (efloor,100,0,0,0,0)
tri=AddTriangle(efloor,v1,v2,v3)
tri2=AddTriangle(efloor,v1,v3,v4)
EntityTexture ewall,tex
EntityRadius ewall,1
EntityType ewall,2
;update the rest of the normals for light,etc
UpdateNormals(ewall)
UpdateNormals(arena)
UpdateNormals(model)

;enable collisions between player and wall
;note since the player model is moving, if you did collisions 2,1,2,2 it wouldn't work

Collisions 1,2,2,2

While Not KeyHit(1)
;Check NewFire
If KeyDown(57)=True Then ;change If keydown(57) to If keyhit(57) for noncontinous firing

;if fired Create a new bullet and position it at players location
b.bullet=New bullet
b\model=CopyEntity(bullx)
ax#=EntityX(model)
ay#=EntityY(model)
az#=EntityZ(model)
PositionEntity  b\model,ax#,ay#,az# 
TurnEntity b\model,0,rot#,0
MoveEntity b\model,0,0,3
b\dur=50
;after dur is over, bullet disappears
EndIf

;Read KeyCommands
;if keyhit(205)=true then   ;exchange this and next line, keydown will fire almost constatly

If KeyDown( 205 )=True Then 
rot#=rot#-5
TurnEntity model,0,-5,0 ;next line stores rotation of player model
If rot#<0 Then rot#=Rot#+360
EndIf
If KeyDown( 203 )=True Then
rot#=rot#+5
TurnEntity model,0,5,0
If rot#>360 Then rot#=rot#-360
EndIf
If KeyDown( 208 )=True Then MoveEntity model,0,0,-1
If KeyDown( 200 )=True Then MoveEntity model,0,0,1
;Update Each Bullet
For b.bullet=Each bullet
MoveEntity b\model,0,0,3
b\dur=b\dur-1
If b\dur<0 Then
FreeEntity b\model
Delete b  ;deletes b.bullet all fields
EndIf
Next
;check collisions
UpdateWorld 
;show the world as it is now
RenderWorld

;I never Did Add life!
Text 10,10,"Life: "+life
Flip
Wend

ClearWorld()
End

Type bullet
Field model
Field dur ;if dur ends bullet disapppears
End Type


end type



stevious(Posted 2004) [#4]
Great, thanks for the replies! I've spent my last 5 years coding for the corporate world (and 5 years prior to that fixing computers...), it's time to shake off the dust and cobwebs and see if I can remember how to code for fun :-)


Rob Farley(Posted 2004) [#5]
translate entity moves an entity regardless of it's orientation:

rotateentity blob,0,90,0
moveentity blob,0,0,1

will move an entity 1 in the x direction because you have pointed it to the right.

rotateentity blob,0,90,0
translateentity blob,0,0,1

will move the entity 1 in the z direction regardless of the orientation.