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
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Another little bug I found:

In the file particle.cpp, the line:

Code: Select all

		rotmat.TransformVec(particle.vx,particle.vy,particle.vz);
Should be:

Code: Select all

		mat.TransformVec(particle.vx,particle.vy,particle.vz);
Otherwise, the particle emitter won't work correctly when its parent is rotated (particles direction is supposed to be affected by the direction of the emitter)
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

This one is not written in FreeBasic, but I hope it's still of interest to someone:

https://openb3d-online.sourceforge.io/

It is possible to write programs in BASIC from a web page, using OpenB3D.

The interpreter can be used from FreeBasic too (viewtopic.php?f=17&t=29109)
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Version 1.26 is online:

https://sourceforge.net/projects/minib3d/files/

It includes the bugfixes I mentioned, and some other ones. It also fixes some dependency issues on Windows
Haubitze
Posts: 44
Joined: May 20, 2016 8:42

Re: MiniB3d for FreeBasic

Post by Haubitze »

what im missing is the 32bit build, call me oldscool but for my needs i NEED it ;D

so this is only a request and successtion and noting more ;)

salute and greate work so far :)
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

For Windows or Linux?
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Since I got no answer, I assume you were talking about the windows version, so I built and added it.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by badidea »

A Rubik's cube demo:

Code: Select all

#include "openb3d/openb3d.bi"
'#include "2d2.bi"
#include "fbgfx.bi"

const as integer screen_width = 800, screen_height = 600

'-------------------------------------------------------------------------------

sub object_key_control(obj as any ptr)
	if multikey(FB.SC_UP) then TurnEntity(obj, 0, 0, 2)
	if multikey(FB.SC_DOWN) then TurnEntity(obj, 0, 0,-2)
	if multikey(FB.SC_LEFT) then TurnEntity(obj, 0, 2, 0)
	if multikey(FB.SC_RIGHT) then TurnEntity(obj, 0,-2, 0)
	if multikey(FB.SC_PAGEUP) then TurnEntity(obj, 2, 0, 0)
	if multikey(FB.SC_PAGEDOWN) then TurnEntity(obj, -2, 0, 0)
end sub

'-------------------------------------------------------------------------------

#define RGBA_A(c) (cuint(c) shr 24)
#define RGBA_R(c) ((cuint(c) shr 16) and &hFF)
#define RGBA_G(c) ((cuint(c) shr 8) and &hFF)
#define RGBA_B(c) (cuint(c) and &hFF)

#define rnd_range(low, high) (rnd(1) * ((high) - (low)) + (low))

const as long FACE_FRONT = 0 'red
const as long FACE_BACK = 1 'orange
const as long FACE_LEFT = 2 'green
const as long FACE_RIGHT = 3 'blue
const as long FACE_TOP = 4 'white
const as long FACE_BOTTOM = 5 'yellow

const as ulong CL_RED = &hB80A31 'front
const as ulong CL_ORANGE = &hFF5700 'back
const as ulong CL_GREEN = &h009C46 'left
const as ulong CL_BLUE = &h0044AF 'right
const as ulong CL_WHITE = &hFFFFFF 'top / up
const as ulong CL_YELLOW = &hFFD600 'bottom / down

'-------------------------------------------------------------------------------

type cubie_type
	dim as any ptr entity
	dim as any ptr quad(0 to 5)
	dim as ulong faceColor(0 to 5) '0 for no quad (F,B,L,F,U,D)
end type

dim as cubie_type cubie(-1 to +1, -1 to +1, -1 to +1) 'x,y,z

'set face color, 0 for no face
for x as integer = -1 to +1
	for y as integer = -1 to +1
		for z as integer =-1 to +1
			with cubie(x, y, z)
				if x = -1 then .faceColor(FACE_LEFT) = CL_GREEN
				if x = +1 then .faceColor(FACE_RIGHT) = CL_BLUE
				if y = -1 then .faceColor(FACE_BOTTOM) = CL_YELLOW
				if y = +1 then .faceColor(FACE_TOP) = CL_WHITE
				if z = -1 then .faceColor(FACE_FRONT) = CL_RED
				if z = +1 then .faceColor(FACE_BACK) = CL_ORANGE
			end with
		next
	next
