Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

06.06.2007, 22:25

Problem mit dem Dreieck

Ich habe das Programm mit dem Dreieck nachprogrammiert und schon mehrmals nach Fehlern gesucht, aber es wird trotzdem immer nur ein größer und kleiner werdendes Viereck gezeichnet.
Hier ist der Code:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <Windows.h>
#include <TriBase.h>
#include "..\\..\\Allgemeines\\InitWindow.h"
#include "..\\..\\Allgemeines\\Direct3DEnum.h"
#include "..\\..\\Allgemeines\\InitDirect3D.h"
#include "..\\..\\resource.h"

struct SVertex
{
    tbVector3 vPosition;
    DWORD dwColor;
    static const DWORD dwFVF;
};


const DWORD SVertex::dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;

float g_fTime = 0.0f;
SVertex g_aTriangleVertex[3];
SDirect3DParameters D3DParams;

tbResult Render(float fNumSecsPassed)
{
    HRESULT hResult;

    tbMatrix mRotation(tbMatrixRotationY(TB_DEG_TO_RAD(g_fTime * 90.0f)));
    tbMatrix mTranslation(tbMatrixTranslation(tbVector3(0.0f,0.0f,2.0f)));

    tbMatrix mWorld(mRotation * mTranslation);
    g_pD3DDevice->SetTransform(D3DTS_WORLD,(D3DMATRIX*)(&mWorld));

    if(FAILED(hResult = g_pD3DDevice -> Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
        D3DCOLOR_XRGB(0,0,63),1.0,0)))
    {
        MessageBox(g_hWindow,"Fehler beím leeren der ZBuffers!","Fehler", MB_ICONEXCLAMATION | MB_OK);
        TB_ERROR_DIRECTX("g_pD3DDevice->Clear",hResult,TB_STOP);
    }

    g_pD3DDevice -> BeginScene();
    
    if(FAILED(hResult = g_pD3DDevice ->DrawPrimitiveUP(D3DPT_TRIANGLELIST,1,&g_aTriangleVertex,sizeof(SVertex))))
    {
        MessageBox(g_hWindow,"Fehler beim Zeichnen!","Fehler", MB_ICONEXCLAMATION | MB_OK);
        TB_ERROR_DIRECTX("g_pD3DDevice->DrawPrimitiveUP",hResult,TBA_STOP);
    }

    g_pD3DDevice -> EndScene();

    g_pD3DDevice -> Present(NULL,NULL,NULL,NULL);

    if(GetAsyncKeyState(VK_ESCAPE))
    {
        PostQuitMessage(0);
    }

    return TB_OK;
}

tbResult Move(float fNumSecsPassed)
{
    g_fTime += fNumSecsPassed;

    return TB_OK;
}

tbResult InitScene()
{

    HRESULT hResult;
    if(FAILED(hResult = g_pD3DDevice ->SetFVF(SVertex::dwFVF)))
    {
        MessageBox(g_hWindow,"Fehler beím setzen des FVF!","Fehler", MB_ICONEXCLAMATION | MB_OK);
        TB_ERROR_DIRECTX("g_pD3DDevice->SetFVF",hResult,TB_ERROR);
    }

    g_pD3DDevice -> SetRenderState(D3DRS_LIGHTING, FALSE);
    g_pD3DDevice -> SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    g_pD3DDevice -> SetRenderState(D3DRS_DITHERENABLE, TRUE);

    float fAspect = (float)(D3DParams.VideoMode.Width)
            /(float)(D3DParams.VideoMode.Height);

    tbMatrix mProjection = tbMatrixProjection(TB_DEG_TO_RAD(90.0f),
        fAspect, 0.1f, 100.0f);

    g_pD3DDevice ->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)(&mProjection));

    g_aTriangleVertex[0].vPosition = tbVector3(0.0f, 1.0f, 0.0f);
    g_aTriangleVertex[1].vPosition = tbVector3(1.0f, -1.0f, 0.0f);
    g_aTriangleVertex[2].vPosition = tbVector3(-1.0f, -1.0f, 0.0f);
    g_aTriangleVertex[0].dwColor = tbColor(1.0f,0.0f,0.0f);
    g_aTriangleVertex[1].dwColor = tbColor(0.0f,1.0f,0.0f);
    g_aTriangleVertex[2].dwColor = tbColor(0.0f,0.0f,1.0f);

    return TB_OK;
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* pcCmdLine, int iShowCmd)
{
    tbInit();
    SDirect3DParameters D3DParams;
    tbResult result = GetDirect3DParameters(&D3DParams);
    if(result == TB_ERROR)
    {
        MessageBox(NULL,"Fehler beim abzählen!","Fehler!",MB_ICONEXCLAMATION | MB_OK);
        tbExit();
        return 1;
    }
    else if(result == TB_CANCELED)
    {
        tbExit();
        return 0;
    }
    if(InitWindow(D3DParams.VideoMode.Width,
        D3DParams.VideoMode.Height,
        "DirectX",
        LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_ICON1))))
    {
        MessageBox(NULL,"Fehler beim erstellen des Fensters!","Fehler!",MB_ICONEXCLAMATION | MB_OK);
        tbExit();
        return 1;
    }

    if(InitDirect3D(&D3DParams,g_hWindow))
    {
        MessageBox(g_hWindow,"Fehlerhafte Initialisierung von Direct3D!","Fehler",MB_OK | MB_ICONEXCLAMATION);
        ExitWindow();
        tbExit();
        return 1;
    }

    if(InitScene())
    {
        MessageBox(g_hWindow,"Szene konnte nicht inizialisiert werden!","Fehler",MB_OK | MB_ICONEXCLAMATION);
        ExitDirect3D();
        ExitWindow();
        tbExit();
        return 1;
    }

    tbDoMessageLoop(Move,Render);

    ExitDirect3D();
    ExitWindow();
    tbExit();
    return 0;
}


