DieHard Wolfers Forum Index DieHard Wolfers
A Wolfenstein 3d Fan Community


  Hosted by: MCS & Areyep.com - Designed by: BrotherTank

Original Yahoo Forum - Die Hard Archives

AReyeP HomepageAreyep Homepage DieHard Wolfenstein BunkerDieHard Wolfenstein Bunker Log inLog in RegisterRegister Banlist FAQFAQ Search ForumsSearch

  Username:    Password:      Remember me       

[Tutorial] Directional 3D Actor types
Page 1 of 1
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page BottomView Next Topic
Post new topicReply to topic
Author Message
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 6:23 ago.

Topics: 165
Posts: 8252
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Thu Oct 01, 2009 6:49 pm
   Subject: [Tutorial] Directional 3D Actor types
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

Want to have a blastable fence in your game? How about shattering glass? Using Ripper's Directional 3D Spites Tutorial alone, you won't achieve this effect by giving the Actors a Directional 3D Flag like FL_DIR_HORIZ_MID or FL_DIR_VERT_MID. But with these code changes, you'll be able to get these new types of Actors to display just like your regular Directional 3D Objects. Unless I've goofed with the tutorial that is. Smile

Note that this code is definitely not the greatest way of coding in the new feature. But for the way I plan to design my WIP mod, it leaves the code in a form easier for me to expand it as I need to. And I really wanted to post the code before I had any chance of losing it.

Known issues: If you design something like a spinning blade with this code, its image won't "flip around" like it should when viewing it from left to right. This is because I haven't changed the code to display such things correctly. Feel free to post a bugfix. Smile

Note also that these types of Actors can't move around properly until you make significant code changes. This is because it uses the "speed" variable to determine what directional type the Actor should be in the Directional 3D structure.

In this version of the code, the Directional 3D types always appear in the center, not in the "front" or "back" like the Directional 3D Sprites tutorial. But you can expand the code below if that really bothers you. Smile

Okay, let's begin. First, let's enable a new actor type called "fenceobj" and "en_fence" in WL_DEF.H. Use an "Adding new enemies" tutorial to find where this is coded. Now, do a search for "Scale3DShape". You should be brought to this:

::: CODE :::
    void Scale3DShape(byte *vbuf, unsigned vbufPitch, statobj_t *ob);

Right below that, add this:
::: CODE :::
    void Scale3DShapeActor(byte *vbuf, unsigned vbufPitch, objtype *ob, short ThreeDimFlag);


Now, open up WL_GAME.CPP. In this case, we enable two types of Actors in the code. One appears in slot 433 of the Objects List, and the other appears in slot 434. This is because 433 is vertical and 434 is horizontal.

::: CODE :::
                case 433: //vertical
                case 434: // horizontal
                    SpawnFence (tile-433,x,y);
                    break;
This gives the "fence" spawner a value of Zero if it's called from slot 433 of the Objects List (making it vertical), and a value of 1 if it's called from slot 434 (making it Horizontal). Alternatively, you might put:

::: CODE :::
                case 433: //vertical
                    SpawnFence (0,x,y);
                    break;
                case 434: // horizontal
                    SpawnFence (1,x,y);
                    break;


Now, let's go to WL_ACT2.CPP. You can find how to add the various amounts of health to your new enemy, and enable the enemy's new statetypes. But we'll do some different code for actually spawning him.

::: CODE :::
/*
===============
=
= SpawnFence
=
===============
*/

void SpawnFence (int actormisc, int tilex, int tiley)
{
    SpawnNewObj (tilex,tiley,&s_fencestand);
    newobj->speed = (-1-actormisc); // -1 if vertical
    newobj->obclass = fenceobj;
    newobj->hitpoints =starthitpoints[gamestate.difficulty][en_fence] ;
    newobj->dir = nodir;
    newobj->flags |= FL_SHOOTABLE|FL_AMBUSH;
}


