MiniB3d for FreeBasic

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
Gunslinger
Posts: 103
Joined: Mar 08, 2016 19:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by Gunslinger »

Converting https://nr100.home.xs4all.nl/badidea/OpenB3D.html
To pdf the hyperlinks in pdf still work.
Nice way to make the index and more document formats.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

@badidea, your solution seems to be the right one. How have you done it? Cross-references, hyperlinks, or what? I tried, but I can't get it to work
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by badidea »

I followed this help: https://help.libreoffice.org/6.1/en-US/ ... ences.html
It took me a while to figure it out as well. It looked cumbersome, but it wasn't so bad actually. I'll try to post a few screen shots...

A useful tool is the 'navigator window / sidebar' which I found in the 'View' menu. It show links and and references in the document.
https://nr100.home.xs4all.nl/badidea/Li ... idebar.png

The create 'reference targets' and insert links to these targets, you need the 'Fields / Cross-references' window, in the 'Inert' menu.
https://nr100.home.xs4all.nl/badidea/Li ... window.png

Setting reference target names looks like this. Keep the target selected in the document while doing this. I assigned the name "ref_ActNewtonian'.
https://nr100.home.xs4all.nl/badidea/Li ... erence.png

Inserting references looks like this. Select insert location in document, select the target in the 'Fields / Cross-references' window and insert.
https://nr100.home.xs4all.nl/badidea/Li ... erence.png

You can keep the 'Fields / Cross-references' window open while adding reference targets and inserting them in the document. You can even copy/paste between the document and this window so you can quickly assign names for the targets.

From the 'navigator window / sidebar' it should also be possible to drag references into the document I think, but I have not figure out yet how to do that.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

I made some tests. In the end, it seems to work if I don't use references, but bookmarks.

About the layout on the sourceforge wiki: it is correct, but incomplete (since it still doesn't have the categories for post processing, for metaballs, and so on) so it needs reworking
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Still working on it, not all links are done yet, but this is just to give an idea

https://www.mediafire.com/file/8ole5ek7 ... D.odt/file
Gunslinger
Posts: 103
Joined: Mar 08, 2016 19:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by Gunslinger »

angros47 wrote:Still working on it, not all links are done yet, but this is just to give an idea

https://www.mediafire.com/file/8ole5ek7 ... D.odt/file
I don't mind the format i'm already happy that you do document and support the openB3D functions.
Maybe you can get some inspiration from this manual index: https://www.debian.org/releases/stable/ ... ex.en.html
with the 1.1 and 1.2 style.
And a another idea is to put the full function as name with parameters like this: https://www.raylib.com/cheatsheet/cheatsheet.html

Something else i have trouble with is the name of the function for some Entities
When is wire code with openB3D i keep forgetting what comes first bij Moving, rotate or coloring Entities.
Example:

Code: Select all

ColorEntity box,127,0,0 
EntityMove box,5,0,0
Yes i know you did not make the names, but sure is confusing.

Keep up the good work.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

To remember, think about how you would give an order to someone in English: do you say "take this", or "this take"? In plain English, you would say something like "Move the entity X by 3 inches", or so on. So, first the verb, then the object, as a general rule
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by badidea »

A suggestion: Add to the top a title, date or version, author and link to the project location.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Fixed
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Little experiment: OpenB3D + Lua inside FreeBasic

https://www.mediafire.com/file/rue9610i ... ar.gz/file

For now, Linux only, sorry. Anyway, it shows that it's possible to use OpenB3D features from a scripting language, as well.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Found a little bug: in functions.cpp, the functions EntityClass, EntityName and TextureName should be changed in this way:

Code: Select all

const char* EntityClass(Entity* ent){
	//return ent->EntityClass().c_str();
	return ent->class_name.c_str();
}

const char* EntityName(Entity* ent){
	//return ent->EntityName().c_str();
	return ent->name.c_str();
}

const char* TextureName(Texture* tex){
	//return tex->TextureName().c_str();
	return tex->file.c_str();
}

Otherwise, depending on the compiler optimizations, they might return garbage
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: MiniB3d for FreeBasic

Post by D.J.Peters »

@angros47 first thank you for the pdf good job (I know how many time are needed to describe all commands)

The name string bugs are a good find also :-)

I know how the the lib works but I don't understand your implemenation of the octree :-(
pdf wrote:OctreeBlock() The size of the mesh should fit between -1,-1,-1 and 1,1,1.
If you add a static mesh to the tree why should it size in range of -1.0 .. +1.0 ?
I mean a mesh of a house or a bridge are much bigger !
How to handle for example If you add a static mesh wich overlaps more than one octree cell's ?
pdf wrote:...and at a position that tries to match the given coordinates X, Y, Z (referred to the octree, not to the world).
What are the x,y,z octree coords mean ?

Can you post one simple example that shows how the OctreeMesh() command works
and a second one for the OctreeBlock() command please ?

Joshy
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

