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

11

16.01.2010, 16:52

ich hab jetzt Camera-,Projektions-,Rotations- und Weltmatrix gesetzt aber es erscheint trotzdem kein Dreieck:

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
#include <windows.h>
#include "InitD3D.h"
#include "InitWindow.h"
#include <dxerr9.h>
#include<d3d9.h> 
#include<d3dx9.h> 


#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ |D3DFVF_DIFFUSE)

CInitD3D id3d;
HWND g_hWindow;

int Höhe = 600;
int Breite = 800;

FLOAT RotationX      = 0; 
FLOAT RotationY      = 0; 
FLOAT RotationZ      = 0; 

FLOAT TranslationX   = 0; 
FLOAT TranslationY   = 0; 
FLOAT TranslationZ   = 0; 

//Hier steht wndProc und initwindow 

struct CUSTOMVERTEX
{
    float x,y,z;
};

CUSTOMVERTEX Vertices[3] = 
{
    {2.0f,5.0f,1.0f},
    {4.0f,2.0f,1.0f},
    {6.0f,5.0f,1.0f}
};

HRESULT Render()
{
    D3DXMATRIX ViewMatrix; 
    D3DXMatrixLookAtLH(&ViewMatrix, 
                       &D3DXVECTOR3(0.0f, 0.0f, -10.0f), 
                       &D3DXVECTOR3(0.0f, 0.0f, 0.0f), 
                       &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); 

    D3DXMATRIX WorldMatrix; 
    D3DXMATRIX RotationMatrix; 
    D3DXMATRIX TranslationMatrix; 

    D3DXMatrixRotationX(&RotationMatrix, RotationX); 
    D3DXMatrixRotationY(&RotationMatrix, RotationY); 
    D3DXMatrixRotationZ(&RotationMatrix, RotationZ); 

    D3DXMatrixTranslation(&TranslationMatrix, TranslationX, TranslationY, TranslationZ); 

    D3DXMatrixMultiply(&WorldMatrix, &RotationMatrix, &TranslationMatrix); 

    id3d.pd3dDevice->SetTransform(D3DTS_WORLD, &WorldMatrix); 


    HRESULT hresult;
    if(FAILED(hresult = id3d.pd3dDevice->Clear(0,
                           NULL,
                           D3DCLEAR_TARGET,
                           D3DCOLOR_XRGB(0, 0, 63),
                           1.0f,
                           0)))
    {
        MessageBox(NULL,"Fehler beim Leeren des Backbuffers","Fehler",MB_OK);
        
        return 1;
    }

    id3d.pd3dDevice->BeginScene();
    id3d.pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST,1,Vertices,sizeof(CUSTOMVERTEX));
    id3d.pd3dDevice->EndScene();
    id3d.pd3dDevice->Present(NULL,NULL,NULL,NULL);

    return 0;
}

HRESULT InitScene()
{
    HRESULT hresult;
    hresult = id3d.pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
    if(FAILED(hresult))
    {
        MessageBox(NULL,"Fehler beim Setzen des Vertexformat","Fehler",MB_OK);
        return 1;
    }

    id3d.pd3dDevice->SetRenderState(D3DRS_LIGHTING,FALSE);
    id3d.pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
    id3d.pd3dDevice->SetRenderState(D3DRS_DITHERENABLE,TRUE);

    D3DXMATRIX ProjMatrix; 
    D3DXMatrixPerspectiveFovLH(&ProjMatrix, 
                               D3DX_PI/4, 
                               static_cast<float>(Breite) / static_cast<float>(Höhe), 
                               1.0f, 
                               100.0f ); 

    id3d.pd3dDevice->SetTransform(D3DTS_PROJECTION, &ProjMatrix); 

    return 0;
}

INT WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   char*    lpCmdLine,
                   int       nCmdShow)
{
    InitWindow();
    id3d.InitD3D(g_hWindow);

    InitScene();

    MSG message; 
    ZeroMemory(&message,sizeof(MSG)); 
    while(message.message != WM_QUIT) 
    { 
        while(PeekMessage(&message,NULL,0,0,PM_REMOVE)) 
        { 
            TranslateMessage(&message); 
            DispatchMessage(&message); 
        } 
        Render();
    } 

    return 0;
}
Metal ist keine Musik sondern eine Religion.

