Page 1 of 2
Wave effect on sprite - [SOLVED]
Posted: Thu Jul 05, 2007 8:02 pm
by DeXtr0
Hey everybody,
I want to create a wave effect (like a flag) but with Z-axis on a 3D sprite.
Does anybody know what is the fastest logical way ?
I've pained my brains but without luck, I don't get it ...
Maybe use clipsprite or perform a peek / plot instruction ?
Let me know please,
DeXtr0
P.S. A small example to point me in the right direction would be very handy

Posted: Thu Jul 05, 2007 8:11 pm
by Kaeru Gaman
when you use 3DSprites, you will have to use a whole lot of them,
because one sprite can only build an edge.
without 3Dsprites, you could use clipping to display a normal sprite rowwise,
each row a bit higher or lower. let the top-line follow a sinus curve.
faster but more mem-needing would be to prerender several animation-frames for the flag.
Posted: Thu Jul 05, 2007 8:16 pm
by Anonymous
You can use this structure for modify Sprite3D :
Code: Select all
Structure vertex
sx.f
sy.f
sz.f
rhw.f
Color.l
specular.l
tu.f
tv.f
EndStructure
Structure PB_Sprite3D
Texture.l
Vertice.vertex[4]
Width.w
Height.w
EndStructure
If i have the time, i will make a simple example.
@++
Posted: Thu Jul 05, 2007 8:29 pm
by Kaeru Gaman
an example for the clipping without sprite3D:
Code: Select all
InitSprite()
InitKeyboard()
OpenScreen(1024,768,32,"X")
CreateSprite(0,300,200)
StartDrawing(SpriteOutput(0))
For n=0 To 199
Line(0,n,300,0,RGB(32-n/8,64-n/4,255-n))
Next
For n=1 To 19
Line(0,10*n,300,0,$C0C000)
Line(15*n,0,0,200,$C0C000)
Next
DrawingMode(#PB_2DDrawing_Outlined)
Box(0,0,300,200,$FFFFFF)
StopDrawing()
Count.d = 0
SetFrameRate(60)
Repeat
ClearScreen($201008)
ExamineKeyboard()
For n=0 To 149
y.d = Sin( (50*Count+n) / 20 )
ClipSprite(0,n*2,0,2,200)
DisplaySprite(0,350+2*n,280+16*y)
Next
Count + 0.05:If Count > 100 : Count = 0 : EndIf
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Posted: Thu Jul 05, 2007 9:52 pm
by rsts
nice
cheers
Posted: Fri Jul 06, 2007 7:51 am
by DeXtr0
Hey Guys,
That example of Kaeru is very good and pretty cool. However then I'll stuck in 2D. I need the Z-axis aswell to get a depth view.
That's why I thought I had to use 3D but now i'm thinking I need the Z-axis also.. (when doing in 2D)
Meaning, related to the example: The flag would lay down (horizontally) and points towards the z-axis. <= It has to look like a carpet that lays down...
It's hard to explain but if you have a carpet in front of you, rotate it so the endside will be in the depth.
After that perform a wave effect on it.
I don't know a better way explain it, what I'm trying to
I hope it's understandable
Thanks already for all the help guys...
Regards,
DeXtr0
Posted: Fri Jul 06, 2007 8:19 am
by Kaeru Gaman
sure, I understand. it's like a perspective view of a waving flying carpet.
there, the waving would not be along the same axis as the carpet lies,
but normally orthogonal to it.
say, the carpet lies in X to Z, the waving is a sinus-movement along Y.
for something like that, you'll surely need some 3D.
this is a mesh, and it is one with quite a lot triagles, to make the waving look smooth.
using D3D or OGL for it with make it possible to enable hardware smoothing,
then you can spare a lot of triagles.
of course you could simulate something like that with Sprite3D,
because a Sprite3D IS a 2-triangle-mesh, and you can combine several S3D to a greater mesh,
but you'll need a whole lot of sprites for that,
because each single sprite in the row can only build one edge,
so you need a lot of edges to make the mesh look smooth.
each sprite3D for it's own will stay a parallelogram with straight edges.
so, perhaps you'll better use a 3D-engine, a complete mesh and hardware smoothing....
Posted: Fri Jul 06, 2007 8:45 am
by DeXtr0
Pfew that's what I thought but not hoped.. Pitty this can not be done with normal 2D manipulation...
Ok then i'll look into the 3D stuff, to find more information.
I just wanted an image to fly around, as you said in a perspective mode waving like a flag..
1000x for the clear explanation Kaeru.
Regards,
DeXtr0
Posted: Fri Jul 06, 2007 8:55 am
by Kaeru Gaman
if you really want only one image doing such movement,
and nothing else (or only little else) on the screen,
you sure can calculate each single pixel's position and draw it.
for this you'll need a fast routine to calculate the coordinates,
and a fast drawing like e.g. BitBlt or direct access to the drawing buffer.
the standard Draw-command is far too slow for such.
I didn't know what you needed it for.
if it's just a screensaver that should not show or do anything else, you surely can do it the hardcoded way.
I thought you perhaps wanted some special-effect-element within a complex game,
there you'll surely need a 3D-engine.
Posted: Fri Jul 06, 2007 9:10 am
by DeXtr0
That's no problem you did not understood it right for the first time.
It was hard for me to explain...
And yes I just want the effect go be in a screensaver or demo/intro, nothing spectacular
Ok since I'm going to do it your way, the fastest thing to calculate the coordinates and/or plotting them is using peek/plot ?
Or use BitBlt ?
Cheers,
DeXtr0
Posted: Fri Jul 06, 2007 9:25 am
by Kaeru Gaman
I have neither experience with BitBlt, nor with POKEing into the Grafix-Mem on 32bit machines,
so I can't tell wich is faster or how exactly to do it.
(last time I directly accessed the Grafix-Mem was with QuickC on a 16bit PC...)
what I can tell you is, that you'll have to optimize the algorithm for the calculation aswell.
you will need a lot of sinus-calculations, so use a precalculated table, not the build-in functions.
optimize the loops the best you can.
e.g. calculate a specific offset only once, and use a more inner loop to draw all pixels with the same offset at the same time.
..ok, such things are even harder to explain... xD
Posted: Fri Jul 06, 2007 9:30 am
by DeXtr0
OK thnx Kaeru,
Now I can try to code it..
As soon as I have it i'll show it to check the FPS..
I'm very curious what it will be...
Thanks for all the help,
DeXtr0
Posted: Fri Jul 06, 2007 9:52 am
by Psychophanta
Posted: Fri Jul 06, 2007 10:19 am
by DeXtr0
Wholy shit, no I did not knew that one
I searched a lot on the forum on wave and flag but not on : Matrice / Vagues (the french translation)
1000x thanks Psychophanta for this tip.
Regards,
DeXtr0
P.S. Sorry I created a new topic, really did not found it..
Posted: Fri Jul 06, 2007 10:44 am
by Kaeru Gaman
huh - this is quite an old thread... didn't know it.