PDA

View Full Version : entity turn...



Lionheart008
30-10-2008, 14:55
hi dear tbgl friends :)

- little question about rotating an object with EntityTurn...


' -- Create something to look at
TBGL_EntityCreateDlSlot(%sScene, %ecityground, 0, %lcityground)
TBGL_EntitySetPos(%sScene, %ecityground, 0, 0, 0)
'-- TBGL_EntityTurn(%sScene, %ecityground, 0, 90/FrameRate, 0)

or


TBGL_EntitySetPos(%sScene, %eCamera, 4,4,4)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
TBGL_Rotate GetTickCount/60,0,0,0
'-- TBGL_EntityTurn(%sScene, %ecityground, 0, 90/FrameRate, 0)


...last line... it's not ok.. ;( , I know... but how can I rotate the object in a correctly way with entity turn??? something is missing or I have doubled this cityground part...

bye, lionheart
ps: back again... new job, not enough time to create new things... ;)

Michael Clease
30-10-2008, 15:45
Frank, I dont understand your question.

to turn an entity i use TBGL_EntityTurn( SceneID, EntityID, X, Y, Z )

Try and explain your what you are doing and what you would like to do. ;)

Lionheart008
30-10-2008, 15:46
yepp!


TBGL_ClearFrame

TBGL_EntityTurn(%sSCENE, %ecityground, 0, 90/FrameRate, 0) ' Turning


TBGL_SceneRender(%sScene)

sorry, does run !!!! have corrected my own script after drinking coffee :D

- must laugh... I have found the right way...

when the example is ready I will show it :)

@ michael: yes, thanks... I have managed it some seconds before your message... you are quite right with


to turn an entity i use TBGL_EntityTurn( SceneID, EntityID, X, Y, Z )


bye, Lionheart

Lionheart008
30-10-2008, 16:46
dear tbgl friends,

some updates first of all, a nice present for tbgl beginners... a very little and easy tbgl example is ready :) "flying cities" vol 0.3a.

a) - more functions and effects will come... of course... take time to load the big objects, sorry, I will change it for a later moment... the project has just started...

b) - tbgl info button open box about open-gl-graphic uses, but not for my old machine ;)

c) - rotation of objects included and change a little the gui color

d) - you can open a new x-men dummy window from the button line ;)

e) - new light effect included :)

bye, Lionheart, nice day/evening
ps: my 5 cent for this day... enough :D

Lionheart008
31-10-2008, 01:40
I have updated the city scene in my last post...

new question: does exist a simple tbgl beginner example for "emitter" particles/objects?
the single particle emitter example is good, but just one step to high dimensioned for me ;)

good night lionheart from freezing and very cold germany

Lionheart008
31-10-2008, 15:01
hi all :)

- it's possible to get one emitter for two objects in my scene? Or it's necessary to create a new one for each new object (here: primitive, torus)?

- I have added a torus in my scene and would like to see it create emitter stuff ;)

- I see only the emitter box... and where is my torus??? Must laugh :D



'
' The particle concept
' Petr Schreiber, started on 10-04-2008, 31-10-2008 lionheart follows :)
'

Uses "TBGL", "TBEM"

BEGIN CONST
' -- Scene IDs
%sScene = 1

' -- Entity IDs
%eCamera = 1
%eLight
%eBox
%eTorus

%particleFirst
END CONST

' -- Auxiliary types
type tXYZ
x as single
y as single
z as single
END TYPE

' -- Structure used for start and end of particle life
type tParamers
scale as single
R as single
G as single
B as single
end type

type tParticle
texture as long
timeBorn as long
timeOut as long
timeFade as long
start as tParamers
target as tParamers
direction as tXYZ
end type

' -- Dummy variable for debug purposes ( maximum entities occupied )
global maxE as long

FUNCTION TBMAIN()
global hWnd As DWORD
global FrameRate AS DOUBLE

msgbox 0, "lionhearts learning tool for simple emitter with primitives :) vol 1.1a"

' -- Create and show window
hWnd = TBGL_CreateWindowEx("Single particle emitter with box and torus- press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow

%textureSmoke = 1
tbgl_Loadtexture app_Sourcepath+"Textures\x-smoke1.bmp", %textureSmoke, %TBGL_TEX_MIPMAP

' -- Create scene
TBGL_SceneCreate(%sScene)

' -- Create basic entities
' -- Create camera to look from 15, 15, 15 to 0, 0, 0

TBGL_EntityCreateCamera(%sScene, %eCamera)
TBGL_EntitySetPos(%sScene, %eCamera, 15, 15, 15)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)