kann mir jemand den Fehler sagen?

Black-Panther

Alter Hase

Beiträge: 1 443

Wohnort: Innsbruck

  • Private Nachricht senden

2

06.06.2007, 22:40

Setz zur Sicherheit IMMER eine Kameramatrix... auch wenns nur die Identitätsmatrix ist!
stillalive studios
Drone Swarm (32.000 Dronen gleichzeitig steuern!)
facebook, twitter

3

07.06.2007, 14:08

sorry hab grad erst angefangen mit directX. Wie macht man das?

Black-Panther

Alter Hase

Beiträge: 1 443

Wohnort: Innsbruck

  • Private Nachricht senden

4

07.06.2007, 14:20

C-/C++-Quelltext

1
g_pD3DDevice ->SetTransform(D3DTS_VIEW, (D3DMATRIX*)(&mCamera));


Wobei mCamera die Kameramatrix ist, welche du einfach auf tbMatrixIdentity() (ich glaub so heißt die Fkt) setzt!
stillalive studios
Drone Swarm (32.000 Dronen gleichzeitig steuern!)
facebook, twitter

5

07.06.2007, 14:22

vielen danke

Bösewicht

unregistriert

6

07.06.2007, 14:22

Die ist doch im Code von David drin.

7

08.06.2007, 10:43

So ich hab jetzt ne Kameramatrix erstellt und auf tbMatrixIdentity()
gesetzt, hab aber immer noch das selbe ergebnis...
hier is nochmal der Code:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <Windows.h>
#include <TriBase.h>
#include "..\\..\\Allgemeines\\InitWindow.h"
#include "..\\..\\Allgemeines\\Direct3DEnum.h"
#include "..\\..\\Allgemeines\\InitDirect3D.h"
#include "..\\..\\resource.h"

struct SVertex
{
    tbVector3 vPosition;
    DWORD dwColor;
    static const DWORD dwFVF;
};


const DWORD SVertex::dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;

float g_fTime = 0.0f;
SVertex g_aTriangleVertex[3];
SDirect3DParameters D3DParams;

tbResult Render(float fNumSecsPassed)
{
    HRESULT hResult;
    tbMatrix mRotation(tbMatrixRotationY(TB_DEG_TO_RAD(g_fTime * 90.0f)));
    tbMatrix mTranslation(tbMatrixTranslation(tbVector3(0.0f,0.0f,2.0f)));
    tbMatrix mWorld(mRotation * mTranslation);

    g_pD3DDevice->SetTransform(D3DTS_WORLD,(D3DMATRIX*)(&mWorld));  

    if(FAILED(hResult = g_pD3DDevice -> Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
        D3DCOLOR_XRGB(0,0,63),1.0,0)))
    {
        MessageBox(g_hWindow,"Fehler beím leeren der ZBuffers!","Fehler", MB_ICONEXCLAMATION | MB_OK);
        TB_ERROR_DIRECTX("g_pD3DDevice->Clear",hResult,TB_STOP);
    }

    g_pD3DDevice -> BeginScene();
    
    if(FAILED(hResult = g_pD3DDevice ->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,1,&g_aTriangleVertex,sizeof(SVertex))))
    {
        MessageBox(g_hWindow,"Fehler beim Zeichnen!","Fehler", MB_ICONEXCLAMATION | MB_OK);
        TB_ERROR_DIRECTX("g_pD3DDevice->DrawPrimitiveUP",hResult,TB_STOP);
    }

    g_pD3DDevice -> EndScene();

    g_pD3DDevice -> Present(NULL,NULL,NULL,NULL);

    if(GetAsyncKeyState(VK_ESCAPE))
    {
        PostQuitMessage(0);
    }

    return TB_OK;
}

