Author Topic: What effect is that and how to achieve it  (Read 7114 times)

0 Members and 1 Guest are viewing this topic.

Offline Meduusa

  • ZX 81
  • *
  • Posts: 14
  • Karma: 1
    • View Profile
In ASD - Metamorphosis demo http://www.pouet.net/prod.php?which=50127 when the lines are drawn and ants run inside of lines how can this line drawing be achievend in directx? Im trying to make a scroller demo like Metamorphosis and I thing tiles is a way to go. Lets say I have a tile1 of size 512x512 under tile2 and tile2 of size 200x200 exactly in center over tile1. How can I draw a vertical line throught tile2 and see tile1 throught it?

Im very sorry for my bad english.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: What effect is that and how to achieve it
« Reply #1 on: May 20, 2008 »
If I had to guese I would say that the ants and centepedes are drawn with vector graphics I couldnt find any textures for them so I'd say that the files f.txt - f4.txt hold data for custom animation scripting using circles and lines etc. while all the other black parts are texture maps with alpha channels. Just guesing here but I have no idea what you might call that

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: What effect is that and how to achieve it
« Reply #2 on: May 20, 2008 »
It certainly looks unique, actually when you think of it from a programming point of view then the ant and centipede bodies are segmented and just follow the paths that are mined out ahead of them.

I guess that there would be many ways of creating these tunnels for the ants to follow. Perhaps they are just lots of small quads generated on the fly with a light coloured material, that would probably be the way I'd do it. It could be that the texture is actually erased to form the tunnels ahead of the creepy crawlies.

No doubt there will be better theories about how to create these tunnels than my two, so watch this space.

And there's nothing wrong with your English.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: What effect is that and how to achieve it
« Reply #3 on: May 20, 2008 »
You could have a look at the "Marching Squares" algorithm. I think something more simple is going on here. It looks like the bugs just do collision checking or some sort of path-finding using an image buffer as a collision object. The movement of the insects appears to be vector based as said before they seem to have a set speed and the angle of travel is jittered between a max and mid or left the same. The movement of the ants reminds me a bit of one of my older games-Air Brawler. As Shockwave said there are many ways to do the tunneling ants effect. I think you might google destructible terrain.
Challenge Trophies Won:

Offline Meduusa

  • ZX 81
  • *
  • Posts: 14
  • Karma: 1
    • View Profile
Re: What effect is that and how to achieve it
« Reply #4 on: May 20, 2008 »
BIG thanks to every one who ansewered I will continue working on this.

But how can i turn part of tile to transparent to see other tile under it? Can I somehow access pixels in texture and set some of them to alpha or set them match color key which will make them transparent? Or can I create 2D array copy correct data to it and then load it as a texture?

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: What effect is that and how to achieve it
« Reply #5 on: May 20, 2008 »
It must be possible to do that in Directx. (using a 2d texture I mean), it's very easy in opengl so I am assuming DX will be just as easy.
As I don't know DX though you'll have to wait for someone who does :) Someone will show you how to do it though.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: What effect is that and how to achieve it
« Reply #6 on: May 20, 2008 »
 IDirect3DDevice9::CreateTexture( )
 IDirect3DTexture9::LockRect( )

first one allocates some memory for the texture the other gives you back a pointer to the memory. It is very important that you keep the format exactly as the hardware is expecting it. for example if the pixel format is 16 bit alpha, 16 bit red, 16 bit green, 16 bit blue (D3DFMT_A16B16G16R16), you cannot hand it back 8bit red, 8bit green, 8bit blue.

http://msdn.microsoft.com/en-us/library/bb174363.aspx
http://msdn.microsoft.com/en-us/library/bb205913(vs.85).aspx
« Last Edit: May 20, 2008 by rain_storm »

Challenge Trophies Won:

Offline Meduusa

  • ZX 81
  • *
  • Posts: 14
  • Karma: 1
    • View Profile
Re: What effect is that and how to achieve it
« Reply #7 on: May 21, 2008 »
Big thanks rain_storm I will try to this out.

First I allocate memory for texture and load it

Code: [Select]
LPDIRECT3DTEXTURE9 sprite;    // the pointer to the sprite

D3DXCreateTextureFromFileEx(d3ddev,    // the device pointer
                                L"Panel2.png",    // file name to load texture from
                                D3DX_DEFAULT,    // default width
                                D3DX_DEFAULT,    // default height
                                D3DX_DEFAULT,    // no mip mapping
                                NULL,    // regular usage
                                D3DFMT_A8R8G8B8,    // 32-bit pixels with alpha
                                D3DPOOL_MANAGED,    // typical memory handling
                                D3DX_DEFAULT,    // no filtering
                                D3DX_DEFAULT,    // no mip filtering
                                D3DCOLOR_XRGB(255, 0, 255),    // the hot-pink color key
                                NULL,    // no image info struct
                                NULL,    // not using 256 colors
&sprite);    // load to sprite

2. Im not sure if Im doing this next step right

Code: [Select]
        RECT area;
D3DLOCKED_RECT area2;

SetRect(&area, 10, 10, 30, 30);  // I define area to be 20 x 20 big area from sprite
sprite->LockRect(0, &area2, &area, D3DLOCK_DISCARD); // and then I lock it

