PDA

View Full Version : TBGL_EntitySetFOV gives strange results



ReneMiner
20-03-2013, 01:51
I won't say the results are wrong, indeed they're fine for the view through camera into the scene, but as follows: my app is created in 4:3-window. Now I added a choice on startup, if to run fullscreen and that is mostly widescreen then...
I made some routine to check out for an appropriate angle and works fine if I order my camera-entity to TBGL_EntitySetFOV to it.
The problem is now the stuff that get's drawn into the scene as printing fonts, points etc. they do not fit their positions as the camera sees them.
Surely it has something to do that the camera-entity-view does not affect the stuff drawn from outside into the scene.

What would be the right switch to manipulate the FOV-angle for primitives (TBGL_POINT, _RECT and _Printfont etc.) so it can be else than 45 degrees also?

Petr Schreiber
20-03-2013, 11:14
Hi Rene,

As the FOV is the property of entity camera, it affects just the entities. If you need to affect 2D elements, the best way is to make separate user defined entity (http://www.thinbasic.com/community/content.php?19-tbgl-user-defined-entities) which will group these object together and integrate them to Scene-Entity system.

Alternatively, you could achieve similar effect by setting custom coordinate system with TBGL_RenderMatrix2D parameters.


Petr

ReneMiner
20-03-2013, 14:02
Can I use TBGL_GBufferDefineFromArray to retrieve something that I can put into an Entity instead of letting the function-slot always count the points in one-by-one?
Would be great since one of the things to display is just points for representing vertex-positions that is stored to an array.
But my problem here is, my Array is 3 Doubles since I need precision in calculations so it's not 3 Floats as TBGL_GBufferDefineFromArray expects.

Great would be if there would be a call as


TBGL_NewList %myList
TBGL_BeginPoly %GL_Triangles '[...Points, whatever]

TBGL_FillPolyWithFloatArrays(count, Positions(1)[,Colors(1),Texel(1),Normals(1)])
' which awaits floats and up to 4 Arrays in the same dimensions of course to read
' in count number of elements
' usual types of TBGL_TVector3F, TBGL_TRGB, TBGL_TVector2F, TBGL_TVector3F
'or
TBGL_FillPolyWithDoubleArrays(count, Positions(1)[,Colors(1),Texel(1),Normals(1)])
' which awaits double-arrays
' usual types of TBGL_TVector3D, TBGL_TRGB, TBGL_TVector2D, TBGL_TVector3D

TBGL_EndPoly
TBGL_EndList

Ok, it's not the function-names to go for - but I chose them to tell what they should do
(1) is always the first element to use
I don't know if TBGL_TVector2D and TBGL_TVector3D exist - at least TBGL_TVector3D gets colored blue and bold in thinAir- but there's nothing about them in TBGL-Helpfile...

Still a problem also is to draw the fonts into 3d-scene

Petr Schreiber
20-03-2013, 17:32
Hi Rene,

all the current mainstream GPUs work with floats, not doubles. OpenGL does have functions which handle doubles, but they need to be retargeted internally to become floats, which eats performance. Especially with large cloud of points it would mean big loss of performance.



Can I use TBGL_GBufferDefineFromArray to retrieve something that I can put into an Entity instead of letting the function-slot always count the points in one-by-one?

Yes. I would recommend generating GBuffer dynamically for each entity and store its value (handle) in entity user data. This way it is encapsulated and easily accessible to function slot entities.


TYPE CustomEntity
gBuffer AS LONG
...
END TYPE

...

' -- Somewhere in initialization
data.gBuffer = TBGL_GBufferCreate(...)

...

' -- Later in render routine
TBGL_GBufferRender(data.gBuffer)



Possible approach would be using dynamically allocated display lists (not a fixed index) + custom entity. You can allocate custom list using TBGL_NewListSpace.


TYPE CustomEntity
dlSlot AS LONG
...
END TYPE

...
' -- Somewhere in initialization
TBGL_NewListSpace(data.dlSlot, 1)
TBGL_NewList data.dlSlot
...
TBGL_EndList

' -- Later in render routine
TBGL_CallList(data.dlSlot)


Your offered syntax is interesting, but there is a problem - for tons of points, the tbgl_BeginPoly/tbgl_EndPoly approach is not recommended, it just eats too many function calls - even if the TBGL_FillPolyWithDoubleArrays would unpack it in compiled code. It is too slow even on modern PC.

TBGL_BeginPoly/TBGL_EndPoly is great for learning the basics, but not usable for high complex geometry (only if compiled in display list, which converts it to another format - but still, the compilation time would be prolonged by too many function calls).

The TBGL_Actor.taguit TBGL template creates a prototype of custom entity for you. You will just need to replace "<object>" with custom name on the beginning.


Petr

ReneMiner
20-03-2013, 19:09
OK, I got my symbolized vertices on screen at the right positions now through storing them in an entity now. Faster also since I don't have to re-read them each frame if they have not changed.

But I still got the problem that font, printed to 3d is not at the right place.

Any idea? Can i make an entity of a string somehow -easy- or do I have to go the hard way and create colored displaylists for that from a set of 3d-letters?
Currently I'm happy that I don't need any texture-slots nor additional media to run my program - and I would like to keep it that way to preserve all texture-slots for my most worshipped user.

Edit: Re-ordering the data

I think that's just necessary because TBGL does not offer complete Vertex-Types as those:
If it uses all floats so we got to live with that, the double-type is anyway just needed for calculations in a drawing-app
- floats is precise enough for display so i keep it floats here


' "Type Vertex-Position" ....
Begin Const
%TBGL_TVPosition = 0 ' which is just the existing TBGL_TVector3F-type
%TBGL_TVNormal
%TBGL_TVUV
%TBGL_TVNormalUV
%TBGL_TVColor
%TBGL_TVNormalColor
%TBGL_TVUVColor
%TBGL_TVNormalUVColor
End Const

you see they add up from the values of the single types

%TBGL_TVNormal (1) + %TBGL_TVUV (2) + %TBGL_TVColor (4) = %TBGL_TVNormalUVColor(7)



Type TBGL_TVNormal
X as Single
Y as Single
Z as Single
nX as Single
nY as Single
nZ as Single
End Type

Type TBGL_TVUV
X as Single
Y as Single
Z as Single
tU as Single
tV as Single
End Type

Type TBGL_TVNormalUV
X as Single
Y as Single
Z as Single
nX as Single
nY as Single
nZ as Single
tU as Single
tV as Single
End Type

Type TBGL_TVColor
X as Single
Y as Single
Z as Single
R as Byte
G as Byte
B as Byte
End Type

Type TBGL_TVNormalColor
X as Single
Y as Single
Z as Single
nX as Single
nY as Single
nZ as Single
R as Byte
G as Byte
B as Byte
End Type

Type TBGL_TVUVColor
X as Single
Y as Single
Z as Single
tU as Single
tV as Single
R as Byte
G as Byte
B as Byte
End Type

Type TBGL_TVNormalUVColor
X as Single
Y as Single
Z as Single
nX as Single
nY as Single
nZ as Single
tU as Single
tV as Single
R as Byte
G as Byte
B as Byte
End Type

It's easy to extend the type-list like that - maybe someday we got physics and vertex-weights also...

Extremely cool would be to pass the whole array at once instantly to an entity, just specify


Dim myArray() as TBGL_TVNormalUV
' fill my array with... triangles for example and call

TBGL_EntityCreateArrayTriangles(eScene, eEntity, myArray(1), %TBGL_TVNormalUV[, TextureID])

whoops...on screen :)