You're probably asking, "WTF is up with the negative speed setting?" Well, the DIR3D code reads the Flags variable to find if the sprite it draws is Directional 3D or not. The problem is, adding the "SHOOTABLE" value to Flags gives the 3D values bad data. So we have to define the Actor's Directional 3D data in a different source. No Actor in the Wolf3D has been coded with a speed below Zero, AFAIK. Smile

Now, go into WL_DRAW.CPP, and do a search for "*transsprite". You should be brought to this:

::: CODE :::
#ifdef USE_DIR3DSPR
  statobj_t *transsprite;

Right below that, add this:
::: CODE :::
  objtype   *transactor;
You'll find out why soon. Smile

Do a search for "transsprite", and you should be brought to these lines:

::: CODE :::
#ifdef USE_DIR3DSPR
        if(statptr->flags & FL_DIR_MASK)
            visptr->transsprite=statptr;
        else
            visptr->transsprite=NULL;
#endif
Right above that, add this:
::: CODE :::
        visptr->transactor=NULL;

Serach again for "transsprite". You should find this:
::: CODE :::
                visptr->flags = (short) obj->flags;
#ifdef USE_DIR3DSPR
                visptr->transsprite = NULL;
#endif

Change that to this:
::: CODE :::
                visptr->flags = (short) obj->flags;

#ifdef USE_DIR3DSPR
              visptr->transsprite=NULL;
              visptr->transactor=NULL;

    switch (obj->speed)
           { case -1:
                  visptr->flags = FL_DIR_VERT_MID; visptr->transactor=obj; break;
             case -2:
                  visptr->flags = FL_DIR_HORIZ_MID; visptr->transactor=obj; break; }
#endif

Now, do a search for USE_DIR3DSPR. You should be brought to:
::: CODE :::
        // draw farthest
        //
#ifdef USE_DIR3DSPR
        if(farthest->transsprite)
            Scale3DShape(vbuf, vbufPitch, farthest->transsprite);
        else

Change those lines to
::: CODE :::
        // draw farthest
        //
#ifdef USE_DIR3DSPR
    if(farthest->flags & FL_DIR_POS_MASK) {
        if(farthest->transactor != NULL) Scale3DShapeActor(vbuf, vbufPitch, farthest->transactor, farthest->flags);
        else if(farthest->transsprite) Scale3DShape(vbuf, vbufPitch, farthest->transsprite); }
        else
Let me tell you what these code changes are all about. First off, the "transactor" variable has *nothing* to do with the TransformActor routine in the same file. Instead, this variable is set to "NULL" until a Directional 3D Actor is found. Then that variable will have the number the 3D code should call for it. You can't send this number through Scale3DShape because it reads a different integer type than the Actors use.

We finally reach the last file, and it's WL_DIR3DSPR.CPP. Go the very end of the file. Just above the "#endif", add this big, bulky, over-inflated (not to mention repetitious) routine:

