unknowncheats uc-forum.com ucdownloads ucdownloads.com

Go Back   UC-Tutorials - Multiplayer Game Hacking and Cheat Tutorials > Programming > Direct3D

- Sponsored Advertisement -
http://www.myfpscheats.com/


Reply
 
Thread Tools Display Modes
  #1  
Old 10-30-2009, 03:42 AM
Dave Dave is offline
Junior Member
 
Join Date: Oct 2009
Posts: 11
Default [Code] Pure D3D 3D Boxes.

Author: CallMeEclipse

Requires you have a good understanding of Direct3D programming, as well as C++

also requires that you can draw with quad vertex primitivs, as well as draw lines.

You cannot just copy and paste this, if you were planning to do so, leave now.


Global Shit:
Code:
//reason i used abc.. instead of the numbers
//is because i drew the box out on paper first
//and i labeled the verts with letters.
#define a 1
#define b 2
#define c 3
#define d 4
#define e 5
#define f 6
#define g 7
#define h 8

struct BoxVerts{   
   float x,y;
};
BoxVerts Vert[256];

float hRad = 300;//height radius
float wRad = 300;//width radius
//remember RADIUS NOT DIAMETER
//ex. box would be 600x600x600

DWORD Color1 = D3DCOLOR_ARGB(200,255,0,0);
DWORD Color2 = D3DCOLOR_ARGB(140,0,0,0);

Main Code:
Code:
World2Screen(    X-wRad,    Y-hRad,    Z+wRad,        Vert[a].x,Vert[a].y);
World2Screen(    X+wRad,    Y-hRad,    Z+wRad,        Vert[b].x,Vert[b].y);
World2Screen(    X-wRad,    Y+hRad,    Z+wRad,        Vert[c].x,Vert[c].y);
World2Screen(    X+wRad,    Y+hRad,    Z+wRad,        Vert[d].x,Vert[d].y);
World2Screen(    X-wRad,    Y-hRad,    Z-wRad,        Vert[e].x,Vert[e].y);
World2Screen(    X+wRad,    Y-hRad,    Z-wRad,        Vert[f].x,Vert[f].y);
World2Screen(    X-wRad,    Y+hRad,    Z-wRad,        Vert[g].x,Vert[g].y);
World2Screen(    X+wRad,    Y+hRad,    Z-wRad,        Vert[h].x,Vert[h].y);


//~~~Drawing Boxes~~~//
//______Vert 1 X | Vert 1 Y  |  Vert 2 X | Vert 2 Y  |  Vert 3 X |  Vert 3 Y | Vert 4 X  | Vert 4 Y_____//

Quad2( Device, Color2,  Primtexture,    Vert[a].x,    Vert[a].y,    Vert[b].x,    Vert[b].y,    Vert[c].x,    Vert[c].y,    Vert[d].x,    Vert[d].y);//Front

Quad2( Device, Color2,  Primtexture,    Vert[e].x,    Vert[e].y,    Vert[f].x,    Vert[f].y,    Vert[g].x,    Vert[g].y,    Vert[h].x,    Vert[h].y);//Back

Quad2( Device, Color2,  Primtexture,    Vert[e].x,    Vert[e].y,    Vert[f].x,    Vert[f].y,    Vert[a].x,    Vert[a].y,    Vert[b].x,    Vert[b].y);//Top

Quad2( Device, Color2,  Primtexture,    Vert[g].x,    Vert[g].y,    Vert[h].x,    Vert[h].y,    Vert[c].x,    Vert[c].y,    Vert[d].x,    Vert[d].y);//Bottom

Quad2( Device, Color2,  Primtexture,    Vert[e].x,    Vert[e].y,    Vert[a].x,    Vert[a].y,    Vert[g].x,    Vert[g].y,    Vert[c].x,    Vert[c].y);//Side 1

Quad2( Device, Color2,  Primtexture,    Vert[b].x,    Vert[b].y,    Vert[f].x,    Vert[f].y,    Vert[d].x,    Vert[d].y,    Vert[h].x,    Vert[h].y);//Side 2