How can I access that area
can i now use sprite as a pointer and plot thing to it like

Code: [Select]
for (int i = 0; i < 30 * 30; i++)
{
    &sprite[i] = D3DCOLOR_XRGB(255, 0, 255);  // this dosent work
}
« Last Edit: May 21, 2008 by Meduusa »

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: What effect is that and how to achieve it
« Reply #8 on: May 21, 2008 »
To write to the locked rect, use "pBits" from the D3DLOCKED_RECT structure returned by IDirect3DTexture9::LockRect.
Challenge Trophies Won:

Offline Meduusa

  • ZX 81
  • *
  • Posts: 14
  • Karma: 1
    • View Profile
Re: What effect is that and how to achieve it
« Reply #9 on: May 21, 2008 »
Yeah I almost solved this one.

Heres the code

Code: [Select]

D3DXCreateTextureFromFileEx(d3ddev,    // the device pointer
                                L"image.png",    // the new file name
                                D3DX_DEFAULT,    // default width
                                D3DX_DEFAULT,    // default height
                                D3DX_DEFAULT,    // no mip mapping
                                NULL,
                                D3DFMT_A8R8G8B8,    // 32-bit pixels with alpha
                                D3DPOOL_MANAGED,    // typical memory handling
                                D3DX_DEFAULT,    // no filtering
                                D3DX_DEFAULT,    // no mip filtering
                                D3DCOLOR_XRGB(255, 0, 255),    // the hot-pink color key
                                NULL,    // no image info struct
                                NULL,    // not using 256 colors
                                &Texture);    // load to sprite

RECT area;
D3DLOCKED_RECT LockedRect;

SetRect(&area, 40, 40, 45, 45);    // area is 5 x 5
Texture->LockRect(0, &LockedRect, &area, 0); // lock target area

DWORD *lockedarea = (DWORD *)LockedRect.pBits;

for(int i=0; i<25; i++)  // 5 times 5 is 25
{
lockedarea[i] = 0x00000000;  // if I do this shouldnt this produce a square but instead it produces a line that is 25
                                                       // (pixels?) long
}

Texture->UnlockRect(0);

Some other interesting issues when I try
Code: [Select]
lockedarea[i] = 0xFFFF00FF; it produses a hot-pink line but if pink is a color-key shouldnt it be then transparent but well I can just set alpha color to 0 and dont bother whit this.

But still why this produces a line instead of square whats wrong? My SetRect() is wrong or LockRect() or maybe Im drawing it wrong?

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: What effect is that and how to achieve it
« Reply #10 on: May 21, 2008 »
Quote
But still why this produces a line instead of square whats wrong?
You need to take "pitch" into account which tells you the offset (in bytes) to get from one scanline to the next.
Although you are locking only a 5x5-area of your texture, there's still the rest of your texture (plus possibly some alignment) in memory which you have to "skip".
« Last Edit: May 21, 2008 by hellfire »
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: What effect is that and how to achieve it
« Reply #11 on: May 21, 2008 »
what hellfire said
You were indexing the texture sequencially
Code: [Select]
for(int i=0; i<25; i++)  // 5 times 5 is 25

you will have to do it something like so
Code: [Select]
for(int y=0; y<5; y++)  { // 5 times 5 is 25
for(int x=0; x<5; x++)  { // 5 times 5 is 25
i = textureX*y + x;
lockedarea[i] = 0x00000000;
}}

sorry if that aint right I can barely read c code let alone write it

Challenge Trophies Won:

Offline Meduusa

  • ZX 81
  • *
  • Posts: 14
  • Karma: 1
    • View Profile
Re: What effect is that and how to achieve it
« Reply #12 on: May 21, 2008 »
Yep I got i working
Code: [Select]

for(int x=0; x<5; x++)  // 5 times 5 is 25
{
for(int y=0; y<5; y++)
{
lockedarea[x+y * offset / 4] = 0x00000000;  // if I do this shouldnt this produce a square but instead it produces a line that is 25
}
}

But now Im noticed that Im having trouble with Z-Buffering. I use this code to draw tiles
Code: [Select]
D3DXVECTOR3 center(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 position(50.0f, 50.0f, 1.0f);
d3dspt->Draw(Texture1, NULL, &center, &position, D3DCOLOR_ARGB(alph, 255, 255, 255));

when i set Z value of position to anything non 0 my tile dosent apper

I have enabled and cleared Z-Buffer by
Code: [Select]
d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE); //this one is in init function
d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); // and this one in rendering function

Might the problem be that Im trying to draw a sprite interface (d3dspt) and not to the d3ddev? Can I enable Z-Buffering to sprite interface or is there a way to overcome this problem?

Offline Meduusa

  • ZX 81
  • *
  • Posts: 14
  • Karma: 1
    • View Profile
Re: What effect is that and how to achieve it
« Reply #13 on: May 21, 2008 »
Ahh sorry for my previous post apparantly I have to modify value of position not center I dont really understand why center doesnt work but I got it working by modifying position. :)

BIG thanks to everybody who helped me throught this I wont forget you.