next

'turn 6 quad faces to make a 6-color cube
'order: front, back, left, right, up, down
dim as single quadPitch(0 to 5) = {0, 180,   0,   0, -90, +90}
dim as single quadYaw(0 to 5) =   {0,   0, -90, +90,   0,   0}

' Set video mode 
screencontrol(FB.SET_GL_2D_MODE, FB.OGL_2D_MANUAL_SYNC)
screenres(screen_width, screen_height, 32, 1, FB.GFX_OPENGL) 'or GFX_MULTISAMPLE or GFX_ALPHA_PRIMITIVES)
Graphics3d(screen_width, screen_height, 32, 1, 1)

' Setup light and camera
var light1 = CreateLight(1)
var cam1 = CreateCamera()
CameraViewport(cam1, 0, 0, screen_width, screen_height)
PositionEntity(cam1, 0, 0, -5) 'move camera back

dim as string mystr = ""

'central pivot point (to rotate the entire cube)
var pivot = CreatePivot()

dim as integer count = 0
for x as integer = -1 to +1
	for y as integer = -1 to +1
		for z as integer =-1 to +1
			with cubie(x, y, z)
				'build a small cube from 6 quads  with each side a different color
				.entity = CreateCube(pivot) 'has parent pivot, is parent for quads
				ScaleMesh(.entity, 0.48, 0.48, 0.48)
				EntityColor(.entity, 40, 40, 40)
				MoveEntity(.entity, x, y, z)
				for i as integer = 0 to 5
					dim as ulong c = .faceColor(i)
					if c <> 0 then
						.quad(i) = CreateQuad(.entity) 'child of cubie
						EntityColor(.quad(i), RGBA_R(c), RGBA_G(c), RGBA_B(c))
						PositionMesh(.quad(i), 0, 0, -1)
						ScaleMesh(.quad(i), 0.42, 0.42, 0.50)
						RotateMesh(.quad(i), quadPitch(i), quadYaw(i), 0)
						'EntityParent(quad(i), pivot1)
					end if
				next
			end with
			count += 1
			'if count = 3 then exit for,for,for
		next
	next
next

'EntityParent(cubie, pivot2)
'PositionMesh(cubie, 2, 1, 3)
'TurnEntity(pivot, 20, 30, 0)
'RotateEntity(cubie, 20, 30, 0)

'wireframe(1)

'Make freebasic print work on 3d screen (2d2.bi)
'dim as font2d f2d

'-------------------------------------------------------------------------------

randomize timer
dim as single dPitch, dYaw, dRoll
dim as double tUpdate = timer + 1
while not multikey(FB.SC_ESCAPE)
	object_key_control(pivot) ' control cube1 with arrow keys
	TurnEntity(pivot, dPitch, dYaw, dRoll)
	UpdateWorld()
	RenderWorld()
	'f2d.print(10, 10, "Hello Cube! " & mystr)
	flip
	sleep 1
	if timer > tUpdate then
		tUpdate = timer + 3 'change somthing again in 3 second
		dim as integer choice = int(rnd_range(0, 3))
		if choice = 0 then dPitch = rnd_range(-1, +1)
		if choice = 1 then dYaw = rnd_range(-1, +1)
		if choice = 2 then dRoll = rnd_range(-1, +1)
	end if
wend
sleep
end
Screenshot here: https://nr100.home.xs4all.nl/badidea/Rubiks_cube_1.png

Next step is rotation of individual discs...

Oh, no! I just broke my cube: https://nr100.home.xs4all.nl/badidea/Rubiks_cube_2.png

Also, I just discovered that 'self parenting' (with call EntityParent) results in crash or freeze :-)
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by badidea »

