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

01.08.2008, 14:20

Umrechnung der Koordinaten (2) - Grafik Problem

Hmm ich habe das so gemacht :

Code:

Quellcode

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
float worldTob2X (float x)
{
   if (x<400.0f || x>400.0f)
   {
      float tempX = x - 400.0f;
      tempX = tempX/30;
      return tempX;
   }
   else {return 0.0f;};
}

float worldTob2Y (float y)
{
   if (y > 300.0f)
   {
      float tempY = 300.0f - y;
      tempY = tempY/30;
      return tempY;
   }
   if (y < 300.0f)
   {
      float tempY = 300.0f - y;
      tempY = tempY/30;
      return tempY;
   }
   if (y == 300.0f)
   {
      return 0.0f;
   }
}
float b2ToWorldX (float x)
{
   float tempX;
   tempX = (800.0f/2.0f)+(30.0f*x);
   return tempX;
}

float b2ToWorldY (float y)
{
   float tempY;
   tempY =(600.0f/2.0f)-(30.0f*y);
   return tempY;
}

Bei einer Auflösung von 800*600.

Aber wenn ich das jetz Render kommt ein "Schönheitsfehler": (download)
Hier meine Render Funktion
Code:

Quellcode

1
2
3
4
5
6
7
8
void CSprite::Render()
{
   b2Vec2 position = m_body->GetPosition();
   m_xPos=(b2ToWorldX(position.x*m_zoom));             
   m_yPos=(b2ToWorldY(position.y*m_zoom));             
   m_rotation = (m_body->GetAngle());
   m_sprite->RenderEx(m_xPos, m_yPos, m_rotation,m_zoom); 
}

Ich glaube es liegt an der RenderFunction, kann aber nix finden.
Wenn ihr wollt kann ich auch mein Source uppen ;)

2

01.08.2008, 14:56

deine umrechnung ist schwachsin. guck se dir nochmal in meiner version an. x >> 1 entspricht x / 2, falls dir das hilft den Code zu verstehen. Ist nur viel schneller ;)
Devil Entertainment :: Your education is our inspiration
Der Spieleprogrammierer :: Community Magazin
Merlin - A Legend awakes :: You are a dedicated C++ (DirectX) programmer and you have ability to work in a team? Contact us!
Siedler II.5 RttR :: The old settlers-style is comming back!

Also known as (D)Evil

3

01.08.2008, 15:13

Zitat von »"Deviloper"«

Ist nur viel schneller ;)

Das wird ziemlich sicher vom Compiler rausoptimiert, benutz also lieber die verständlichere Variante ;)

4

01.08.2008, 18:00

1.

Das:

Quellcode

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
float g_width, g_heigth;  // des Fensters

// foreward decleration
namespace hge
{ class Point; }

namespace b2
{
    class Point
    {
        float m_x;
        float m_y;

    public:
        Point(const float x = 0.0f, const float y = 0.0f)
            : m_x(x), m_y(y)
        {}

    public:
        operator hge::Point() const { return hge::Point(m_x * 30 + (g_width >> 1)), m_y * 30 + (g_height >> 1))); }

    public:
        const float get_x() const { return m_x; }
        const float get_y() const { return m_y; }
        void set_x(const float x) { m_x = x; }
        void set_y(const float y) { m_y = y; }
    };
}; // b2

namespace hge
{
    class Point
    {
        float m_x;
        float m_y;

    public:
        Point(const float x = 0.0f, const float y = 0.0f)
            : m_x(x), m_y(y)
        {}

    public:
        operator b2::Point() const { return b2::Point((m_x - (g_width >> 1)) / 30, (m_y - (g_height >> 1)) / 30); }

    public:
        const float get_x() const { return m_x; }
        const float get_y() const { return m_y; }
        void set_x(const float x) { m_x = x; }
        void set_y(const float y) { m_y = y; }
    };
}; // hge

void init(const float width, const float heigth)
{
    g_width = width;
    g_heigth= heigth;
}


versteh ich net ;)

2. Was ist ein meiner Unrechnung flasch ? Sie is nur nicht optimial zB kann man das zusammenfügen

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
   if (y > 300.0f)
   {
      float tempY = 300.0f - y;
      tempY = tempY/30;
      return tempY;
   }
   if (y < 300.0f)
   {
      float tempY = 300.0f - y;
      tempY = tempY/30;
      return tempY;
   } 


Aber ist sie darum schwachsinn ? oder ist sie falsch ?

5

01.08.2008, 18:47

