What do YOU use vertex commands for?

Blitz3D Forums/Blitz3D Programming/What do YOU use vertex commands for?

puki(Posted 2004) [#1]
I have never used the 'Surface' stuff in Blitz3D - never had the need to. I realise that you can use the 'AddVertex' and 'AddTriangle' stuff for particle effect stuff, etc.

However, what else do you people do with it? For example, do people use it to build level geometry on-the-fly? I also see potential for 'Magic Carpet' type terrain deformation stuff.

I'm just intrigued as to how many people use the commands and what they do with them. I wonder if there is a fair percentage of people that don't use this stuff who could have a use for it.

Feel free to supply any code for stuff you do.


John Pickford(Posted 2004) [#2]
In my current game I'm building geometry all over the place. The landscapes, various special effects (explosions, parabolic arrows & smoke trails), text, sprites etc. Probably 90% of the polygons on screen are created in code rather than in modelled.


Rob Farley(Posted 2004) [#3]
Soft shadows are another one.

In the code archives I've added a little thing that mangles a mesh (asteriod creator). This uses the vertex commands.

Single surface text commands.


(tu) ENAY(Posted 2004) [#4]
Once you get the hang of it and some maths. Creating your own models with vertices is incredibly useful, for quads and sprites I don't think I could live without it :)


puki(Posted 2004) [#5]
Excellent, replies already coming in - keep them coming.


Dreamora(Posted 2004) [#6]
Use it for GUI system and a quad tree based world section handling.


Fry Crayola(Posted 2004) [#7]
I use it for a single surface 2D graphics system. I never liked the 3D sprites myself, instead I prefer this.

It's fast, I can use transparency, vertex colours, rotation, scaling... all whilst using the same techniques and disciplines as when using the 2D command set.

It took a while to build the engine, but once it was ready...


puki(Posted 2004) [#8]
Slightly off topic, but "Rob Cummings" once did a code archive thing where I could not see his point.

This is a Blitz3D built-in code example - can someone explain the following to me:
Graphics3D 640,480 ,16,2
camera=CreateCamera() 

ent=CreateSphere()
EntityFX ent,2 ; enable vertex colors
LightMesh ent,255,255,0,50,-20,20,-20 ; apply fake lighting

MoveEntity camera,0,2,-10 
PointEntity camera,ent

While Not KeyDown(1) 
RenderWorld
Flip 
Wend
End


However, if I comment out two lines
;EntityFX ent,2 ; enable vertex colors
;LightMesh ent,255,255,0,50,-20,20,-20 ; apply fake lighting

I see the same effect (there is no visual difference) - so, what is the point of this? In both cases I am seeing a grey sphere. Is the demo a bit lame or should I be seeing a visual effect that my Radeon is not showing me?


_PJ_(Posted 2004) [#9]
Ive never used the commands, nor felt a necessity to (for any of my projects so far, that is), however, I am glad "puki" asked this question, because some of these replies are intrestin'!!!


puki(Posted 2004) [#10]
It seems you can merrily go about adding vertices in your code, yet you seem only able to add triangles to a 'Surface' - so to make a square you'd have to use a triangle and a flipped one - even though you can legally create 4 vertices.

Theoretically (by 'AddVertex'), Blitz allows you to construct a square with 4 vertices - how do you view this - you can construct it, but how do you get to see the sucker? ie how do you attatch this to something other than a surface to see it? Or is there no benefit to using 'AddVertex' to create shapes other than triangles?


Bouncer(Posted 2004) [#11]
puki: All the shapes you create consist of triangles.

To make the square... First you add the vertices... then you build the triangles between the vertices... you can build a square with 2 triangles. You connect the vertices with addtriangle.. just connect the points 1,2,3 ... and 2,3,4. and there's your square.


puki(Posted 2004) [#12]
Ah, but I was trying to see if anyone had a work-around - of course 3D works in triangles. However, is there a use for using 'AddVertex' more than 3 times per 'shape' (not necessarily a triangle) - Blitz lets you type it in, has anyone actually bypassed 'AddTriangle' to a 'Surface' to add 'YourShape' to a 'Surface' (or something other than a 'Surface')?

It is probably not possible - but there are some crafty Blitzers about and maybe someone has - I hope it isn't "halo" as he cannot currently reply.

Of course, I may be suggesting something ridiculous - but then what happens to the values of the left over 'AddVertex' commands - you can type them in - what does Blitz do with the ones it never uses - can you later access them?


poopla(Posted 2004) [#13]
It's not possible(unless I'm missunderstanding). The only geometry representation blitz uses are triangles. I don't know what other methods DX 7 had, and he may be using some of them internally for optimized geometry data management.

There is no way to "bypassed 'AddTriangle' to a 'Surface'". Unless you draw your triangles manually :).


puki(Posted 2004) [#14]
Just to clarify what I am getting at - and I accept this could be complete rubbish:

Take the Blitz3D built-in example for 'AddTriangle' or 'AddSurface':
v0 = AddVertex (surf, -5,-5,0,  0  ,0)
v1 = AddVertex (surf,  5,-5,0,  1  ,0)
v2 = AddVertex (surf,  0, 5,0,  0.5,1)

tri = AddTriangle (surf,v0,v2,v1)


Technically, Blitz will let you add as many as you like 'AddVertex' commands under the first three - so you could have v3 = AddVertex (surf,xxxxx) all the way up to v1000 = AddVertex (surf,xxxxx)

Can you only process 3 at a time - is there a work-around to apply (for example) 20 'AddVertex' commands at once to a 'Surface'?

Edit:

On paper, you can make a square out of 4 of them.


Dreamora(Posted 2004) [#15]
still don't get your question.
you can add as many vertices to a surface as your graphic card can handle. But AddTriangle only accepts 3 Vertices.

Only workaround would be if you could set the whole thing to triangle strip / triangle fan for automatic triangle generation.


Damien Sturdy(Posted 2004) [#16]
I use them for a simple lighting effect which includes shadows, using vertexcolor and linepick... quite effective for a n00b.


Regular K(Posted 2004) [#17]
"Ah, but I was trying to see if anyone had a work-around - of course 3D works in triangles. However, is there a use for using 'AddVertex' more than 3 times per 'shape' (not necessarily a triangle) - Blitz lets you type it in, has anyone actually bypassed 'AddTriangle' to a 'Surface' to add 'YourShape' to a 'Surface' (or something other than a 'Surface')?"

CreateCube(), CreateSphere(), etc does this for you :P i know thats not what your looking for though.


Damien Sturdy(Posted 2004) [#18]
Addmesh tooo


TomToad(Posted 2004) [#19]
I think I might know what you're asking. You can add as many vertexes and trianlges to a surface as you want (or the graphics card can handle). Vertexes are basically points in 3D space and are not visible. They are basically placeholders for defining triangles. When you create the triangle, then the triangle will be visible, assuming the normals are pointing in the correct direction. The surface is basically another placeholder which isn't visible. It is something to put vertexes and triangles on.
Think of it this way, suppose you want to draw a picture on a piece of paper. You start with nothing, then you get yourself a surface, i.e. the piece of paper. Now the paper is blank without any images on it at all; however the paper does have properties which will affect the final image. It's color, texture, thickness, etc...
Now you need something to draw with, so you grab a pencil. In 3D you're "drawing implement" is the vertex. You draw with the pencil by dragging it on the paper, in 3D you draw by connecting the vertexes with lines. Once again, the pencil has it's own properties which affect the image. Color, width, hardness, percentage of carbon/lead, etc...
Now you actually draw the image on the paper by dragging the pencil on the surface. Once again, properties can be affected by pressure, direction, dullness of pencil, etc...

Now like I said before, in 3D, you "draw" by connecting the vertexes with lines to create polygons. Some rendering engines allow various types of polygons, square, rectangular, octagonal, etc... But for games, it is more efficient to draw the polygons, and more consistent accross hardware, if all the vertexes in the polygon lie on the same plane. The only way to assure this is to allow only three vertexes, i.e. a triangle. No matter how you draw the triangle, the three vertexes making it up will always be on the same plane. The creators of DirectX decided, with DirectX being made mainly for games, to use triangles exclusively for 3D rendering.

Now for your question, since the surface is not visible until you add the triangles, and since the AddTriangle command only accepts 3 vertexes, there is really no point in adding more, unless you want to make more than one triangle. Even if there was a way, it would be inconsistent among graphics cards.

Did I sufficiently confuse you yet?


puki(Posted 2004) [#20]
Nope, I'm not confused.

However, do you have to use 'AddTriangle'? In a nutshell, do you peeps create a square with 2 triangles - ie, nobody is just doing it with 4 vertices - let's assume there is no such thing as 'AddTriangle' in Blitz3D - how are you lot making complex shapes - or are you relying on 'AddTriangle'?

I'm kind of trying to work out if I need to use 'AddTriangle' or are there other ways that don't limit you to using a triangle.

The main reason was - when I looked at Blitz3D's own example code of the triangle - I thought 'Aha, 2 will make a square' - I then thought 'Hold on, I'm going to have to manually work out the position/values of the second triangle'. Then I thought 'Why not just use 4 vertices and make a square?'.


Bouncer(Posted 2004) [#21]
Yes you have to use triangle... because even the square consists of two triangles, as you already know. Triangle is the simplest shape in a 3D world so you have to build everything using those. And ofcourse you have to manually build those triangles... think of it this way... if you have lot's of vertices then there's no way blitz is going to know how you want to connect those vertices eg. what kind of shape you want to make... so you have to triangulate your mesh by hand.


Damien Sturdy(Posted 2004) [#22]
[Edited to remove bad mood swing]

DORGH

sorry, im just in a real bad mood and happened to read this at the time.


Right, you CAN do it with 4 vertices:

mesh=createmesh()
surface=createsurface(mesh)
;                    x y z u v
v1=addvertex(surface,0,0,0,0,0)
v2=addvertex(surface,1,0,0,1,0)
v3=addvertex(surface,0,1,0,0,1)
v4=addvertex(surface,1,1,0,1,1)

;                vertices to connect
tri1=addtriangle(surface,v1,v2,v3)
tri2=addtriangle(surface,v2,v4,v3)
Updatenormals mesh


Note, thats untested, but if ive written it correctly with all the syntax right, itl do a square with 4 vertices :/


TomToad(Posted 2004) [#23]
Cygnus, you actually created a 2 sided triangle.
try replacing
tri1=addtriangle(surface,v1,v2,v3)
tri2=addtriangle(surface,v1,v3,v2)

with
tri1=AddTriangle(surface,v1,v2,v3)
tri2=AddTriangle(surface,v2,v4,v3)

Now I might have the vertex orders incorrect, making the square half visible on one side and half visible on the other. I can never seem to remember wether the order should be clockwise or counterclockwise.


Damien Sturdy(Posted 2004) [#24]
Oops, i typed too fast.. Edited!


2 4 3 should be right.


TomToad(Posted 2004) [#25]
Just tested. I got the normals pointing the same way, but away from the viewer. They should go in a clockwise direction to be viewed.
tri1=AddTriangle(surface,v3,v2,v1)
tri2=AddTriangle(surface,v2,v3,v4)



puki(Posted 2004) [#26]
Hey, out of interest - assuming someone creates a relatively complex model using Blitz3D Vertex stuff. If the model is compressed into 2D (buy positioning any set of vertices to the same point in 3d space) is the overhead lower than if it was in 3D?

For example - imagine a computer keyboard accuratley modelled this way (purley using Blitz Vertex stuff) - but you take the relevent vertices and move them so in fact it is flat (2D), is the overhead less than if it where still in 3D? Obviously, you have the same amount of vertices - but is the fact that you are not applying depth a speed benefit?

I hope I explained that good enough?


TomToad(Posted 2004) [#27]
If you have the same number of vertexes, triangles, and surfaces, then it will not increase the speed. However, if you're trying to attempt at drawing something 2D, and wanted to use vertexes and triangles restricted to the X/Y plane instead of using actual 2D draw commands, sometimes that can be faster because most modern video cards are optimized for displaying 3D.


puki(Posted 2004) [#28]
Well, my thought was a kind of on-the-fly LOD - for example - imagine a Quake-style FPS - in which you have certain objects that would look good close up with depth - such as a keyboard which from a distance (or not visible) is completely flat, yet as the player approaches it, you can subtly apply the depth by moving the vertices.

I'm talking in general here - not necessarily a keyboard - maybe a large control panel that has buttons on it that you want to just subtly make 3D, because the player may view it at an angle when close to it - the panel itself will already be in 3D, it is just cosmetic things that can 'shift' in and out of 3D. Of course, you could just apply the depth separatly with primatives (add little cubes in and expand them) - but I am sort of *feeling* my way into what you can use the Blitz3D vertex stuff for.


Ziltch(Posted 2004) [#29]
If vertices are on top of each other they can end up causing flashing triangles.

This is to do with the Zbuffer ordering the triangles for display.


John Pickford(Posted 2004) [#30]
puki, flattening an object will not speed it up. You still have the same number of vertices and triangle, so there would be no point in doing that. Also, as mentioned above you'll get a lot of triangle occupying the same 'space' which causes a messy effect known as 'z fighting'.


mrtricks(Posted 2004) [#31]
I am currently using it to create a building / destruction system - in my game (FPS / RTS cross) you can order buildings built in real time, to your design specifications, then walk in and around them, and blow chunks out of them. Got the core system working quite nicely, and I'm looking forward to freeing up some more time to work on it.


N(Posted 2004) [#32]
I use them for fonts, GUIs, generating terrain, grass, particles, water, cloth simulations (those ones didn't go as well as I'd have liked), [software] vertex shaders, [software] vertex lighting, etc.

If it's something that you've wanted to do in Blitz3D, I've probably done it.


puki(Posted 2004) [#33]
I found this little tutorial thing-bob at Blitzcoder.

http://www.blitzcoder.com/cgi-bin/articles/show_article2.pl?f=gamearray12142001.html


I'm still not sure if the Blitz3D Vertex stuff is good for the creation of indoor level geometry.

The Vertex stuff seems more for 'special effects' stuff. I wonder if anyone has created a level on-the-fly with it (maybe for occlusion reasons) rather than use a pre-made level.

Edit:

Off Topic - but nice little physics tutorial:
http://www.blitzcoder.com/cgi-bin/articles/show_article2.pl?f=gamesnickbull02272002.html

and a (somewhat brief) particles tutorial:
http://www.blitzcoder.com/cgi-bin/articles/show_article2.pl?f=gamegiako07072002.html


Dreamora(Posted 2004) [#34]
For levels I prefer creating "rooms" and create a vis tree to hide stuff on "per room" base ( same for terrains. all is handled using a quad tree with the terrainmeshs as leafs )


puki(Posted 2004) [#35]
Aha, "Dreamora" - this is what I am getting at (in my slow, bumbling, "puki" way).

I assume constructing on-the-fly is preferrable for occlusion stuff - but is there any drawback? I assume you can create the geometry quickly - coz some of it can be premade stuff that you can continually re-use to construct the indoor environment as you move through it.

Are you actually creating the geometry on-the-fly with Vertex stuff - or loading in stuff - or both?


WolRon(Posted 2004) [#36]
Isn't there a Tron demo that came with Blitz3D that uses the Vertex commands to draw the wall that follows the bike on the fly? I know that I was playing with it a while back (but maybe "I" made the wall follow the bike, I can't remember because I modified it a lot).


TomToad(Posted 2004) [#37]
Under samples\mak\tron in the samples directory :-)


big10p(Posted 2004) [#38]
Honestly, I wouldn't know what to do with Blitz 3D if it didn't allow dynamic mesh manipulation.


puki(Posted 2004) [#39]
Hi, "puki" ("Vertex Virgin") here again. This Vertex stuff is very time consuming and fiddly.

Just another question: Considering a vertex is a point in 3D space, do you lot generally do your 'AddVertex' in the intended 3D space or do you position the surface afterwards?

To clarify that - imagine you are making a cube out of 6 surfaces (forget about the fact that you can 'copy' and there are easier ways to do it)

v1=addvertex(front,0,0,0,0,0)
v2=addvertex(front,1,0,0,1,0)
v3=addvertex(front,0,1,0,0,1)
v4=addvertex(front,1,1,0,1,1)

Would you lot generally identically produce 6 of these (forgetting about the easier ways of doing it) and then just position the 6 surfaces afterwards (which I think would be easier because you can just position and rotate them into place)

or, would you actually set up the 'Addvertex' commands already in the correct 3d positions (which would appear more fiddly).

I'm assuming my assumption is correct - I'm just *feeling* for any drawback - coz it it seems so much easier that it worries me.

I hope the above makes sense.


Dreamora(Posted 2004) [#40]
I would not use 6 surfaces normally.

6 indipendent quads ( 24 vertices ) are enough as the texturing problem only happens if the cube is created out of 8 vertices in which case 1 UV should hold for 3 different quads which is impossible.


WolRon(Posted 2004) [#41]
Do it whatever way is good for you.


REDi(Posted 2004) [#42]
puki you can't move surfaces individually.


simonh(Posted 2004) [#43]
Going back to your earlier question:

However, if I comment out two lines

;EntityFX ent,2 ; enable vertex colors
;LightMesh ent,255,255,0,50,-20,20,-20 ; apply fake lighting

I see the same effect (there is no visual difference) - so, what is the point of this?


The behaviour of Blitz changed a while back so that the default vertex color of meshes is not 0,0,0 but 255,255,255 - therefore using LightMesh as in the above example will not have any effect - the mesh is already fully lit.

You can get around this by first subtracting colour away from the vertices using LightMesh mesh -255,-255,-255, and then using LightMesh as you would do normally. The online command reference contains an updated example for that command:

http://www.blitzbasic.com/b3ddocs/command.php?name=LightMesh&ref=goto


puki(Posted 2004) [#44]
Aha, nice one "simonh" - I kind of felt glum for days thinking I was the only person affected by it - the built-in Blitz3D example needs updating in the next update.


puki(Posted 2004) [#45]
I decided to work-log my findings with regard to the 'Surface' stuff - will form the evenutal basis of a tutorial designed for beginners - I think Blitz3D needs something like this - because if there was already a tutorial on the 'Surface' stuff then I would be reading it now:

http://www.blitzbasic.com/logs/userlog.php?log=379&user=6822


BlackD(Posted 2004) [#46]
I use vertex commands for everything.. clearing the screen, printing text, negotiating TCP connections..

But seriously. I use them pretty heavily. Most of the geometry in my game is created in-game (terrain, buildings, bridges, etc) rather than using models. I'm even working on a 3D modeller which generates Blitz3D surface/vertex/triangle code rather than a model, then utilize BVM to load the snippets as "models". But.. I didn't say that. Cause Halo will start asking "is it done yet? is it done yet?" ;)

+BlackD


Damien Sturdy(Posted 2004) [#47]
I'm not Halo, but, is it done yet?


puki(Posted 2004) [#48]
Actually, I am starting to love using them. Have only started last week - hence 'Vertex Piglet'. Starting to find it easier to create stuff. Not played with this type of thing for probably 10 years back on the Amiga.

Tiz fun.


BlackD(Posted 2004) [#49]
The Amiga has DirectX? I seem to remember the Amiga only having COS and SIN and having to transpose all 3D coordinates to 2D manually.. I must've skipped a stage. :)


puki(Posted 2004) [#50]
Well, yeh - I wasn't doing it the exact same way. I just meant in general - playing with 3D.

When I dug out my pad of graph papper - I found a floppy disk I had done in 3D on the Amiga - with shutter, label and write protect thingy. I might re-do that in Blitz3D.


BlackD(Posted 2004) [#51]
I'm not Halo, but, is it done yet?

Naw.. about a month or so. :P Still figuring out the math for zoom levels in the 2D views. Basically, having to write vector routines. But once it's looking good enough I'll post it up to gallery.

+BlackD


WolRon(Posted 2004) [#52]
A 3D floppy? that's sad.

You should see my model of a 3D piece of paper (with letterhead even...).


puki(Posted 2004) [#53]
>' A 3D floppy? that's sad.'

True "Wolron", true. Although, 10-15 years ago that was fashionable on the Amiga and I was jolly proud of it (at the time).

I'll soon construct something a bit more advanced - I'm just getting to grips with the workings of Blitz3D's 'Surface/vertex' stuff.

However, I shall get to the 'Promised Land', some of you may die before then, but I shall get to the 'Promised Land'.


aab(Posted 2004) [#54]
maybe one day I'll use them to Create destroyable terrain, such as Halo 2 will have.


puki(Posted 2004) [#55]
"Dreamora" mentioned that he uses a vis tree to hide stuff on "per room" base ( same for terrains. all is handled using a quad tree with the terrainmeshs as leafs).

Out of interest, does anyone use Blitz3D's Surface/Vertex commands to do their own clipping? I'm assuming it is possible via 'VertexX#/Y#/Z#'.

Anyone tried it?

EDIT:
In fact, "big10p" (A.K.A. "Chris Chadwick") did a demo - I just found it.