tbResult Move(float fNumSecsPassed)
{
    g_fTime += fNumSecsPassed;

    return TB_OK;
}

tbResult InitScene()
{

    HRESULT hResult;
    if(FAILED(hResult = g_pD3DDevice ->SetFVF(SVertex::dwFVF)))
    {
        MessageBox(g_hWindow,"Fehler beím setzen des FVF!","Fehler", MB_ICONEXCLAMATION | MB_OK);
        TB_ERROR_DIRECTX("g_pD3DDevice->SetFVF",hResult,TB_ERROR);
    }

    g_pD3DDevice -> SetRenderState(D3DRS_LIGHTING, FALSE);
    g_pD3DDevice -> SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    g_pD3DDevice -> SetRenderState(D3DRS_DITHERENABLE, TRUE);

    float fAspect = (float)(D3DParams.VideoMode.Width)
            /(float)(D3DParams.VideoMode.Height);

    tbMatrix mCamera(tbMatrixIdentity());
    tbMatrix mProjection = tbMatrixProjection(TB_DEG_TO_RAD(90.0f),
        fAspect, 0.1f, 100.0f);

    g_pD3DDevice ->SetTransform(D3DTS_VIEW, (D3DMATRIX*)(&mCamera));
    g_pD3DDevice ->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)(&mProjection));

    g_aTriangleVertex[0].vPosition = tbVector3(0.0f, 1.0f, 0.0f);
    g_aTriangleVertex[1].vPosition = tbVector3(1.0f, -1.0f, 0.0f);
    g_aTriangleVertex[2].vPosition = tbVector3(-1.0f, -1.0f, 0.0f);
    g_aTriangleVertex[0].dwColor = tbColor(1.0f,0.0f,0.0f);
    g_aTriangleVertex[1].dwColor = tbColor(0.0f,1.0f,0.0f);
    g_aTriangleVertex[2].dwColor = tbColor(0.0f,0.0f,1.0f);

    return TB_OK;
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* pcCmdLine, int iShowCmd)
{
    tbInit();
    SDirect3DParameters D3DParams;
    tbResult result = GetDirect3DParameters(&D3DParams);
    if(result == TB_ERROR)
    {
        MessageBox(NULL,"Fehler beim abzählen!","Fehler!",MB_ICONEXCLAMATION | MB_OK);
        tbExit();
        return 1;
    }
    else if(result == TB_CANCELED)
    {
        tbExit();
        return 0;
    }
    if(InitWindow(D3DParams.VideoMode.Width,
        D3DParams.VideoMode.Height,
        "DirectX",
        LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_ICON1))))
    {
        MessageBox(NULL,"Fehler beim erstellen des Fensters!","Fehler!",MB_ICONEXCLAMATION | MB_OK);
        tbExit();
        return 1;
    }

    if(InitDirect3D(&D3DParams,g_hWindow))
    {
        MessageBox(g_hWindow,"Fehlerhafte Initialisierung von Direct3D!","Fehler",MB_OK | MB_ICONEXCLAMATION);
        ExitWindow();
        tbExit();
        return 1;
    }

    if(InitScene())
    {
        MessageBox(g_hWindow,"Szene konnte nicht inizialisiert werden!","Fehler",MB_OK | MB_ICONEXCLAMATION);
        ExitDirect3D();
        ExitWindow();
        tbExit();
        return 1;
    }

    tbDoMessageLoop(Move,Render);

    ExitDirect3D();
    ExitWindow();
    tbExit();
    return 0;
}

muss die KameraMatrix in ne andere Funkion?

Ich hab keine KameraMatrix gefunden im Beispielprogramm...

8

08.06.2007, 11:30

jetzt funktionierts!
hab den Code einfach neu geschrieben ;)
thx @ all!

Werbeanzeige