Wave effect on sprite - [SOLVED]

Just starting out? Need help? Post your questions and find answers here.
DeXtr0
User
User
Posts: 58
Joined: Tue Mar 06, 2007 12:49 pm
Location: Belgium
Contact:

Wave effect on sprite - [SOLVED]

Post 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 :wink:
Last edited by DeXtr0 on Fri Jul 06, 2007 10:20 am, edited 1 time in total.
Proud member of dAWN (www.dawncreations.com)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
Anonymous

Post 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.
@++
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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)
oh... and have a nice day.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

nice :D

cheers
DeXtr0
User
User
Posts: 58
Joined: Tue Mar 06, 2007 12:49 pm
Location: Belgium
Contact:

Post 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
Proud member of dAWN (www.dawncreations.com)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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....
oh... and have a nice day.
DeXtr0
User
User
Posts: 58
Joined: Tue Mar 06, 2007 12:49 pm
Location: Belgium
Contact:

Post 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
Proud member of dAWN (www.dawncreations.com)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
DeXtr0
User
User
Posts: 58
Joined: Tue Mar 06, 2007 12:49 pm
Location: Belgium
Contact:

Post by DeXtr0 »

That's no problem you did not understood it right for the first time.
It was hard for me to explain... :cry:

And yes I just want the effect go be in a screensaver or demo/intro, nothing spectacular :wink:

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
Proud member of dAWN (www.dawncreations.com)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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
oh... and have a nice day.
DeXtr0
User
User
Posts: 58
Joined: Tue Mar 06, 2007 12:49 pm
Location: Belgium
Contact:

Post 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
Proud member of dAWN (www.dawncreations.com)
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
DeXtr0
User
User
Posts: 58
Joined: Tue Mar 06, 2007 12:49 pm
Location: Belgium
Contact:

Post by DeXtr0 »

Wholy shit, no I did not knew that one :shock:

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..
Proud member of dAWN (www.dawncreations.com)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

huh - this is quite an old thread... didn't know it.
oh... and have a nice day.
Post Reply