About the first question: the mesh should fit between -1,-1,-1 and 1,1,1, but it is not mandatory: this is just because during the rendering, the octree cell is automatically scaled down, by halving its width, height, and depth at each level: at level 0 these measures are the same of the octree measures (you set them with CreateOctree), at level 1 they are halved, at level 2 divided by four and so on.

So, if you do CreateOctree (100,100,100) , a cell at level 2 would be 25,25,25. If you have a block (created with OctreeBlock), and you use for that block a cube made with CreateCube, it will be scaled to fit that cell size perfectly. Meshes created with the graphic primitives (CreateSphere, CreateCone, CreateCube and so on) usually fit between -1,-1,-1 and 1,1,1, so the octree expects a mesh of that size (if you created a mesh of different size you can scale it using FitMesh). If you use a larger, or smaller mesh, it's not an issue: the mesh will be rendered anyway, it will just be larger than the octree cell. It shouldn't cause problem, since the octree cell is virtual, it is not something visible on the screen, although it might disappear if the cell is completely out of view (the scene manager, expecting that the mesh is completely inside the cell, would conclude that the mesh is not visible and so it would not render it, not knowing that the overlapping part of the mesh might be still in view). In some rare cases having a block that overlaps the octree cell might be useful, so I didn't made the use of a fitting mesh mandatory (hence why I wrote "should" and not "must"): otherwise I would have included a call to FitMesh in the OctreeBlock command

OctreeBlock is supposed to be used to set the "bricks", to create complex levels (in Minecraft style, for example, or in earlier Tomb Raider style). Although MineCraft uses also CSG, not just octrees, to manage so many blocks.

OctreeMesh, instead, is supposed to be used if you want to use the octree as a scene manager: in fact, if you have a complex scene, with thousands or more of meshes, the default scene manager would be pretty slow, since it checks for each mesh if it is in view of the camera before rendering it: an octree can be faster, because it can group several meshes at once: if one section of the octree is out of view, all the meshes assigned to that section will be out of view too, and there is no need to check them one by one.

So, if you want to place a house, or a bridge in an octree, you should use OctreeMesh, not OctreeBlock

About the coordinates: locating a specific cell in the octree might not be so easy, since each level has a different amount of cells, and they are of a different size than other levels: so, instead of numbering them, OctreeMesh and OctreeBlock (the only commands that need to access a specific cell of the octree) try to locate it automatically, according to the position (so they accept coordinates). If the octree has just been created, the coordinates are the same of the world coordinates. But the octree can also be moved, rotated and scaled like any other entity. In that case, world coordinates must be transformed to local coordinates.

This is an old demo I wrote years ago: it shows how the two commands can be used (OctreeMesh requires to duplicate a mesh, or at least to instance it, if you want to have it appear more than once, and to position it, while OctreeBlock does all the work on its own):

Code: Select all

#include "openb3d.bi"


screen 18,  32, , &h10002 

	
Graphics3d 640,480,32,1,1


var camera=createcamera(0)
'cameraclscolor camera,0,255,0
var cube=createcone'sphere(80)
moveentity cube,0,0,5
'flipmesh cube

'scalemesh cube,.5,.5,.5

var x=createoctree(2,2,2)

var light=createlight()
moveentity light,10,10,10
pointentity light,cube
moveentity camera,0,0,-5


OctreeMesh x, cube,0,1,0,0

EntityPickMode x,2


var cube2= createcube
var cube4= createcube

entityalpha cube2,.5
entityalpha cube4,.5
scalemesh cube2,.25,.25,.25


EntityPickMode cube2,2

for i as single=-1.5 to 1.5 step .5
	var cube= repeatmesh(cube2)
	EntityPickMode cube,2
	positionentity cube,.25,i+.25,.25
	Octreemesh x, cube,3,0,i,0,0
	Octreeblock x, cube4,3,1,i,0,0

next
'	OctreeBlock x, cube2,2,0,0,0,5,5


'freeentity cube
'wireframe 1




EntityRadius x,2

EntityPickMode cube,2
Dim CurrentX     As Integer
Dim CurrentY     As Integer
Dim MouseButtons As Integer



'scaleentity x,1,3,1

var sphere=Createsphere() 

scaleentity sphere,.1,.1,.1
entitycolor sphere,255,0,0

'x=camera
dim key as string

var zzzz=copyentity(x)


do


	GetMouse CurrentX, CurrentY, , MouseButtons

	CameraPick (camera,CurrentX,480-CurrentY) 
	PositionEntity sphere,PickedX(),PickedY(),PickedZ()


	key=inkey
        if key=" " then moveentity x,.1,0,0
        if key="z" then freeentity x':end
        if key=chr(255)+"H" then turnentity x,1,0,0,0
        if key=chr(255)+"P" then turnentity x,-1,0,0,0
        if key=chr(255)+"M" then turnentity x,0,-1,0,0
        if key=chr(255)+"K" then turnentity x,0,1,0,0

	updateworld 1
	renderworld
sleep 1
	flip
loop until key=chr(27)
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: MiniB3d for FreeBasic

Post by D.J.Peters »

@angros47 again thank you :-)

Joshy
Post Reply