PDA

View Full Version : making Holes in a model on the fly (of type m15)



zak
03-03-2012, 16:10
the project is to make holes in a flat rectangular model of type M15.
just click on the woody surface to make square holes, move the mouse while pressing it and you have a worm path. use arrows to rotate the surface, and P,L to move light up down, press F1 for help with keys.
the model composed from triangles and every triangle have 3 vertices, the order of vertices like this picture:
7829
i don't know if it is possible to delete the triangle vertices in the memory, but we can assign the coordinates of the second vertex to the first vertex so we have a very thin triangle (ie: a line) and the what was space inside the triangle now outside and we can look through it.
i have constructed a cubes over every consecurtive 2 triangles so to check if the mouse click is within one.
then deleting a 2 triangles which form a square. i feel something not precise here but my brain are frozen from cold.
there is something regarding the light, it is the Gray color around the holes, we can get rid of it if we turn off light. i don't know why this phenomena.

7830

references:
of course i depend heavily on the Petr tactics/plans/code in
demo_of_0192.TBASIC" IN FOLDER "TBGL_BonusPack_1_6_0_10\GUIandText\Selection" in the TBGL Bonus Pack Version: 1.6.0.10 downloaded from here
http://www.thinbasic.com/index.php?option=com_jdownloads&Itemid=95&task=viewcategory&catid=5

2- water_patch example in the thread http://www.thinbasic.com/community/showthread.php?8150-Height-of-ground-how-to-get-this

Petr Schreiber
03-03-2012, 18:39
Hi Zak,

thanks for sharing the code! I can see my original example used lot of the legacy stuff, so I fine tuned the code:

no need for UI module to handle input, TBGL has own functions now
no need to reset each key manually, TBGL_ResetKeyState() does it for all keys
TBGL_CreateWindow is marked as obsolete, I recommend using TBGL_CreateWindowEx
TBGL_SetupLightSource is marked as obsolete, TBGL_SetLightParameter gives more precision (you can just change position, or just color, not needed to specify all again and again as with the obsolete function)
changed the lighting a bit, so moving the light is more evident
added new function: holding right mouse button will create mountains, when you hold shift, it will create valley


I managed to minimize the shading artefact to just one vertex - the problem is in the SMOOTH mode, TBGL averages the normals of adjacent triangles for given point. As the deleting is implemented in the code as compressing the triangle to one point, it has very strange normal, so it "damages" the normals of the neighbors. If you switch to PRECISE mode, you will see the problem will be gone.


Petr

P.S.: During the autumn, I did a minor revision of whole BonusPack, you can download the recent version here: http://www.thinbasic.com/index.php?option=com_jdownloads&Itemid=95&task=view.download&cid=6

EDIT: Possible solution could be to not compress the triangle to single point, but redefine it to really tiny subpixel triangle with the same orientation as original. Then the normal is preserved and no artifacts should appear.

ErosOlmi
03-03-2012, 19:27
Little problem in F1 Help function: missing handle.
Better passing main window handler like: Function drawHelp(ByVal hWnd As DWord)

zak
03-03-2012, 20:17
thank you Eros and Petr, without the M15 huge number of functions i never be able to destroy visualy a model. i can't find in another langauages such an easy manipulations for models, and many people in different forums are asking about this but they are left alone.
my next project will be to destroy a wall ie a surface with thickness, and finaly a small game in which an artillery are bombing the wall to destroy it, depends on the momentum of the projectile, distance, direction, but i am too slow, and will post it if ever finished here.

Petr Schreiber
04-03-2012, 11:15
Eros, the F1 problem was introduced by me when refactoring the code, I reuploaded the attachement which fixes that and adds more help text

Zak, that sounds great! You could use TBGL_m15SetVertexRGB with some dark color to make the hole borders look "burned".
Please try the attached forgotten demo (I think I never posted it). You can click on the model of starship, and it interactively makes it explode on those places - including burned and damaged borders of the explosion and flying debris.


Petr

zak
04-03-2012, 11:57
that is a gorgeous demo Petr, i have burned the ship completely, in fact i need time to grasp the code.
http://s17.postimage.org/7xz23cuun/ship.jpg

in the example holes_in_model4 making bumps and valleys with R-click and shift R-click is a great demo it can be used in a demo to inflate virtual balloons or even in a demo to show a pregnant woman for the biology classes.
i want to add a little thing for the rectangular flat models. this is to cut the time to a half ,ie instead of looping from 1 to vertexCount we check if x is negative or positive, but this is if the model vertices have this coordinates or we need another plan if not.

If x > 0 Then
beginsCalc = vertexCount /2
square = (vertexCount /6)/2
Else
beginsCalc = 1: square = 0
EndIf
For i = beginsCalc To vertexCount Step 6
square += 1
If TBGL_PointInside3D( x, 0, z, %TBGL_OBJ_CUBE, Cubes(square).x, Cubes(square).y, Cubes(square).z, Cubes(square).r) Then
deleteSquares(i)
End If
Next

PS: another idea is to use TBGL_m15GetModelDimensions( 1, dx, dy, dz ) to see what is the half of the rectangle, i will keep thinking about this .

ErosOlmi
04-03-2012, 12:58
without the M15 huge number of functions i never be able to destroy visualy a model. i can't find in another langauages such an easy manipulations for models, and many people in different forums are asking about this but they are left alone

Petr has done an enormous amount of job inside TBGL.
He deserve a great audience. But or later it will happen.