12

16.01.2010, 17:04

Dir ist schon klar, dass das FVF falsch ist, oder ?

13

16.01.2010, 17:06

falsch Oo inwiefern?
Metal ist keine Musik sondern eine Religion.

14

16.01.2010, 17:10

C-/C++-Quelltext

1
2
3
4
struct CUSTOMVERTEX
{
    float x,y,z;
};

Da hast du die Position drinne.

C-/C++-Quelltext

1
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ |D3DFVF_DIFFUSE)

Hiermit teilst du DX aber mit, dass du in deinem Vertexformat Position und Farbe drinne hast.

15

16.01.2010, 17:17

macht keinen Unterschied
Metal ist keine Musik sondern eine Religion.

16

16.01.2010, 17:29

Was sagt denn die DirectX Debug-Ausgabe ?

Nexxtron

Alter Hase

Beiträge: 424

Wohnort: Heilbronn

Beruf: Student - Software Engineering

  • Private Nachricht senden

17

16.01.2010, 18:41

du hast wohl vergessen deine ViewMatrix zu setzen :roll:
New Project: Operation CityRacer

Gotbread

Alter Hase

Beiträge: 421

Beruf: Student (Etechnik) + Hiwi

  • Private Nachricht senden

18

17.01.2010, 13:01

ei ei ei, so kann das nix werden.

zuerstmal, du brauchst eine farbe! ob dx auch ohne farbe was
zeichnen kann, weiß ich grade nicht, trotzdem solltest du sie einbauen,
sonst wäre dein dreieck sehr langweilig.

C-/C++-Quelltext

1
2
3
4
5
struct CUSTOMVERTEX
{
    float x,y,z;
    DWORD color; // <---

};


natürlich musst du deine vertices anpassen, ungefähr so:
(die positionen sind auch komisch)

C-/C++-Quelltext

1
2
3
4
5
6
CUSTOMVERTEX Vertices[3] =
{
    {0.0f,1.0f,1.0f,0x00ff0000},
    {1.0f,0.0f,1.0f,0x0000ff00},
    {-1.0f,0.0f,1.0f,0x000000ff}
};


die matrix-geschichte ist auch nicht richtig...

D3DXMatrixRotation* überschreibt dir übrigens jedes mal die matrix,
du musst also mehrere anlegen, und miteinander multiplizieren.

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
D3DXMATRIX WorldMatrix;
D3DXMATRIX ViewMatrix;
D3DXMATRIX ProjectionMatrix;

float stime = 0.f;
stime += 0.01f;
D3DXMatrixRotationY(&WorldMatrix, stime);

D3DXMatrixLookAtLH(&ViewMatrix,
                       &D3DXVECTOR3(0.0f, 0.0f, -10.0f),
                       &D3DXVECTOR3(0.0f, 0.0f, 0.0f),
                       &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); 

D3DXMatrixPerspectiveFovLH(&ProjectionMatrix, D3DXToRadian(60.f),1.f,1.f,100.f);

id3d.pd3dDevice->SetTransform(D3DTS_WORLD, &WorldMatrix);
id3d.pd3dDevice->SetTransform(D3DTS_VIEW, &viewMatrix);
id3d.pd3dDevice->SetTransform(D3DTS_PROJECTION, &ProjectionMatrix);


ein zbuffer wäre übrigens sehr nützlich ;)

danach sollte es eigentlich klappen
Mfg Goti
www.gotbread.bplaced.net
viele tolle spiele kostenlos, viele hardware-basteleien :)

"Es ist nicht undicht, es läuft über" - Homer Simpson

19

25.01.2010, 18:43

Sorry für die späte antwort aber: Du bist der größte Gotbread. Es lag tatsächlich an den Matricen und der Farbe :D :D :D
Metal ist keine Musik sondern eine Religion.

Gotbread

Alter Hase

Beiträge: 421

Beruf: Student (Etechnik) + Hiwi

  • Private Nachricht senden

20

25.01.2010, 18:45

juhu :lol:
Mfg Goti
www.gotbread.bplaced.net
viele tolle spiele kostenlos, viele hardware-basteleien :)

"Es ist nicht undicht, es läuft über" - Homer Simpson

Werbeanzeige