::: CODE :::
void Scale3DShapeActor(byte *vbuf, unsigned vbufPitch, objtype *obj, short ThreeDimFlag)
{
    fixed nx1,nx2,ny1,ny2;
    int viewx1,viewx2;
    fixed diradd;
    fixed playx = viewx;
    fixed playy = viewy;

    int ThreeDimShapenum = obj->state->shapenum;

    //
    // the following values for "diradd" aren't optimized yet
    // if you have problems with sprites being visible through wall edges
    // where they shouldn't, you can try to adjust these values and SIZEADD
    //

    diradd=0x8000;


    if(ThreeDimFlag & FL_DIR_VERT_FLAG)     // vertical dir 3d sprite
    {
        fixed gy1,gy2,gx,gyt1,gyt2,gxt;
        //
        // translate point to view centered coordinates
        //
        gy1 = (((long)obj->tiley) << TILESHIFT)+0x8000-playy-0x8000L-SIZEADD;
        gy2 = gy1+0x10000L+2*SIZEADD;
        gx = (((long)obj->tilex) << TILESHIFT)+diradd-playx;

        //
        // calculate newx
        //
        gxt = FixedMul(gx,viewcos);
        gyt1 = FixedMul(gy1,viewsin);
        gyt2 = FixedMul(gy2,viewsin);
        nx1 = gxt-gyt1;
        nx2 = gxt-gyt2;

        //
        // calculate newy
        //
        gxt = FixedMul(gx,viewsin);
        gyt1 = FixedMul(gy1,viewcos);
        gyt2 = FixedMul(gy2,viewcos);
        ny1 = gyt1+gxt;
        ny2 = gyt2+gxt;
    }
    else                                    // horizontal dir 3d sprite
    {
        fixed gx1,gx2,gy,gxt1,gxt2,gyt;
        //
        // translate point to view centered coordinates
        //
        gx1 = (((long)obj->tilex) << TILESHIFT)+0x8000-playx-0x8000L-SIZEADD;
        gx2 = gx1+0x10000L+2*SIZEADD;
        gy = (((long)obj->tiley) << TILESHIFT)+diradd-playy;

        //
        // calculate newx
        //
        gxt1 = FixedMul(gx1,viewcos);
        gxt2 = FixedMul(gx2,viewcos);
        gyt = FixedMul(gy,viewsin);
        nx1 = gxt1-gyt;
        nx2 = gxt2-gyt;

        //
        // calculate newy
        //
        gxt1 = FixedMul(gx1,viewsin);
        gxt2 = FixedMul(gx2,viewsin);
        gyt = FixedMul(gy,viewcos);
        ny1 = gyt+gxt1;
        ny2 = gyt+gxt2;
    }

    if(nx1 < 0 || nx2 < 0) return;      // TODO: Clip on viewplane

    //
    // calculate perspective ratio
    //
    if(nx1>=0 && nx1<=1792) nx1=1792;
    if(nx1<0 && nx1>=-1792) nx1=-1792;
    if(nx2>=0 && nx2<=1792) nx2=1792;
    if(nx2<0 && nx2>=-1792) nx2=-1792;

    viewx1=(int)(centerx+ny1*scale/nx1);
    viewx2=(int)(centerx+ny2*scale/nx2);

    if(viewx2 < viewx1)
    {
        Scale3DShaper(viewx2,viewx1,ThreeDimShapenum,ThreeDimFlag,ny2,ny1,nx2,nx1,vbuf,vbufPitch);
    }
    else
    {
        Scale3DShaper(viewx1,viewx2,ThreeDimShapenum,ThreeDimFlag,ny1,ny2,nx1,nx2,vbuf,vbufPitch);
    }
}

All right, I believe that should do it. You should Rebuild all your source files when compiling, or you might find the results unpredictable.

Feel free also to post code optimizations, as I already know they're badly needed. Smile

Edit: Corrected name in Spawn routine. Thanks to Adam for the bug report. Smile

Second edit: Elaborated the WL_GAME.CPP part of this tutorial.


Last edited by Tricob on Fri Oct 02, 2009 5:33 am; edited 2 times in total
Metalor
DieHard Mutant
DieHard Mutant


Joined: 24 Aug 2005
Last Visit: 1:36 ago.

Topics: 95
Posts: 914
Location: California
usa.gif

PostPosted: Thu Oct 01, 2009 8:14 pm
   Subject: Re: [Tutorial] Directional 3D Actor types
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Just checked it out and it works great! Only problem that I found was the "actormisc" code in the spawn actor routine, I had to remove it to get the code to work, but other than that, it's great!

_________________
- Taking a hiatus from Wolfenstein for a while...

...But I'll be back, you can count on it!
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 14 Nov 2018

Topics: 46
Posts: 2315
Location: USA
usa.gif

