Posted: 14th May 2003 1:07
And a little "make a triangle with memblocks" tutorial.

+ Code Snippet
sync on

rem setting the triangle vars
polys=1
x1#=-3.0 : y1#=2.0 : z1#=1.0
x2#=3.0 : y2#=2.0 : z2#=-1.0
x3#=-1.0 : y3#=-1.0 : z3#=0.0

rem make the memblock with the right size (Each poly has 3 vertices with 36 bytes of data each)
rem plus another 12 bytes for the header
make memblock 1,(polys*3*36)+12

rem write the header
rem FVF format (4 bytes, so a dword) this is normally 338
write memblock dword 1,0,338

rem FVF size (in this case 36 bytes)
write memblock dword 1,4,36

rem Number of vertices
write memblock dword 1,8,polys*3

rem writing data for the first vertex
rem position (3 floats(float=4 bytes) for the x,y and z position of the vertex point)
write memblock float 1,12,x1#
write memblock float 1,16,y1#
write memblock float 1,20,z1#
rem normal (again 3 floats) we well set it so each vertex point faces the camera (not normal)
write memblock float 1,24,0
write memblock float 1,28,0
write memblock float 1,32,-1.00
rem color (as a dword, or as 4 bytes blue,green,red,alpha)
write memblock dword 1,36,rgb(255,0,0)
rem UV texture coordinates (2 floats) doesn't matter for now, because we don't give it a texture
write memblock float 1,40,0.00
write memblock float 1,44,0.00

rem writing data for the second vertex
rem position (3 floats(float=4 bytes) for the x,y and z position of the vertex point)
write memblock float 1,12+36,x2#
write memblock float 1,16+36,y2#
write memblock float 1,20+36,z2#
rem normal (again 3 floats) we well set it so each vertex point faces the camera (not normal)
write memblock float 1,24+36,0
write memblock float 1,28+36,0
write memblock float 1,32+36,-1.00
rem color (as a dword, or as 4 bytes blue,green,red,alpha)
write memblock dword 1,36+36,rgb(0,255,0)
rem UV texture coordinates (2 floats) doesn't matter for now, because we don't give it a texture
write memblock float 1,40+36,1.00
write memblock float 1,44+36,0.00

rem writing data for the third vertex
rem position (3 floats(float=4 bytes) for the x,y and z position of the vertex point)
write memblock float 1,12+72,x3#
write memblock float 1,16+72,y3#
write memblock float 1,20+72,z3#
rem normal (again 3 floats) we well set it so each vertex point faces the camera (not normal)
write memblock float 1,24+72,0
write memblock float 1,28+72,0
write memblock float 1,32+72,-1.00
rem color (as a dword, or as 4 bytes blue,green,red,alpha)
write memblock dword 1,36+72,rgb(0,0,255)
rem UV texture coordinates (2 floats) doesn't matter for now, because we don't give it a texture
write memblock float 1,40+72,0.50
write memblock float 1,44+72,1.00

rem make a mesh out of this memblock
make mesh from memblock 1,1

rem make an object with this mesh
make object 1,1,0



position camera 0,0,-10


do

sync
loop


Writing this, I found out that you can actually set the transparency for a vertex point. Could be used for cool effect (vertex points slowly fading away as a dying effect or as a teleportation effect)


Kevil
Posted: 24th May 2003 15:09
thank you very much for the tuto, now I understand better how it work

I'm doing my best for the editor, and now I'm working on a system that create a ground without the randomize so we'll have smooth hills
Posted: 24th May 2003 16:59
Oh! - So DBP does support vertex alpha!
Posted: 24th May 2003 17:05
@Kevil

I tried replacing the colour DWORD with 4 bytes to experiment with alpha, but it didn't make any difference what value I set the alpha byte to. Could you give a demo for alpha like this?
Posted: 24th May 2003 18:24
@Rob:
Have you tried to set object transparency to one or two?
Posted: 24th May 2003 18:37
Yeah, you have to set the object transparency to 1, but after some testing, I found out that vertex alpha only works when you don't have a texture on the object.

Kevil
Posted: 24th May 2003 18:59
Kevil - I got vertex alpha to work after applying a texture. However, I set up vertex alpha + transparency, THEN applied the texture.
Posted: 24th May 2003 19:12
OK Got it!

After altering vertex alpha, you must:

1) Recall SET OBJECT TRANSPARENCY
2) Retexture the object

Eg: An addition to your code (swap the image for one on your HD)

+ Code Snippet
sync on: sync rate 0

rem setting the triangle vars
polys=1
x1#=-3.0 : y1#=2.0 : z1#=1.0
x2#=3.0 : y2#=2.0 : z2#=-1.0
x3#=-1.0 : y3#=-1.0 : z3#=0.0

rem make the memblock with the right size (Each poly has 3 vertices with 36 bytes of data each)
rem plus another 12 bytes for the header
make memblock 1,(polys*3*36)+12