' -- Create point light
TBGL_EntityCreateLight(%sScene, %eLight)
TBGL_EntitySetPos(%sScene, %eLight, 15, 10, 5)

%PARTICLE = 2
tbgl_NewList %PARTICLE
tbgl_UseDepthmask %FALSE
tbgl_UseBlend %TRUE
tbgl_Uselighting %FALSE

tbgl_BeginPoly %GL_QUADS
tbgl_Normal 0,0,1
tbgl_TexCoord2d 0,0
tbgl_Vertex -1,-1,0

tbgl_TexCoord2d 1,0
tbgl_Vertex 1,-1,0

tbgl_TexCoord2d 1,1
tbgl_Vertex 1, 1,0

tbgl_TexCoord2d 0,1
tbgl_Vertex -1,1, 0
tbgl_EndPoly

tbgl_Uselighting %TRUE
tbgl_UseBlend %FALSE
tbgl_UseDepthmask %TRUE
tbgl_EndList

' -- Create something to look at - our particle emiter
TBGL_EntityCreatebox(%sScene, %eBox, 0, 0.75, 0.75, 1.55, 0, 255, 40, 0)
TBGL_EntitySetPos(%sScene, %eBox, 0, 0, 0)

TBGL_EntityCreateTorus(%sScene, %eTorus, 0.2, 0.65, 250, 0, 0)
TBGL_EntitySetPos(%sScene, %eTorus, 0.25, 0.25, 0.25)

' -- Resets status of all keys
TBGL_ResetKeyState()

%evt_ParticleAdd = 1
%evt_ParticleProcess = 2

dim eventParticleAdd, eventParticleProcess as dword

'Fire a trigger to start running the event
eventParticleAdd = TBEM_AddEvent("Particle_Add", %evt_ParticleAdd)

'Repeat emiting each 30 ms
TBEM_SetRepeat(eventParticleAdd, %TRUE, 30)
TBEM_AddTrigger(%evt_ParticleAdd)

'Fire a trigger to start running the event
eventParticleAdd = TBEM_AddEvent("Particle_Process", %evt_ParticleProcess)
'Repeat the processing of particles each 30 ms
TBEM_SetRepeat(eventParticleAdd, %TRUE, 30)
TBEM_AddTrigger(%evt_ParticleProcess)

' -- Maxx speed
tbgl_usevsync 0

dim x, y, z as double

' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate

TBGL_ClearFrame

' -- Make the emitter behave like mad
TBGL_Entityturn(%sScene, %eBox, 0, (sin(Gettickcount/1000)*200)/FrameRate, 0)
TBGL_Entityturn(%sScene, %eBox, (sin(Gettickcount/1000)*100)/FrameRate,0, 0)
TBGL_Entitypush(%sScene, %eBox, 0, 0, 5/FrameRate)

TBGL_Entityturn(%sScene, %eTorus, 0, (sin(Gettickcount/1000)*180)/FrameRate, 0)
TBGL_Entityturn(%sScene, %eTorus, (sin(Gettickcount/1000)*150)/FrameRate,0, 0)
TBGL_Entitypush(%sScene, %eTorus, 0, 0, 5/FrameRate)


' -- Hook camera with emitor
TBGL_Entitygetpos(%sScene, %eBox, x, y, z)
TBGL_Entitygetpos(%sScene, %eTorus, x, y, z)
TBGL_EntitySetPos(%sScene, %eCamera, x+15, y+15, z+15)


TBGL_EntitySettarget(%sScene, %eCamera, %eBox)
TBGL_EntitySettarget(%sScene, %eCamera, %eTorus)

' -- Render it all
TBGL_SceneRender(%sScene)

' -- Very important, using TBEM to handle all events
TBEM_Run

TBGL_DrawFrame

' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While

Wend

TBGL_DestroyWindow
END FUNCTION

SUB Particle_Add()
' -- Variable to retrieve user data
dim particle as tParticle

' -- Get next available entity slot
dim e as long = tbgl_EntityGetFreeID(%sScene, %particleFirst)

' -- Store maximum slot occupied, just for debugging, not needed
maxE = max(maxE, e)

dim x, y, z as double
dim dx, dy, dz as double

' -- We want the box to "shoot" particles like from exhaust, so we will get vector aligned with length
tbgl_entityGetZAxis(%sScene, %eBox, dx, dy, dz)
tbgl_entityGetZAxis(%sScene, %eTorus, dx, dy, dz)

' -- Store initial data
particle.texture = %textureSmoke
particle.timeBorn = Gettickcount
particle.start.scale = rndf(0.125, 0.25)
particle.start.r = rnd(24,50)
particle.start.g = rnd(0,23)
particle.start.b = 0
particle.target.scale = particle.start.scale+rndf(1,10)