Hmm was verstehst du daran nicht? Nen Namensraum für b2 und hge, dann jeweils darin die Klasse Point, die einen Punkt darin representiert. Und diesen Punkten hab ich jeweils einen Umwandlungsoperator (type-cast) für den anderen Typ spendiert :)

Aber stimmt, da wahr ich wohl nicht gerade gut drauf als ich den Code geschrieben habe :P

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
inline const float world_to_b2_X(const float x)
{ return (x - (g_width >> 1)) / 30.0f; }

inline const float world_to_b2_Y(const float y)
{ return ((g_height >> 1) - y) / 30.0f); }

inline const float b2_to_world_X(const float x) 
{ return static_cast<float>(g_width >> 1) + x * 30.0f; }

inline const float b2_to_world_Y(const float y) 
{ return static_cast<float>(g_height >> 1) - y * 30.0f; }
... so sollte doch recht schnell und korrekt so funktionieren.
Devil Entertainment :: Your education is our inspiration
Der Spieleprogrammierer :: Community Magazin
Merlin - A Legend awakes :: You are a dedicated C++ (DirectX) programmer and you have ability to work in a team? Contact us!
Siedler II.5 RttR :: The old settlers-style is comming back!

Also known as (D)Evil

6

01.08.2008, 20:00

was heißt dieses >> 1 ?
das kenn ich nur von cin>> ? ^^

Und das bringt nen Fehler: Ungültig weil der linke Operant vom Typ Float ist

7

01.08.2008, 20:04

bitshift ;) einfach
y >> x == y / 2^x
y << x == y * 2^x
Devil Entertainment :: Your education is our inspiration
Der Spieleprogrammierer :: Community Magazin
Merlin - A Legend awakes :: You are a dedicated C++ (DirectX) programmer and you have ability to work in a team? Contact us!
Siedler II.5 RttR :: The old settlers-style is comming back!

Also known as (D)Evil

8

01.08.2008, 20:06

Muss ich das ersetzen oder muss ich das iwie implementieren wie zB bei Klassen ?

Aber erstzen is einfacher , y>> 1 = y/2 ^^

Fehler :

Quellcode

1
2
3
4
5
6
7
8
9
------ Erstellen gestartet: Projekt: 2D Simulation, Konfiguration: Debug Win32 ------
Verknüpfen...
LINK : warning LNK4098: Standardbibliothek "LIBCMTD" steht in Konflikt mit anderen Bibliotheken; /NODEFAULTLIB:Bibliothek verwenden.
csprite.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""float const __cdecl b2_to_world_Y(float)" (?b2_to_world_Y@@YA?BMM@Z)" in Funktion ""public: void __thiscall CSprite::Render(void)" (?Render@CSprite@@QAEXXZ)".
csprite.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""float const __cdecl b2_to_world_X(float)" (?b2_to_world_X@@YA?BMM@Z)" in Funktion ""public: void __thiscall CSprite::Render(void)" (?Render@CSprite@@QAEXXZ)".
C:\Dokumente und Einstellungen\Fabian\Desktop\C++\hge box2d\2D Simulation\Debug\2D Simulation.exe : fatal error LNK1120: 2 nicht aufgelöste externe Verweise.
Das Buildprotokoll wurde unter "file://c:\Dokumente und Einstellungen\Fabian\Desktop\C++\hge box2d\2D Simulation\2D Simulation\Debug\BuildLog.htm" gespeichert.
2D Simulation - 3 Fehler, 1 Warnung(en)
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========


Wenn ich die Lib ignoriere findet er LIBC.lib net.

Und das:
/NODEFAULTLIB:libcmtd.lib
hilf auch net :'(

9

01.08.2008, 20:34

Behoben, einfach das Inline weg gemacht, aber jetz ist das der gleiche Fehler wie im Photo obne zu sehn ist...
Da ist was mit Render flasch.. aber was ?

10

01.08.2008, 20:37

Mir ist aufgefallen wenn ich

Quellcode

1
2
const float b2_to_world_X(const float x)
{ return static_cast<float>(g_width >> 1) + x * 30.0f; } 

zu

Quellcode

1
2
const float b2_to_world_X(const float x)
{ return static_cast<float>(g_width >> 1) -  x * 30.0f; } 

[/code]

mache der das richtig zeichnet, aber dann sind die Koordinaten vertauscht wie man sich denken kann da der die flasch berechnet...


EDIT: sry wollte eig editieren[/code]

Werbeanzeige