PostPosted: Thu Oct 01, 2009 8:51 pm
   Subject: Re: [Tutorial] Directional 3D Actor types
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

A quick glance shows that you call SpawnFence, but the method is really called SpawnJaws....

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 6:23 ago.

Topics: 165
Posts: 8252
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Thu Oct 01, 2009 9:02 pm
   Subject: Re: [Tutorial] Directional 3D Actor types
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Metalor - The routine should work properly if you call it up in WL_GAME as I've illustrated above. You'll have little control over how the Actor displays if you leave the "actormisc" variable out. Creating a whole separate Spawn routine will solve that problem, but it's unnecessary with what I supply above. Smile

Adam Biser wrote:
A quick glance shows that you call SpawnFence, but the method is really called SpawnJaws....
Laughing Thanks; I knew I missed something. I appreciate the bug report. It's now corrected. Thumbs Up
Metalor
DieHard Mutant
DieHard Mutant


Joined: 24 Aug 2005
Last Visit: 1:36 ago.

Topics: 95
Posts: 914
Location: California
usa.gif

PostPosted: Thu Oct 01, 2009 9:43 pm
   Subject: Re: [Tutorial] Directional 3D Actor types
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Oh well, what I put in works fine, the actors look and act how they're supposed to so I see no problem other than what I mentioned above, which I improvised for, so no biggie.

And in ragards to Adam's comment, yeah I caught the SpawnJaws too, but didn't know what to make of it. I mean, horror movie sharks are cool, but a 2D one just doesn't have the Oomph that a semi-3d one has. (especially if it doesn't move, which brings up the question: will it be possible for 3D directional guards to move at all? Cause if so, that gives me an excellent idea)

_________________
- Taking a hiatus from Wolfenstein for a while...

...But I'll be back, you can count on it!
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 6:23 ago.

Topics: 165
Posts: 8252
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Fri Oct 02, 2009 5:29 am
   Subject: Re: [Tutorial] Directional 3D Actor types
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Metalor wrote:
Oh well, what I put in works fine, the actors look and act how they're supposed to so I see no problem other than what I mentioned above, which I improvised for, so no biggie.
Well, this still helps me realize that the WL_GAME.CPP part of the tutorial needs to be more clear as to what it does. Smile

Quote:
And in regards to Adam's comment, yeah I caught the SpawnJaws too, but didn't know what to make of it.
I'll be posting a screenshot of "Jaws" when his graphics are done. Smile