rem write the header
rem FVF format (4 bytes, so a dword) this is normally 338
write memblock dword 1,0,338

rem FVF size (in this case 36 bytes)
write memblock dword 1,4,36

rem Number of vertices
write memblock dword 1,8,polys*3

rem writing data for the first vertex
rem position (3 floats(float=4 bytes) for the x,y and z position of the vertex point)
write memblock float 1,12,x1#
write memblock float 1,16,y1#
write memblock float 1,20,z1#
rem normal (again 3 floats) we well set it so each vertex point faces the camera (not normal)
write memblock float 1,24,0
write memblock float 1,28,0
write memblock float 1,32,-1.00
rem color (as a dword, or as 4 bytes blue,green,red,alpha)
write memblock dword 1,36,rgb(255,0,0)
rem UV texture coordinates (2 floats) doesn't matter for now, because we don't give it a texture
write memblock float 1,40,0.00
write memblock float 1,44,0.00

rem writing data for the second vertex
rem position (3 floats(float=4 bytes) for the x,y and z position of the vertex point)
write memblock float 1,12+36,x2#
write memblock float 1,16+36,y2#
write memblock float 1,20+36,z2#
rem normal (again 3 floats) we well set it so each vertex point faces the camera (not normal)
write memblock float 1,24+36,0
write memblock float 1,28+36,0
write memblock float 1,32+36,-1.00
rem color (as a dword, or as 4 bytes blue,green,red,alpha)
write memblock dword 1,36+36,rgb(0,255,0)
rem UV texture coordinates (2 floats) doesn't matter for now, because we don't give it a texture
write memblock float 1,40+36,1.00
write memblock float 1,44+36,0.00

rem writing data for the third vertex
rem position (3 floats(float=4 bytes) for the x,y and z position of the vertex point)
write memblock float 1,12+72,x3#
write memblock float 1,16+72,y3#
write memblock float 1,20+72,z3#
rem normal (again 3 floats) we well set it so each vertex point faces the camera (not normal)
write memblock float 1,24+72,0
write memblock float 1,28+72,0
write memblock float 1,32+72,-1.00
rem color (as a dword, or as 4 bytes blue,green,red,alpha)
write memblock byte 1,36+72,0
write memblock byte 1,36+73,0
write memblock byte 1,36+74,255
write memblock byte 1,36+75,0
rem UV texture coordinates (2 floats) doesn't matter for now, because we don't give it a texture
write memblock float 1,40+72,0.50
write memblock float 1,44+72,1.00

rem make a mesh out of this memblock
make mesh from memblock 1,1

rem make an object with this mesh
make object 1,1,0



position camera 0,0,-10

set object transparency 1,1

Load Image "C:Inetpubwwwrootrwknighttzgfxcdrom.bmp",1
texture object 1,1

do
   If upkey() then vaup()
   If downkey() then vadown()
   cval = memblock byte(1,36+75)
   text 20,20,"Current Vertex Alpha: " + str$(cval)
   text 20,40,"Screen FPS: " + str$(Screen FPS())
sync
loop

function vaup()
   current = memblock byte(1,36+75)
   if current < 255
      write memblock byte 1,36+75,current+1
      change mesh from memblock 1,1
      change mesh 1,0,1
      texture object 1,1
      set object transparency 1,1
   endif
endfunction

function vadown()
   current = memblock byte(1,36+75)
   if current > 0
      write memblock byte 1,36+75,current-1
      change mesh from memblock 1,1
      change mesh 1,0,1
      texture object 1,1
      set object transparency 1,1
   endif
endfunction


With P4.1 - I can do this in realtime

This could be VERY useful. For example, you could have water which gets darker and more opaque as it gets deeper.

Another use for this would be a beam effect. You could use vertex alpha to make the ends of the trail more and more feint.
Posted: 24th May 2003 19:52
Oh cool! That could definately be useful.

Kevil
Posted: 24th May 2003 20:12
gr8 code comrade
Posted: 25th May 2003 0:01
Kevil, look at mikes diary entry a few weeks back for the reason for size restrictions
Posted: 25th May 2003 1:25
@ The Communist
Your avatar pops up a password box when viewed.
Posted: 25th May 2003 10:02
> you could have water which gets darker and more opaque as it gets deeper
Have you just understood it?
Posted: 25th May 2003 19:22
"Have you just understood it?"

[Goes red-faced]
Posted: 25th May 2003 20:44
I don't have understood
Posted: 27th May 2003 12:26
> [Goes red-faced]
sorry
Posted: 27th May 2003 19:19
Oooh. Ive just gone all goosebumply over the mention of a tutorial for this...

Sounds great. Along with rudimentory Physics stuff, i reckon everyone needs to learn this. Good luck. Excellent stuff. And please, that tutorial... x-d