The openb3d 'action' commands (such as ActTurnBy(entity,x,y,x,rate)) do not seem very useful or am I missing something?
My issues:
- First: the 'rate' is undocumented and is not time-dependent. The rate seems different if a e.g. 50 ms sleep is added in the main loop containing UpdateWorld() & RenderWorld().
- Second: There does not seem to be a way to check if the action has finished. There is only AppendAction() and FreeAction(), both not suitable for this.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

The purpose of ActTurnBy is to have an action that is performed gradually, during the main cycle (a small percentage of the action, depending on "rate", is performed each time UpdateWorld is called). This function is not much useful on its own, but if it's combined with other actions using AppendAction allows scripted animations. The command AppendAction allows to trigger further actions automatically when the specific action is completed
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by badidea »

angros47 wrote:The purpose of ActTurnBy is to have an action that is performed gradually, during the main cycle (a small percentage of the action, depending on "rate", is performed each time UpdateWorld is called). This function is not much useful on its own, but if it's combined with other actions using AppendAction allows scripted animations. The command AppendAction allows to trigger further actions automatically when the specific action is completed
Yes, but in my case I want to 'trigger' some other code when the action is completed.
And because I cannot trust the duration of the action and I cannot ask if the action is done, I cannot really use it.
A int ActionDone(Action* action) function would be usefull I think.
I can of course make my own gradual timed action (in my case a 90 degree rotation of a Rubik's cube disc).
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by badidea »

Something else. What I, as a beginner in 3d-graphics, miss in the openb3d guide in an introduction explaining the basic concepts, such as: What is a mesh, surface, vertex, entity, triangle and the relation between them. I think I do know that now, but I would have made my (and I assume of others) start with openb3d quicker.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

For now, there is no specific command to detect if an action is done (perhaps in the future I could add it, or maybe add a callback). Anyway, you could use an action to trigger another action on a dummy entity (like a pivot), and then check if it has been moved, or rotated.

About the manual: to do what you ask, a whole tutorial would be necessary, it's basically like writing a book. Anyway, the tutorials made for Blitz3D could help, perhaps.
Gunslinger
Posts: 103
Joined: Mar 08, 2016 19:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by Gunslinger »

Hello

I made a syntax highlight for geany with OpenB3D 1.26 current version now
For windows update your filetypes.freebasic and keep your build settings at (%USERPROFILE%\AppData\Roaming\geany\filedefs\filetypes.freebasic)
For lunix all users at (/usr/share/geany/filedefs/filetypes.freebasic)

the color for user1 is keyword_3 in your active colorscheme of geany
I hope someone can use this.
Still think its a good idea to put openB3D in namespace like B3D for big projects.

Code: Select all

[keywords]
#for geany under windows place in %USERPROFILE%\AppData\Roaming\geany\filedefs\filetypes.freebasic
#OpenB3D 1.26 for freebasic
user1=ambientlight ambientshader antialias clearworld graphics3d renderworld updateworld wireframe createtexture loadanimtexture loadtexture loadmaterial getbrushtexture backbuffertotex buffertotex textobuffer cameratotex depthbuffertotex texturefilter cleartexturefilters positiontexture rotatetexture scaletexture textureheight texturewidth texturename freetexture textureblend texturecoords setcubeface setcubemode createbrush loadbrush brushalpha brushblend brushcolor brushfx brushshininess brushtexture getentitybrush getsurfacebrush freebrush createshader createshadervgf loadshader loadshadervgf freeshader getshaderprogram setfloat setfloat2 setfloat3 setfloat4 setinteger setinteger2 setinteger3 setinteger4 usefloat usefloat2 usefloat3 usefloat4 useinteger useinteger2 useinteger3 useinteger4 useentity usematrix usesurface shadeentity shademesh shaderfunction shadermaterial shadertexture shadesurface createmesh loadanimmesh loadmesh copymesh repeatmesh createcone createcube createcylinder createsphere createquad paintmesh addmesh positionmesh rotatemesh scalemesh meshcsg meshcullradius countsurfaces createbone skinmesh fitmesh flipmesh updatenormals updatetexcoords meshesintersect meshdepth meshheight meshwidth getsurface createsurface addtriangle addvertex trianglevertex counttriangles countvertices paintsurface clearsurface findsurface vertexalpha vertexcolor vertexred vertexblue vertexgreen vertexnormal vertexnx vertexny vertexnz vertexcoords vertexx vertexy vertexz vertextexcoords vertexu vertexv vertexw createcamera cameraclscolor cameraclsmode camerafogcolor camerafogmode camerafogrange camerapick cameraproject projectedx projectedy projectedz cameraprojmatrix cameraprojmode camerarange cameraviewport camerazoom entityinview pickedentity pickedsurface pickedtriangle pickedx pickedy pickedz pickednx pickedny pickednz pickedtime createlight lightcolor lightconeangles lightrange createpivot createsprite createvoxelsprite loadsprite handlesprite rotatesprite scalesprite spriterendermode spriteviewmode voxelspritematerial createshadow freeshadow resetshadow createplane createterrain creategeosphere loadterrain loadgeosphere geosphereheight modifyterrain modifygeosphere terrainheight terrainx terrainy terrainz createfluid createblob fluidarray fluidfunction fluidthreshold createoctree octreeblock octreemesh createparticleemitter emitterparticlefunction emitterparticlelife emitterparticlespeed emitterrate emittervariance emittervector particlecolor particletrail particlevector moveentity pointentity positionentity translateentity rotateentity turnentity scaleentity addanimseq loadanimseq animseq animate animlength animtime animating setanimkey setanimtime extractanimseq freeentity copyentity entityalpha entitycolor entityshininess entitytexture paintentity entityfx entityautofade entityblend entityorder nameentity hideentity showentity entityparent getparententity tformnormal tformpoint tformvector tformedx tformedy tformedz countchildren entitydistance entityvisible entityx entityy entityz entitypitch entityroll entityyaw entityscalex entityscaley entityscalez findchild getchild deltapitch deltayaw entityclass entityname entitymatrix entitypick linepick entityradius resetentity collisions countcollisions collisionentity collisionnx collisionny collisionnz collisionx collisiony collisionz collisionsurface collisiontriangle collisiontime entitycollided entitybox entitytype entitypickmode getentitytype clearcollisions actfadeto actmoveby actnewtonian actscaleto acttintto acttrackbydistance acttrackbypoint actturnby actturnto actvector appendaction freeaction createconstraint createrigidbody freeconstraint freerigidbody createstencil usestencil stencilalpha stencilclscolor stencilclsmode stencilmesh stencilmode createpostfx addrendertarget postfxbuffer postfxfunction postfxshader postfxshaderpass postfxtexture vectorpitch vectoryaw getmatelement

[build-menu]
FT_00_LB=_Compile
FT_00_CM=fbc -w all "%f" -gen gcc -target win64
FT_00_WD=
FT_01_LB=Build
FT_01_CM=fbc -exx "%f"
FT_01_WD=
FT_02_LB=win32 bit
FT_02_CM=fbc -w all "%f" -target win32
FT_02_WD=
Last edited by Gunslinger on Jan 05, 2022 9:16, edited 2 times in total.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: MiniB3d for FreeBasic

Post by Munair »

Geany already supports FreeBASIC, if I'm not mistaken.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by badidea »

Munair wrote:Geany already supports FreeBASIC, if I'm not mistaken.
Yes, Gunslinger's post it to give the openb3d keywords their own color in the editor
Like this:
Image

Note that it may be better to change the Geany configuration for the current user only, as the global Geany configuration files are overwritten on re-install (according to the Geany wiki/website). The local user files are in ~/.config/geany on linux.
In my case, I had to create ~/.config/geany/filedefs/filetypes.common and add:

Code: Select all

[named_styles]
keyword_3=0x800080;;true;false
And add to my ~/.config/geany/filedefs/filetypes.freebasic:

Code: Select all

[keywords]
user1=ambientlight ambientshader antia... (etc.)
Last edited by badidea on Jan 04, 2022 20:45, edited 5 times in total.
Post Reply