Quote:
... (especially if it doesn't move, which brings up the question: will it be possible for 3D directional guards to move at all? Cause if so, that gives me an excellent idea)
Yep, just not in T_Chase. Smile First, have your Actor's statetypes use the "T_Blade" function instead of "T_Chase". Then, you have to "#define" a number in WL_DEF.H (or WL_GAMESETTINGS.H, if you use BunkerSDL) that has the Actor's speed placed in it; say - BLADESPEED. Then, Copy and Paste the T_Chase function to another part of WL_ACT2.CPP, call the new routine T_Blade, and change every occurrence of "ob->speed" in that routine to BLADESPEED. I believe that will get it moving. Make sure the SightPlayer routine in WL_STATE.CPP doesn't change your Actor's "ob->speed" setting, or your Actor will stop having the Directional 3D feature when he's alerted. Smile
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 14 Nov 2018

Topics: 46
Posts: 2315
Location: USA
usa.gif

PostPosted: Fri Oct 02, 2009 6:06 am
   Subject: Re: [Tutorial] Directional 3D Actor types
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

When I saw SpawnJaws, I pictured the image of Jaws from the posters but with an animated mouth chomping away. Very Happy

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page
Metalor
DieHard Mutant
DieHard Mutant


Joined: 24 Aug 2005
Last Visit: 1:36 ago.

Topics: 95
Posts: 914
Location: California
usa.gif

PostPosted: Fri Oct 02, 2009 8:21 am
   Subject: Re: [Tutorial] Directional 3D Actor types
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Tricob wrote:
Yep, just not in T_Chase. Smile First, have your Actor's statetypes use the "T_Blade" function instead of "T_Chase". Then, you have to "#define" a number in WL_DEF.H (or WL_GAMESETTINGS.H, if you use BunkerSDL) that has the Actor's speed placed in it; say - BLADESPEED. Then, Copy and Paste the T_Chase function to another part of WL_ACT2.CPP, call the new routine T_Blade, and change every occurrence of "ob->speed" in that routine to BLADESPEED. I believe that will get it moving. Make sure the SightPlayer routine in WL_STATE.CPP doesn't change your Actor's "ob->speed" setting, or your Actor will stop having the Directional 3D feature when he's alerted. Smile


Funny thing that, my game actually doesn't have T_Chase in it anymore, it now has chase commands such as "MeleeChase" "MutantChaseA~D" "RangeChase" etc. 'Cause now all of the chase routines are for specific actions or for specific weapons. Meaning one guard could have (and one that I know of DOES have) up to four or more chase functions programmed into it.

Unfortunately, none of my chase functions are called: "T_Blade"

Quote:
When I saw SpawnJaws, I pictured the image of Jaws from the posters but with an animated mouth chomping away.


Or perhaps when animated properly, it could be this: (still relying on the Jaws theme of course) http://www.youtube.com/watch?v=FV4LRQWCkNM
So, more or less some odd eyecandy for the viewer.

_________________
- Taking a hiatus from Wolfenstein for a while...

...But I'll be back, you can count on it!
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 6:23 ago.

Topics: 165
Posts: 8252
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Fri Oct 02, 2009 7:19 pm
   Subject: Re: [Tutorial] Directional 3D Actor types
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Re: Jaws. Well, seeing as I've blown his cover by accident, I guess I'll have to set Sonder aside for another day, and finish up Jaws's graphics and post a screenshot of him; DHWs seem to be showing genuine interest in him. Going by the posts I've read here, I doubt anyone has figured out exactly what he really is, and what he's like. But when you do see him, you'll understand why he absolutely *had* to be 3D-Directional. Smile
Metalor
DieHard Mutant
DieHard Mutant


Joined: 24 Aug 2005
Last Visit: 1:36 ago.

Topics: 95
Posts: 914
Location: California
usa.gif

PostPosted: Fri Oct 02, 2009 8:17 pm
   Subject: Re: [Tutorial] Directional 3D Actor types
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

And here I thought it was all playful speculation!

_________________
- Taking a hiatus from Wolfenstein for a while...

...But I'll be back, you can count on it!
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page TopView Next Topic
Page 1 of 1
Jump to:  

Related topics
 Topics   Replies   Views   Last Post 
No new posts Sticky: [Tutorial] Compiling Wolf4SDL with Code::Blocks
Author: dcbasic
90 27517 Wed May 24, 2017 7:53 pm
Falcon*93 View latest post
No new posts [help] Adding teleporters in wolf4sdl
Author: Mortimer
35 11726 Fri May 26, 2017 8:19 am
Military View latest post
No new posts [SDL-Help] Wall patches fix
Author: insurrectionman
0 1252 Tue Jul 15, 2008 11:12 am
insurrectionman View latest post
No new posts [Wolf4SDL Help] Inserting a second palette (like in SoD)
Author: Andy_Nonymous
10 3534 Mon Jun 02, 2008 3:59 pm
Adam Biser View latest post
No new posts [Help] Problem with Checkweaponchange function (wolf4sdl)
Author: Mortimer
4 3375 Sat May 17, 2008 11:26 am
Mortimer View latest post
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
   You cannot delete your posts in this forum
You cannot vote in polls in this forum


Copyright ©2003-2008 DieHard Wolfers
A Modified subBunker Theme by BrotherTank
Powered by phpBB © 2001, 2005 phpBB Group