//~~~Outline~~~//
//______Vert 1 X | Vert 1 Y  |  Vert 2 X | Vert 2 Y_____//
DrawLine( Color1,     Vert[a].x,    Vert[a].y,    Vert[b].x,    Vert[b].y    );//--|
DrawLine( Color1,     Vert[a].x,    Vert[a].y,    Vert[c].x,    Vert[c].y    );//  |
DrawLine( Color1,     Vert[b].x,    Vert[b].y,    Vert[d].x,    Vert[d].y    );//  |-Front Box
DrawLine( Color1,     Vert[c].x,    Vert[c].y,    Vert[d].x,    Vert[d].y    );//--|

DrawLine( Color1,     Vert[e].x,    Vert[e].y,    Vert[f].x,    Vert[f].y    );//--|
DrawLine( Color1,     Vert[e].x,    Vert[e].y,    Vert[g].x,    Vert[g].y    );//  |
DrawLine( Color1,     Vert[f].x,    Vert[f].y,    Vert[h].x,    Vert[h].y    );//  |-Back Box
DrawLine( Color1,     Vert[g].x,    Vert[g].y,    Vert[h].x,    Vert[h].y    );//--|

DrawLine( Color1,     Vert[b].x,    Vert[b].y,    Vert[f].x,    Vert[f].y    );//--|
DrawLine( Color1,     Vert[a].x,    Vert[a].y,    Vert[e].x,    Vert[e].y    );//  |
DrawLine( Color1,     Vert[d].x,    Vert[d].y,    Vert[h].x,    Vert[h].y    );//  |-Connectors
DrawLine( Color1,     Vert[c].x,    Vert[c].y,    Vert[g].x,    Vert[g].y    );//--|


Supporting Functions:
Code:
void Quad2( LPDIRECT3DDEVICE9 c_pDev, DWORD COLOR, IDirect3DTexture9 *ppD3Dtex,float Point1x,float Point1y,float Point2x,float Point2y,float Point3x,float Point3y,float Point4x,float Point4y)
{
struct sVerts
{
    float x, y, z, rhw;  
    DWORD colour;
};

sVerts cQuad[] =
    {
        {Point4x,                        Point4y,                1,    1,    COLOR},
        {Point1x,                        Point1y,                1,    1,    COLOR},
        {Point2x,                        Point2y,                    1,    1,    COLOR}, 
        {Point4x,                        Point4y,                1,    1,    COLOR},
        {Point3x,                        Point3y,                1,    1,    COLOR},
        {Point1x,                        Point1y,                1,    1,    COLOR}
    };
    pVerts=sizeof(cQuad)/sizeof(sVerts);
    pTri=pVerts/3;
    Device->SetTexture(0,ppD3Dtex);
    Device->DrawPrimitiveUP(D3DPT_TRIANGLELIST,pTri,cQuad,sizeof(sVerts));
}

void DrawLine(DWORD color, float x, float y, float x2, float y2)
{

    D3DXVECTOR2 cLine1[2];
    D3DXVECTOR2 cLine2[2];
    D3DXVECTOR2 cLine3[2];
    D3DXVECTOR2 cLine4[2];
    cLine1[0].x = x; 
    cLine1[0].y = y; 
    cLine1[1].x = x2; 
    cLine1[1].y = y2;
    pLine->SetWidth(1);
    pLine->SetAntialias(false);
    pLine->SetGLLines(false);
    pLine->Begin();
    pLine->Draw(vLine1, 2, color);
    pLine->End();
}
As for the Worldtoscreen, you can use any one that you have, for this particular project i used an engine world2screen..

but i normally use D3D for everything, if you want to find a d3d w2s, search around UC i know there is multiple posts..

Anyways, have Fun!


NOTE: i understand using the engine w2S is not pure d3d, however the boxes themselves are!
Reply With Quote
Reply

  • Submit Thread to Digg
  • Submit Thread to del.icio.us
  • Submit Thread to StumbleUpon
  • Submit Thread to Google
  • Submit Thread to Facebook
  • Submit Thread to My Yahoo!
  • Submit Thread to MySpace
  • Submit Thread to Twitter
  • Submit Thread to Reddit

Tags
boxes, code, d3d, pure

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 06:20 AM.