Aliens Vs Predator source update is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

Commit 377

User picture
  • Author: sirlemonhead
  • 2010-10-22 03:54 (over 3 years ago)

- FOV is now set correctly for each species
- passing full vertex declaration class to R_CreateVertexDeclaration
- test frustum cull code (disabled)

Files Affected

 
376377
56
extern void D3D_FadeDownScreen(int brightness, int colour);
56
extern void D3D_FadeDownScreen(int brightness, int colour);
57
extern void D3D_ScreenInversionOverlay();
57
extern void D3D_ScreenInversionOverlay();
58
 
58
 
 
 
59
extern VIEWDESCRIPTORBLOCK *ActiveVDBList[];
 
 
60
extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
 
 
61
 
 
 
62
const int MARINE_FOV =    77;
 
 
63
const int ALIEN_FOV     =    110;
 
 
64
 
 
 
65
extern void R_SetFov(uint32_t fov);
 
 
66
 
59
void SetupVision(void)
67
void SetupVision(void)
60
{
68
{
61
    /* KJL 16:33:47 01/10/97 - change view for alien;
69
    /* KJL 16:33:47 01/10/97 - change view for alien;
62
    this must be called after ProcessSystemObjects() */
70
    this must be called after ProcessSystemObjects() */
63
    if(AvP.PlayerType == I_Alien)
71
    if (AvP.PlayerType == I_Alien)
64
       {
72
       {
65
        /* setup wide-angle lens */
73
        /* setup wide-angle lens */
66
        extern VIEWDESCRIPTORBLOCK *ActiveVDBList[];
 
 
67
        extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
 
 
68
        VIEWDESCRIPTORBLOCK *VDBPtr = ActiveVDBList[0];
74
        VIEWDESCRIPTORBLOCK *VDBPtr = ActiveVDBList[0];
69
 
75
 
70
        LOCALASSERT(VDBPtr);
76
        LOCALASSERT(VDBPtr);
...
 
...
 
76
 
82
 
77
        /* KJL 17:37:51 7/17/97 - frustum setup */
83
        /* KJL 17:37:51 7/17/97 - frustum setup */
78
        SetFrustumType(FRUSTUM_TYPE_WIDE);
84
        SetFrustumType(FRUSTUM_TYPE_WIDE);
 
 
85
        R_SetFov(ALIEN_FOV);
79
    }
86
    }
80
    else if (AvP.PlayerType == I_Predator)
87
    else if (AvP.PlayerType == I_Predator)
81
    {
88
    {
82
        /* setup normal-angle lens */
89
        /* setup normal-angle lens */
83
        extern VIEWDESCRIPTORBLOCK *ActiveVDBList[];
 
 
84
        extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
 
 
85
        VIEWDESCRIPTORBLOCK *VDBPtr = ActiveVDBList[0];
90
        VIEWDESCRIPTORBLOCK *VDBPtr = ActiveVDBList[0];
86
 
91
 
87
        LOCALASSERT(VDBPtr);
92
        LOCALASSERT(VDBPtr);
...
 
...
 
93
        SetupPredOVision();
98
        SetupPredOVision();
94
        /* KJL 17:37:51 7/17/97 - frustum setup */
99
        /* KJL 17:37:51 7/17/97 - frustum setup */
95
        SetFrustumType(FRUSTUM_TYPE_NORMAL);
100
        SetFrustumType(FRUSTUM_TYPE_NORMAL);
 
 
101
        R_SetFov(MARINE_FOV);
96
    }
102
    }
97
    else
103
    else
98
    {
104
    {
99
        /* setup normal-angle lens */
105
        /* setup normal-angle lens */
100
        extern VIEWDESCRIPTORBLOCK *ActiveVDBList[];
 
 
101
        extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
 
 
102
        VIEWDESCRIPTORBLOCK *VDBPtr = ActiveVDBList[0];
106
        VIEWDESCRIPTORBLOCK *VDBPtr = ActiveVDBList[0];
103
 
107
 
104
        LOCALASSERT(VDBPtr);
108
        LOCALASSERT(VDBPtr);
...
 
...
 
110
        SetupMarineOVision();
114
        SetupMarineOVision();
111
        /* KJL 17:37:51 7/17/97 - frustum setup */
115
        /* KJL 17:37:51 7/17/97 - frustum setup */
112
        SetFrustumType(FRUSTUM_TYPE_NORMAL);
116
        SetFrustumType(FRUSTUM_TYPE_NORMAL);
 
 
117
        R_SetFov(MARINE_FOV);
113
    }
118
    }
114
 
119
 
115
    InitCameraValues();
120
    InitCameraValues();
...
 
...
 
138
{
143
{
139
    /* setup in-game data */
144
    /* setup in-game data */
140
    PredOVision.VisionMode = PREDOVISION_NORMAL;
145
    PredOVision.VisionMode = PREDOVISION_NORMAL;
141
    PredOVision.VisionIsChanging=0;
146
    PredOVision.VisionIsChanging = 0;
142
    /* JH - 29/5/97 for d3d */
147
    /* JH - 29/5/97 for d3d */
143
    d3d_light_ctrl.ctrl = LCCM_NORMAL;
148
    d3d_light_ctrl.ctrl = LCCM_NORMAL;
144
}
149
}
...
 
...
 
146
 
151
 
147
void HandlePredOVision(void)
152
void HandlePredOVision(void)
148
{
153
{
149
    PLAYER_STATUS *playerStatusPtr= (PLAYER_STATUS *) (Player->ObStrategyBlock->SBdataptr);
154
    PLAYER_STATUS *playerStatusPtr = (PLAYER_STATUS *) (Player->ObStrategyBlock->SBdataptr);
150
 
155
 
151
    if (playerStatusPtr->IsAlive)
156
    if (playerStatusPtr->IsAlive)
152
    {
157
    {
376377
3997
float Source[3];
3997
float Source[3];
3998
float Dest[3];
3998
float Dest[3];
3999
 
3999
 
 
 
4000
float p = 1.0f;
 
 
4001
float o = 1.0f;
 
 
4002
 
4000
extern void TranslationSetup(void)
4003
extern void TranslationSetup(void)
4001
{
4004
{
4002
    char buf[100];
4005
    char buf[100];
4003
    VECTORCH v = Global_VDB_Ptr->VDB_World;
4006
    VECTORCH v = Global_VDB_Ptr->VDB_World;
4004
    extern int PredatorVisionChangeCounter;
4007
    extern int PredatorVisionChangeCounter;
4005
    float p = PredatorVisionChangeCounter / 65536.0f;
4008
    /*float*/ p = PredatorVisionChangeCounter / 65536.0f;
4006
    float o = 1.0f;
4009
    /*float*/ o = 1.0f;
4007
    p = 1.0f+p;
4010
    p = 1.0f+p;
4008
 
4011
 
4009
    if (NAUSEA_CHEATMODE)
4012
    if (NAUSEA_CHEATMODE)
...
 
...
 
4016
    }
4019
    }
4017
 
4020
 
4018
    // right vector
4021
    // right vector
4019
    ViewMatrix[0] = (float)(Global_VDB_Ptr->VDB_Mat.mat11)/65536.0f*o;
4022
    ViewMatrix[0] = (float)(Global_VDB_Ptr->VDB_Mat.mat11)/65536.0f;//*o;
4020
    ViewMatrix[1] = (float)(Global_VDB_Ptr->VDB_Mat.mat21)/65536.0f*o;
4023
    ViewMatrix[1] = (float)(Global_VDB_Ptr->VDB_Mat.mat21)/65536.0f;//*o;
4021
    ViewMatrix[2] = (float)(Global_VDB_Ptr->VDB_Mat.mat31)/65536.0f*o;
4024
    ViewMatrix[2] = (float)(Global_VDB_Ptr->VDB_Mat.mat31)/65536.0f;//*o;
4022
 
4025
 
4023
    // up vector
4026
    // up vector
4024
    ViewMatrix[4] = (float)(Global_VDB_Ptr->VDB_Mat.mat12)/65536.0f*p;
4027
    ViewMatrix[4] = (float)(Global_VDB_Ptr->VDB_Mat.mat12)/65536.0f;//*p;
4025
    ViewMatrix[5] = (float)(Global_VDB_Ptr->VDB_Mat.mat22)/65536.0f*p;
4028
    ViewMatrix[5] = (float)(Global_VDB_Ptr->VDB_Mat.mat22)/65536.0f;//*p;
4026
    ViewMatrix[6] = (float)(Global_VDB_Ptr->VDB_Mat.mat32)/65536.0f*p;
4029
    ViewMatrix[6] = (float)(Global_VDB_Ptr->VDB_Mat.mat32)/65536.0f;//*p;
4027
 
4030
 
4028
    // lookat vector
4031
    // lookat vector
4029
    ViewMatrix[8] = (float)(Global_VDB_Ptr->VDB_Mat.mat13)/65536.0f;
4032
    ViewMatrix[8] = (float)(Global_VDB_Ptr->VDB_Mat.mat13)/65536.0f;
...
 
...
 
4040
    ViewMatrix[7] = ((float)-v.vy)*p;
4043
    ViewMatrix[7] = ((float)-v.vy)*p;
4041
    ViewMatrix[11] = ((float)-v.vz)*CameraZoomScale;
4044
    ViewMatrix[11] = ((float)-v.vz)*CameraZoomScale;
4042
    #else
4045
    #else
4043
    ViewMatrix[3] = ((float)v.vx)*o;
4046
    ViewMatrix[3] = ((float)v.vx);//*o;
4044
    ViewMatrix[7] = ((float)v.vy)*p;
4047
    ViewMatrix[7] = ((float)v.vy);//*p;
4045
    ViewMatrix[11] = ((float)v.vz);;
4048
    ViewMatrix[11] = ((float)v.vz);
4046
    #endif
4049
    #endif
4047
/*
4050
/*
4048
    sprintf(buf,
4051
    sprintf(buf,
...
 
...
 
6178
        particle.ParticleID = PARTICLE_STAR;
6181
        particle.ParticleID = PARTICLE_STAR;
6179
        particle.Colour = StarArray[i].Colour;
6182
        particle.Colour = StarArray[i].Colour;
6180
 
6183
 
6181
        position.vx += Global_VDB_Ptr->VDB_World.vx;
6184
//        position.vx += Global_VDB_Ptr->VDB_World.vx;
6182
        position.vy += Global_VDB_Ptr->VDB_World.vy;
6185
//        position.vy += Global_VDB_Ptr->VDB_World.vy;
6183
        position.vz += Global_VDB_Ptr->VDB_World.vz;
6186
//        position.vz += Global_VDB_Ptr->VDB_World.vz;
6184
 
6187
 
6185
        TranslatePointIntoViewspace(&position);
6188
        TranslatePointIntoViewspace(&position);
6186
 
6189
 
376377
180
    return true;
180
    return true;
181
}
181
}
182
 
182
 
183
effectID_t EffectManager::AddEffect(const std::string &effectName, const std::string &vertexShaderName, const std::string &pixelShaderName, const VertexDeclaration *vertexDeclaration)
183
effectID_t EffectManager::AddEffect(const std::string &effectName, const std::string &vertexShaderName, const std::string &pixelShaderName,
VertexDeclaration *vertexDeclaration)
184
{
184
{
185
    shaderID_t vertexID = nullID;
185
    shaderID_t vertexID = nullID;
186
    shaderID_t pixelID = nullID;
186
    shaderID_t pixelID = nullID;
...
 
...
 
214
        r_VertexShader newVertexShader;
214
        r_VertexShader newVertexShader;
215
        newVertexShader.isValid = false;
215
        newVertexShader.isValid = false;
216
 
216
 
217
        if (R_CreateVertexShader(vertexShaderName, newVertexShader))
217
        if (R_CreateVertexShader(vertexShaderName, newVertexShader, vertexDeclaration))
218
        {
218
        {
219
            // ok, store it
219
            // ok, store it
220
            newVertexShader.isValid = true;
220
            newVertexShader.isValid = true;
376377
97
        bool SetActive(effectID_t effectID);
97
        bool SetActive(effectID_t effectID);
98
        bool SetMatrix(effectID_t effectID, const char* constant, R_MATRIX &matrix);
98
        bool SetMatrix(effectID_t effectID, const char* constant, R_MATRIX &matrix);
99
        bool SetInt(effectID_t effectID, const char* constant, int32_t n);
99
        bool SetInt(effectID_t effectID, const char* constant, int32_t n);
100
        effectID_t AddEffect(const std::string &effectName, const std::string &vertexShaderName, const std::string &pixelShaderName, const class VertexDeclaration *vertexDeclaration);
100
        effectID_t AddEffect(const std::string &effectName, const std::string &vertexShaderName, const std::string &pixelShaderName, class
VertexDeclaration *vertexDeclaration);
101
};
101
};
102
 
102
 
103
#endif
103
#endif
376377
44
        return false;
44
        return false;
45
    }
45
    }
46
 
46
 
47
    if (R_CreateVertexDeclaration(this->declaration, this->elements))
47
    if (R_CreateVertexDeclaration(this))
48
    {
48
    {
49
        // we don't need this anymore?
49
        // we don't need this anymore?
50
        this->elements.clear();
50
        this->elements.clear();
376377
90
class VertexDeclaration
90
class VertexDeclaration
91
{
91
{
92
    private:
92
    private:
93
        r_vertexDeclaration    declaration;
 
 
94
        std::vector<vertexElement> elements;
 
 
95
        uint32_t offset;
93
        uint32_t offset;
96
 
94
 
97
    public:
95
    public:
98
        VertexDeclaration();
96
        VertexDeclaration();
99
        ~VertexDeclaration();
97
        ~VertexDeclaration();
 
 
98
 
 
 
99
        // members
 
 
100
        std::vector<vertexElement> elements;
 
 
101
        r_vertexDeclaration    declaration;
 
 
102
 
 
 
103
#ifdef _XBOX
 
 
104
        std::vector<DWORD> d3dElement;
 
 
105
#endif
 
 
106
 
 
 
107
        // functions
100
        void Add(uint16_t stream, VD_TYPE type, VD_METHOD method, VD_USAGE usage, uint8_t usageIndex);
108
        void Add(uint16_t stream, VD_TYPE type, VD_METHOD method, VD_USAGE usage, uint8_t usageIndex);
101
        bool Create();
109
        bool Create();
102
        bool Set();
110
        bool Set();
376377
32
#include "font2.h"
32
#include "font2.h"
33
#include <XInput.h> // XInput API
33
#include <XInput.h> // XInput API
34
 
34
 
 
 
35
// Alien FOV - 115
 
 
36
// Marine & Predator FOV - 77
 
 
37
 
35
extern "C"
38
extern "C"
36
{
39
{
37
    #include "AvP_UserProfile.h"
40
    #include "AvP_UserProfile.h"
...
 
...
 
48
D3DXMATRIX matIdentity;
51
D3DXMATRIX matIdentity;
49
D3DXMATRIX matViewPort;
52
D3DXMATRIX matViewPort;
50
 
53
 
 
 
54
static D3DXPLANE m_frustum[6];
 
 
55
 
 
 
56
extern "C"
 
 
57
{
 
 
58
    BOOL CheckPointIsInFrustum(D3DXVECTOR3 *point)
 
 
59
    {
 
 
60
        // check if point is in front of each plane
 
 
61
        for (int i = 0; i < 6; i++)
 
 
62
        {
 
 
63
            if (D3DXPlaneDotCoord(&m_frustum[i], point) < 0.0f)
 
 
64
            {
 
 
65
                // its outside
 
 
66
                return FALSE;
 
 
67
            }
 
 
68
        }
 
 
69
 
 
 
70
        // return here if the point is entirely within
 
 
71
        return TRUE;
 
 
72
    }
 
 
73
}
 
 
74
 
 
 
75
// call per frame after we've updated view and projection matrixes
 
 
76
void BuildFrustum()
 
 
77
{
 
 
78
    D3DXMATRIX viewProjection;
 
 
79
    D3DXMatrixMultiply(&viewProjection, &matView, &matProjection);
 
 
80
 
 
 
81
    // Left plane
 
 
82
    m_frustum[0].a = viewProjection._14 + viewProjection._11;
 
 
83
    m_frustum[0].b = viewProjection._24 + viewProjection._21;
 
 
84
    m_frustum[0].c = viewProjection._34 + viewProjection._31;
 
 
85
    m_frustum[0].d = viewProjection._44 + viewProjection._41;
 
 
86
 
 
 
87
    // Right plane
 
 
88
    m_frustum[1].a = viewProjection._14 - viewProjection._11;
 
 
89
    m_frustum[1].b = viewProjection._24 - viewProjection._21;
 
 
90
    m_frustum[1].c = viewProjection._34 - viewProjection._31;
 
 
91
    m_frustum[1].d = viewProjection._44 - viewProjection._41;
 
 
92
 
 
 
93
    // Top plane
 
 
94
    m_frustum[2].a = viewProjection._14 - viewProjection._12;
 
 
95
    m_frustum[2].b = viewProjection._24 - viewProjection._22;
 
 
96
    m_frustum[2].c = viewProjection._34 - viewProjection._32;
 
 
97
    m_frustum[2].d = viewProjection._44 - viewProjection._42;
 
 
98
 
 
 
99
    // Bottom plane
 
 
100
    m_frustum[3].a = viewProjection._14 + viewProjection._12;
 
 
101
    m_frustum[3].b = viewProjection._24 + viewProjection._22;
 
 
102
    m_frustum[3].c = viewProjection._34 + viewProjection._32;
 
 
103
    m_frustum[3].d = viewProjection._44 + viewProjection._42;
 
 
104
 
 
 
105
    // Near plane
 
 
106
    m_frustum[4].a = viewProjection._13;
 
 
107
    m_frustum[4].b = viewProjection._23;
 
 
108
    m_frustum[4].c = viewProjection._33;
 
 
109
    m_frustum[4].d = viewProjection._43;
 
 
110
 
 
 
111
    // Far plane
 
 
112
    m_frustum[5].a = viewProjection._14 - viewProjection._13;
 
 
113
    m_frustum[5].b = viewProjection._24 - viewProjection._23;
 
 
114
    m_frustum[5].c = viewProjection._34 - viewProjection._33;
 
 
115
    m_frustum[5].d = viewProjection._44 - viewProjection._43;
 
 
116
 
 
 
117
    // Normalize planes
 
 
118
    for (int i = 0; i < 6; i++)
 
 
119
    {
 
 
120
        D3DXPlaneNormalize(&m_frustum[i], &m_frustum[i]);
 
 
121
    }
 
 
122
}
 
 
123
 
51
/*
124
/*
52
// vertex declarations
125
// vertex declarations
53
D3DVERTEXELEMENT9 declMain[] =
126
D3DVERTEXELEMENT9 declMain[] =
...
 
...
 
559
 
632
 
560
    // test vertex buffer
633
    // test vertex buffer
561
    d3d.particleVB = new VertexBuffer;
634
    d3d.particleVB = new VertexBuffer;
562
    d3d.particleVB->Create(MAX_VERTEXES, FVF_LVERTEX, USAGE_DYNAMIC);
635
    d3d.particleVB->Create(MAX_VERTEXES*6, FVF_LVERTEX, USAGE_DYNAMIC);
563
 
636
 
564
    d3d.particleIB = new IndexBuffer;
637
    d3d.particleIB = new IndexBuffer;
565
    d3d.particleIB->Create(MAX_INDICES, USAGE_DYNAMIC);
638
    d3d.particleIB->Create(MAX_INDICES*6, USAGE_DYNAMIC);
566
 
639
 
567
    // test main
640
    // test main
568
    d3d.mainVB = new VertexBuffer;
641
    d3d.mainVB = new VertexBuffer;
...
 
...
 
689
        }
762
        }
690
    }
763
    }
691
 
764
 
 
 
765
    void R_SetFov(uint32_t fov)
 
 
766
    {
 
 
767
        d3d.fieldOfView = fov;
 
 
768
    }
 
 
769
 
692
    void FlushD3DZBuffer()
770
    void FlushD3DZBuffer()
693
    {
771
    {
694
        d3d.lpD3DDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
772
        d3d.lpD3DDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
...
 
...
 
999
}
1077
}
1000
*/
1078
*/
1001
 
1079
 
 
 
1080
/*
1002
static bool CreateVertexShader(const std::string &fileName, r_VertexShader &vertexShader)
1081
static bool CreateVertexShader(const std::string &fileName, r_VertexShader &vertexShader)
1003
{
1082
{
1004
    LPD3DXBUFFER pErrors = NULL;
1083
    LPD3DXBUFFER pErrors = NULL;
...
 
...
 
1046
 
1125
 
1047
    return true;
1126
    return true;
1048
}
1127
}
 
 
1128
*/
1049
 
1129
 
1050
static bool CreatePixelShader(const std::string &fileName, r_PixelShader &pixelShader)
1130
static bool CreatePixelShader(const std::string &fileName, r_PixelShader &pixelShader)
1051
{
1131
{
...
 
...
 
1180
    return d3dType;
1260
    return d3dType;
1181
}
1261
}
1182
 
1262
 
1183
bool R_CreateVertexDeclaration(r_vertexDeclaration &declaration, std::vector<vertexElement> &elements)
1263
bool R_CreateVertexDeclaration(class VertexDeclaration *vertexDeclaration)
1184
{
1264
{
 
 
1265
    // take a local copy of this to aid in keeping the code below a bit tidier..
 
 
1266
    size_t elementsSize = vertexDeclaration->elements.size();
 
 
1267
 
1185
    std::vector<D3DVERTEXELEMENT9> d3dElement;
1268
    std::vector<D3DVERTEXELEMENT9> d3dElement;
1186
    d3dElement.resize(elements.size() + 1); // +1 for DECL_END()
1269
    d3dElement.resize(elementsSize+1); // +1 for DECL_END()
1187
 
1270
 
1188
    for (uint32_t i = 0; i < elements.size(); i++)
1271
    for (uint32_t i = 0; i < elementsSize; i++)
1189
    {
1272
    {
1190
        d3dElement[i].Stream = elements[i].stream;
1273
        d3dElement[i].Stream = vertexDeclaration->elements[i].stream;
1191
        d3dElement[i].Offset = elements[i].offset;
1274
        d3dElement[i].Offset = vertexDeclaration->elements[i].offset;
1192
        d3dElement[i].Type = VD_TYPEtoD3DDECLTYPE(elements[i].type);
1275
        d3dElement[i].Type   = VD_TYPEtoD3DDECLTYPE(vertexDeclaration->elements[i].type);
1193
        d3dElement[i].Method = D3DDECLMETHOD_DEFAULT; // TODO
1276
        d3dElement[i].Method = D3DDECLMETHOD_DEFAULT; // TODO
1194
        d3dElement[i].Usage = VD_USAGEtoD3DDECLUSAGE(elements[i].usage);
1277
        d3dElement[i].Usage  = VD_USAGEtoD3DDECLUSAGE(vertexDeclaration->elements[i].usage);
1195
        d3dElement[i].UsageIndex = elements[i].usageIndex;
1278
        d3dElement[i].UsageIndex = vertexDeclaration->elements[i].usageIndex;
1196
    }
1279
    }
1197
 
1280
 
1198
    // add D3DDECL_END() which is {0xFF,0,D3DDECLTYPE_UNUSED,0,0,0}
1281
    // add D3DDECL_END() which is {0xFF,0,D3DDECLTYPE_UNUSED,0,0,0}
1199
    d3dElement[elements.size()].Stream = 0xFF;
1282
    d3dElement[elementsSize].Stream = 0xFF;
1200
    d3dElement[elements.size()].Offset = 0;
1283
    d3dElement[elementsSize].Offset = 0;
1201
    d3dElement[elements.size()].Type = D3DDECLTYPE_UNUSED;
1284
    d3dElement[elementsSize].Type = D3DDECLTYPE_UNUSED;
1202
    d3dElement[elements.size()].Method = 0;
1285
    d3dElement[elementsSize].Method = 0;
1203
    d3dElement[elements.size()].Usage = 0;
1286
    d3dElement[elementsSize].Usage = 0;
1204
    d3dElement[elements.size()].UsageIndex = 0;
1287
    d3dElement[elementsSize].UsageIndex = 0;
1205
 
1288
 
1206
    // try and create it now
1289
    // try and create it now
1207
    LastError = d3d.lpD3DDevice->CreateVertexDeclaration(&d3dElement[0], &declaration);
1290
    LastError = d3d.lpD3DDevice->CreateVertexDeclaration(&d3dElement[0], &vertexDeclaration->declaration);
1208
    if (FAILED(LastError))
1291
    if (FAILED(LastError))
1209
    {
1292
    {
1210
        Con_PrintError("Could not create vertex declaration");
1293
        Con_PrintError("Could not create vertex declaration");
...
 
...
 
1239
    return true;
1322
    return true;
1240
}
1323
}
1241
 
1324
 
1242
bool R_CreateVertexShader(const std::string &fileName, r_VertexShader &vertexShader)
1325
bool R_CreateVertexShader(const std::string &fileName, r_VertexShader &vertexShader, VertexDeclaration *vertexDeclaration)
1243
{
1326
{
1244
    return CreateVertexShader(fileName, vertexShader);
1327
    LPD3DXBUFFER pErrors = NULL;
 
 
1328
    LPD3DXBUFFER pCode = NULL;
 
 
1329
    std::string actualPath = shaderPath + fileName;
 
 
1330
 
 
 
1331
    // test that the path to the file is valid first (d3dx doesn't give a specific error message for this)
 
 
1332
    std::ifstream fileOpenTest(actualPath.c_str(), std::ifstream::in | std::ifstream::binary);
 
 
1333
    if (!fileOpenTest.good())
 
 
1334
    {
 
 
1335
        LogErrorString("Can't open vertex shader file " + actualPath, __LINE__, __FILE__);
 
 
1336
        return false;
 
 
1337
    }
 
 
1338
    // close the file
 
 
1339
    fileOpenTest.close();
 
 
1340
 
 
 
1341
    // set up vertex shader
 
 
1342
    LastError = D3DXCompileShaderFromFile(actualPath.c_str(), //filepath
 
 
1343
                        NULL,            // macro's
 
 
1344
                        NULL,            // includes
 
 
1345
                        "vs_main",       // main function
 
 
1346
                        "vs_2_0",        // shader profile
 
 
1347
                        0,               // flags
 
 
1348
                        &pCode,          // compiled operations
 
 
1349
                        &pErrors,        // errors
 
 
1350
                        &vertexShader.constantTable); // constants
 
 
1351
 
 
 
1352
    if (FAILED(LastError))
 
 
1353
    {
 
 
1354
        OutputDebugString(DXGetErrorString(LastError));
 
 
1355
        OutputDebugString(DXGetErrorDescription(LastError));
 
 
1356
 
 
 
1357
        if (pErrors)
 
 
1358
        {
 
 
1359
            // shader didn't compile for some reason
 
 
1360
            OutputDebugString((const char*)pErrors->GetBufferPointer());
 
 
1361
            pErrors->Release();
 
 
1362
        }
 
 
1363
 
 
 
1364
        return false;
 
 
1365
    }
 
 
1366
 
 
 
1367
    d3d.lpD3DDevice->CreateVertexShader((DWORD*)pCode->GetBufferPointer(), &vertexShader.shader);
 
 
1368
    pCode->Release();
 
 
1369
 
 
 
1370
    return true;
 
 
1371
//    return CreateVertexShader(fileName, vertexShader);
1245
}
1372
}
1246
 
1373
 
1247
bool R_CreatePixelShader(const std::string &fileName, r_PixelShader &pixelShader)
1374
bool R_CreatePixelShader(const std::string &fileName, r_PixelShader &pixelShader)
...
 
...
 
2414
    return true;
2541
    return true;
2415
}
2542
}
2416
 
2543
 
2417
void R_UpdateViewMatrix(float *viewMat)
 
 
2418
{
 
 
2419
    D3DXVECTOR3 vecRight    (viewMat[0], viewMat[1], viewMat[2]);
 
 
2420
    D3DXVECTOR3 vecUp        (viewMat[4], viewMat[5], viewMat[6]);
 
 
2421
    D3DXVECTOR3 vecFront    (viewMat[8], -viewMat[9], viewMat[10]);
 
 
2422
    D3DXVECTOR3 vecPosition (viewMat[3], -viewMat[7], viewMat[11]);
 
 
2423
 
 
 
2424
    D3DXVec3Normalize(&vecFront, &vecFront);
 
 
2425
 
 
 
2426
    D3DXVec3Cross(&vecUp, &vecFront, &vecRight);
 
 
2427
    D3DXVec3Normalize(&vecUp, &vecUp);
 
 
2428
 
 
 
2429
    D3DXVec3Cross(&vecRight, &vecUp, &vecFront);
 
 
2430
    D3DXVec3Normalize(&vecRight, &vecRight);
 
 
2431
 
 
 
2432
    // right
 
 
2433
    matView._11 = vecRight.x;
 
 
2434
    matView._21 = vecRight.y;
 
 
2435
    matView._31 = vecRight.z;
 
 
2436
 
 
 
2437
    // up
 
 
2438
    matView._12 = vecUp.x;
 
 
2439
    matView._22 = vecUp.y;
 
 
2440
    matView._32 = vecUp.z;
 
 
2441
 
 
 
2442
    // front
 
 
2443
    matView._13 = vecFront.x;
 
 
2444
    matView._23 = vecFront.y;
 
 
2445
    matView._33 = vecFront.z;
 
 
2446
 
 
 
2447
    // 4th
 
 
2448
    matView._14 = 0.0f;
 
 
2449
    matView._24 = 0.0f;
 
 
2450
    matView._34 = 0.0f;
 
 
2451
    matView._44 = 1.0f;
 
 
2452
 
 
 
2453
    matView._41 = -D3DXVec3Dot(&vecPosition, &vecRight);
 
 
2454
    matView._42 = -D3DXVec3Dot(&vecPosition, &vecUp);
 
 
2455
    matView._43 = -D3DXVec3Dot(&vecPosition, &vecFront);
 
 
2456
}
 
 
2457
 
 
 
2458
// we need this for zooming
2544
// we need this for zooming
2459
void R_CameraZoom(float zoomScale)
2545
void R_CameraZoom(float zoomScale)
2460
{
2546
{
376377
87
r_Texture CreateD3DTallFontTexture(AVPTEXTURE *tex);
87
r_Texture CreateD3DTallFontTexture(AVPTEXTURE *tex);
88
 
88
 
89
// vertex declaration
89
// vertex declaration
90
bool R_CreateVertexDeclaration(r_vertexDeclaration &declaration, std::vector<struct vertexElement> &elements);
90
bool R_CreateVertexDeclaration(class VertexDeclaration *vertexDeclaration);
91
bool R_SetVertexDeclaration(r_vertexDeclaration &declaration);
91
bool R_SetVertexDeclaration(r_vertexDeclaration &declaration);
92
bool R_ReleaseVertexDeclaration(r_vertexDeclaration &declaration);
92
bool R_ReleaseVertexDeclaration(r_vertexDeclaration &declaration);
93
 
93
 
94
// shader functions
94
// shader functions
95
bool R_CreateVertexShader(const std::string &fileName, r_VertexShader &vertexShader);
95
bool R_CreateVertexShader(const std::string &fileName, r_VertexShader &vertexShader, VertexDeclaration *vertexDeclaration);
96
bool R_CreatePixelShader(const std::string &fileName, r_PixelShader &pixelShader);
96
bool R_CreatePixelShader(const std::string &fileName, r_PixelShader &pixelShader);
97
bool R_SetVertexShader(r_VertexShader &vertexShader);
97
bool R_SetVertexShader(r_VertexShader &vertexShader);
98
bool R_SetPixelShader(r_PixelShader &pixelShader);
98
bool R_SetPixelShader(r_PixelShader &pixelShader);
376377
41
    #include "kshape.h"
41
    #include "kshape.h"
42
    int LightIntensityAtPoint(VECTORCH *pointPtr);
42
    int LightIntensityAtPoint(VECTORCH *pointPtr);
43
    extern float CameraZoomScale;
43
    extern float CameraZoomScale;
 
 
44
    extern float p, o;
44
}
45
}
45
 
46
 
46
static float currentCameraZoomScale = 1.0f;
47
static float currentCameraZoomScale = 1.0f;
...
 
...
 
248
    mainList->Sort();
249
    mainList->Sort();
249
 
250
 
250
    // check if we're zooming in (Predator zoom)
251
    // check if we're zooming in (Predator zoom)
251
    if (currentCameraZoomScale != CameraZoomScale)
252
//    if (currentCameraZoomScale != CameraZoomScale)
252
    {
253
    {
253
        R_CameraZoom(CameraZoomScale);
254
//        R_CameraZoom(CameraZoomScale);
254
        currentCameraZoomScale = CameraZoomScale;
255
//        currentCameraZoomScale = CameraZoomScale;
 
 
256
        D3DXMatrixPerspectiveFovLH(&matProjection, D3DXToRadian(d3d.fieldOfView * CameraZoomScale), (((float)ScreenDescriptorBlock.SDB_Width) *1) / (((float)ScreenDescriptorBlock.SDB_Height) *p), 64.0f, 1000000.0f);
255
    }
257
    }
256
 
258
 
257
    {
259
    {
...
 
...
 
312
 
314
 
313
void DrawFmvFrame(uint32_t frameWidth, uint32_t frameHeight, uint32_t textureWidth, uint32_t textureHeight, r_Texture fmvTexture)
315
void DrawFmvFrame(uint32_t frameWidth, uint32_t frameHeight, uint32_t textureWidth, uint32_t textureHeight, r_Texture fmvTexture)
314
{
316
{
 
 
317
/*
315
    uint32_t topX = (640 - frameWidth) / 2;
318
    uint32_t topX = (640 - frameWidth) / 2;
316
    uint32_t topY = (480 - frameHeight) / 2;
319
    uint32_t topY = (480 - frameHeight) / 2;
317
 
320
 
...
 
...
 
369
    {
372
    {
370
        OutputDebugString("DrawPrimitiveUP failed\n");
373
        OutputDebugString("DrawPrimitiveUP failed\n");
371
    }
374
    }
 
 
375
*/
372
}
376
}
373
 
377
 
374
void DrawFmvFrame2(uint32_t frameWidth, uint32_t frameHeight, uint32_t *textures, uint32_t numTextures)
378
void DrawFmvFrame2(uint32_t frameWidth, uint32_t frameHeight, uint32_t *textures, uint32_t numTextures)
...
 
...
 
1046
    orthoList->CreateOrthoIndices(orthoIndex);
1050
    orthoList->CreateOrthoIndices(orthoIndex);
1047
}
1051
}
1048
 
1052
 
 
 
1053
extern void BuildFrustum();
 
 
1054
 
1049
extern "C" {
1055
extern "C" {
1050
 
1056
 
1051
#include "3dc.h"
1057
#include "3dc.h"
...
 
...
 
1115
    viewMatrix._41 = -D3DXVec3Dot(&vecPosition, &vecRight);
1121
    viewMatrix._41 = -D3DXVec3Dot(&vecPosition, &vecRight);
1116
    viewMatrix._42 = -D3DXVec3Dot(&vecPosition, &vecUp);
1122
    viewMatrix._42 = -D3DXVec3Dot(&vecPosition, &vecUp);
1117
    viewMatrix._43 = -D3DXVec3Dot(&vecPosition, &vecFront);
1123
    viewMatrix._43 = -D3DXVec3Dot(&vecPosition, &vecFront);
 
 
1124
 
 
 
1125
    // move this later (we may not catch projection matrix changes otherwise)
 
 
1126
//    BuildFrustum();
1118
}
1127
}
1119
 
1128
 
1120
void DrawCoronas()
1129
void DrawCoronas()
...
 
...
 
1349
}
1358
}
1350
#endif
1359
#endif
1351
 
1360
 
 
 
1361
extern BOOL CheckPointIsInFrustum(D3DXVECTOR3 *point);
 
 
1362
 
1352
void D3D_ZBufferedGouraudTexturedPolygon_Output(POLYHEADER *inputPolyPtr, RENDERVERTEX *renderVerticesPtr)
1363
void D3D_ZBufferedGouraudTexturedPolygon_Output(POLYHEADER *inputPolyPtr, RENDERVERTEX *renderVerticesPtr)
1353
{
1364
{
1354
    // bjd - This is the function responsible for drawing level geometry and the players weapon
1365
    // bjd - This is the function responsible for drawing level geometry and the players weapon
1355
 
1366
 
 
 
1367
    bool valid = false;
 
 
1368
/*
 
 
1369
    // test frustum culling for each point
 
 
1370
    for (uint32_t i = 0; i < RenderPolygon.NumberOfVertices; i++)
 
 
1371
    {
 
 
1372
        RENDERVERTEX *vertices = &renderVerticesPtr[i];
 
 
1373
 
 
 
1374
        VECTORCHF test;
 
 
1375
        test.vx = vertices->X;
 
 
1376
        test.vy = vertices->Y;
 
 
1377
        test.vz = vertices->Z;
 
 
1378
 
 
 
1379
        TransformToViewspace(&test);
 
 
1380
 
 
 
1381
        D3DXVECTOR3 temp;
 
 
1382
//        temp.x = (float)vertices->X;
 
 
1383
//        temp.y = (float)-vertices->Y;
 
 
1384
//        temp.z = (float)vertices->Z;
 
 
1385
 
 
 
1386
        temp.x = (float)test.vx;
 
 
1387
        temp.y = (float)-test.vy;
 
 
1388
        temp.z = (float)test.vz;
 
 
1389
 
 
 
1390
        if (CheckPointIsInFrustum(&temp) == TRUE)
 
 
1391
        {
 
 
1392
            // true
 
 
1393
            valid = true;
 
 
1394
            break;
 
 
1395
        }
 
 
1396
    }
 
 
1397
 
 
 
1398
    // lets bail out of this function and not draw this poly if none of the points are inside the view frustum
 
 
1399
    if (valid == false)
 
 
1400
        return;
 
 
1401
*/
1356
    // We assume bit 15 (TxLocal) HAS been
1402
    // We assume bit 15 (TxLocal) HAS been
1357
    // properly cleared this time...
1403
    // properly cleared this time...
1358
    uint32_t textureID = (inputPolyPtr->PolyColour & ClrTxDefn);
1404
    uint32_t textureID = (inputPolyPtr->PolyColour & ClrTxDefn);
...
 
...
 
1660
 
1706
 
1661
void D3D_DecalSystem_Setup(void)
1707
void D3D_DecalSystem_Setup(void)
1662
{
1708
{
1663
/*
 
 
1664
    UnlockExecuteBufferAndPrepareForUse();
1709
    UnlockExecuteBufferAndPrepareForUse();
1665
    ExecuteBuffer();
1710
    ExecuteBuffer();
1666
    LockExecuteBuffer();
1711
    LockExecuteBuffer();
1667
 
1712
 
1668
    ChangeZWriteEnable(ZWRITE_DISABLED);
1713
    ChangeZWriteEnable(ZWRITE_DISABLED);
1669
*/
 
 
1670
}
1714
}
1671
 
1715
 
1672
void D3D_DecalSystem_End(void)
1716
void D3D_DecalSystem_End(void)
1673
{
1717
{
1674
 
 
 
1675
    DrawParticles();
1718
    DrawParticles();
1676
    DrawCoronas();
1719
    DrawCoronas();
1677
/*
1720
 
1678
    UnlockExecuteBufferAndPrepareForUse();
1721
    UnlockExecuteBufferAndPrepareForUse();
1679
    ExecuteBuffer();
1722
    ExecuteBuffer();
1680
    LockExecuteBuffer();
1723
    LockExecuteBuffer();
1681
 
1724
 
1682
    ChangeZWriteEnable(ZWRITE_ENABLED);
1725
    ChangeZWriteEnable(ZWRITE_ENABLED);
1683
*/
 
 
1684
}
1726
}
1685
 
1727
 
1686
void D3D_Decal_Output(DECAL *decalPtr, RENDERVERTEX *renderVerticesPtr)
1728
void D3D_Decal_Output(DECAL *decalPtr, RENDERVERTEX *renderVerticesPtr)