' -- We want to fade to some shade of gray
x = rnd(6,12)
particle.target.r = x
particle.target.g = x
particle.target.b = x

' -- Time out means how long the particle will be alive
particle.timeOut = 4500

' -- Time fade means the time particle takes to transform from initial color to target color
' -- This parameter MUST be smaller than timeout
' -- After reaching target color particle fades to black = invisibility
particle.timeFade = 3500

' -- direction parameter means basically delta movement per second
' -- Here I make it more random to make final efect nicer
x = rndf(1,5)
particle.direction.x = -dx * x
particle.direction.y = -dy * x
particle.direction.z = -dz * x


dim s as single

' -- We will use %eBox as particle emitter, of course in final version it will not be fixed like this
TBGL_EntityGetPos(%sScene, %eBox, x, y, z)
TBGL_EntityGetPos(%sScene, %eTorus, x, y, z)

' -- Each particle will be represented by billboard
TBGL_EntityCreateDlSlot(%sScene, e, 0, %PARTICLE)
s = particle.start.scale
TBGL_EntitySetPos(%sScene, e, x+rndf(-s,s), y+rndf(-s,s), z+rndf(-s,s))
TBGL_EntitySetScale(%sScene, e, particle.start.scale, particle.start.scale, particle.start.scale)
tbgl_entitysettexture(%sScene, e, particle.texture)
tbgl_entitysetuserdata(%sScene, e, particle)

END SUB

SUB Particle_Process()

' -- Custom timing for particle engine
' -- Because particles are handled at different FPS than scene for now

static LastParticleTime as long = GetTickCount
local TimeDelta as double = (Gettickcount-LastParticleTime)/1500

' -- Index of last particle
dim last as long = tbgl_EntityGetFreeID(%sScene, %particleFirst)-1

dim particle as tParticle ptr
dim delta, lifespan, colorspan, s, r, g, b as double

' -- Here we process each particle
for e as long = %particleFirst to last

' -- Overlap user data first
particle = tbgl_entitygetuserdatapointer(%sScene, e)

delta = gettickcount - particle.timeBorn

' -- Lifespan is normalized delta to interval [0, 1]
lifespan = delta/particle.timeOut

' -- If particle is in "live" phase, we work with it
if delta < particle.timeOut then

' -- Till timefade we interpolate target - start color
if delta < particle.timeFade then
colorspan = delta/particle.timeFade
r = particle.start.r + (particle.target.r - particle.start.r) * colorspan
g = particle.start.g + (particle.target.g - particle.start.g) * colorspan
b = particle.start.b + (particle.target.b - particle.start.b) * colorspan
else
' -- Else we converge to black
colorspan = 1-((delta-particle.timeFade)/(particle.timeOut-particle.timeFade))
r = particle.target.r * colorspan
g = particle.target.g * colorspan
b = particle.target.b * colorspan
end if

' -- Set color to particle
tbgl_EntitySetColor(%sScene, e, r, g, b)

' -- Set scale
s = particle.start.scale + (particle.target.scale-particle.start.scale)*lifespan
tbgl_EntitySetScale(%sScene, e, s, s, s)
else
' -- Else we destroy it and make the slot free for reuse
TBGL_EntityDestroy(%sScene, e)
end if

' -- Move it in specified direction
TBGL_Entitymove(%sScene, e, particle.direction.x*TimeDelta, particle.direction.y*TimeDelta, particle.direction.z*TimeDelta)

next

' -- In the end, we just make all our particles to face camera
tbgl_entitysettarget(%sScene, %particleFirst, last, %eCamera)

LastParticleTime = GetTickCount
END SUB




bye, Lionheart
my example I attach here as code script

Petr Schreiber
31-10-2008, 15:17
Hi Frank,

one detail:


tbgl_entityGetZAxis(%sScene, %eBox, dx, dy, dz)
tbgl_entityGetZAxis(%sScene, %eTorus, dx, dy, dz)


... this way you store box axis to dx, dy and dz and then you immediately overwrite it with data from torus.
You need to retrieve data for one entity, add particle there, retrieve for other, add particle there...


Petr

Lionheart008
31-10-2008, 19:22
hi petr,

it's ok, this chapter emitter is still too heavy for me... the limit is to high for me today...
I have tried some new exercises with my example and a new object in it, but without success... the second object doesn't emitting coloured things, must grinning...

- but it doesn't matter... time heals all questions and I will check this theme about emitter functions to another time... so I get no headache :) or frustrated... and it's so cold in my flat... :D must go out now with mrs. doggy... wow-wow ;D

best regards, nice evening, Lionheart