metody w klasie

0

Mam klasę window która posiada różne funkcje. Jedna z nich(window::refresh) przyjmuje 3 parametry(2 vectory jeden bool) jednak kiedy wypisuję ich wartość to widze w konsoli:

1.#QNAN 

co to oznacza? czemu tak się dzieje? jak to naprawić?

0
class Object
{
public:
    double rotation;
    Object()
    {
        rotation=0;
    }
}
int main
{
    vector <Object>object;
    object.push_back(Object());
    object[0].rotation=0;
} 

i jak mam funkcję której argumentem jest

vector<Object>object 

to jego zmienna rotation wynosi 1.#QNAN

0
void refresh(vector<Object>object)
{
    cout << object[0].rotation << endl;
} 
0

a więc w uproszczeniu(wywalając inne zmienne)

class Object
{
public:
    double rotation;
    Object()
    {
        rotation=0;
    }
}
void refresh(vector<Object>object)
{
    cout << object[0].rotation << endl;
}
int main()
{
    vector<Object>object;
    object.push_back(Object());
    object[0].rotation=0.0;
    refresh(object);
    return 0;
} 
0

coś mi się widzi, że coś nie tak przekazujesz. Dodatkowo argument taki jak podajesz jest nieefektywny, jeśli nie wykonujesz operacji zmian, to lepiej przekaż

 void refresh(vector<Object> &object)

Dodatkowo - coś nie wszystkie informacje podajesz, co widać np - kod który wkleiłeś nie kompiluje się, bo brakuje średnika po definicji klasy.

0

Pomijając to, że kopiujesz cały wektor do funkcji, to żadnego NaNa nie widzę: http://ideone.com/IEIjht

0

mogę wkleić cały kod ale jest to lekko poplątane

0

To popraw go, żeby nie był poplątany to jest duża szansa, że znajdziesz błąd. W tym co podałeś nie ma błędu.

0

plik main.cpp:

#include "definitions.hpp"
#include "loadercore.hpp"
#include "phisics.hpp"
using namespace std;

int time=0;
void CALLBACK TimerProc(HWND hWnd, UINT uMsg, UINT IDEvent, DWORD dwTime)
{
    time++;
}
UINT timer=SetTimer(NULL,1,10,&TimerProc);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
    HWND consolewindow=FindWindowA("ConsoleWindowClass",NULL);
    double turning=3;
    Coords helpcoords;
    bool rot=true;
    vector <Window> childwindow;
    vector <Object> object;
    vector <dBlock> models;
    vector <cProject> cproject;
    loadall(models,cproject);
    Player player;
    player.objectid=0;
    Keyboard keyboard;
    bool Exit=false;
    MSG msg;
    if (models.size()>0)
    {
        models[0].walls.push_back(Wall());
        models[0].walls[0].points.push_back(Point(50.0,50.0,1.0,1.0,1.0));
        models[0].walls[0].points.push_back(Point(-50.0,50.0,1.0,1.0,1.0));
        models[0].walls[0].points.push_back(Point(-50.0,-50.0,1.0,1.0,1.0));
        models[0].walls[0].points.push_back(Point(50.0,-50.0,1.0,1.0,1.0));
    }
    object.push_back(Object());
    object[0].blocks.push_back(Block(0,models[0]));
    object[0].blocks[0].energy.max=1.0;
    object[0].blocks[0].energy.current=0;
    object[0].blocks[0].thrust=100.0;
    object[0].blocks[0].angle=0;
    object[0].rotation=90.0;

    object.push_back(Object());
    object[1].blocks.push_back(Block(0,models[0]));
    object[1].blocks[0].energy.max=1.0;
    object[1].blocks[0].energy.current=0;
    object[1].blocks[0].thrust=0;
    object[1].blocks[0].angle=0;
    object[1].rotation=0;
    object[1].position.coords.x=300;

    object[1].blocks.push_back(Block(0,models[0]));
    object[1].blocks[1].energy.max=1.0;
    object[1].blocks[1].energy.current=0;
    object[1].blocks[1].thrust=0;
    object[1].blocks[1].angle=0;
    object[1].blocks[1].coords.x=100;

    Window mainwindow(hInstance,SW_MAXIMIZE);
    if (mainwindow.error==true)
    {
        return 0;
    }
    while (true)
    {
        while (time>0)
        {
            time--;
            if (!mainwindow.refresh(object,models,player,rot))
            {
                mainwindow.updatemouse();
                if (mainwindow.mousestate.lkey and mainwindow.active==1)
                {
                    helpcoords.x=mainwindow.mousestate.x;
                    helpcoords.y=mainwindow.mousestate.y;
                    rotation(0-object[player.objectid].rotation,helpcoords.x,helpcoords.y);
                    if (getrotation(helpcoords.x,helpcoords.y)*object[player.objectid].rspeed<0 and abs(round(getrotation(helpcoords.x,helpcoords.y)-90))<3)
                    {
                        object[player.objectid].rspeed-=round(object[player.objectid].rspeed/5);
                    }
                    else if (getrotation(helpcoords.x,helpcoords.y)*object[player.objectid].rspeed<0 and abs(round(getrotation(helpcoords.x,helpcoords.y)-90))<15)
                    {
                        object[player.objectid].rspeed-=round(object[player.objectid].rspeed/7);
                    }
                    if (round(getrotation(helpcoords.x,helpcoords.y)-90)>0)
                    {
                        object[player.objectid].rspeed+=turning;
                    }
                    else if (round(getrotation(helpcoords.x,helpcoords.y)-90)<0)
                    {
                        object[player.objectid].rspeed-=turning;
                    }
                }
                for (unsigned int i=0; i<object.size(); i++)
                {
                    calculatephysics(object[i],models,0.01);
                }
                keyboard.reloadstates();
                if (keyboard.usekey('P')==true and mainwindow.active==1)
                {
                    if (mainwindow.mode==0)
                    {
                        mainwindow.maximize();
                    }
                    else if (mainwindow.mode==1)
                    {
                        mainwindow.normalize();
                    }
                }
                if (keyboard.keys[(int)'W'].state==true)
                {
                    for (unsigned int i=0; i<object[0].blocks.size(); i++)
                    {
                        object[0].blocks[i].energy.current=object[0].blocks[i].energy.max;
                    }
                }
                else
                {
                    for (unsigned int i=0; i<object[0].blocks.size(); i++)
                    {
                        object[0].blocks[i].energy.current=0;
                    }
                }
            }
            else
            {
                Exit=true;
                break;
            }
        }
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
            {
                Exit=true;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        if (Exit==true)
        {
            break;
        }
    }
    ShowWindow(consolewindow,SW_SHOW);
    DisableOpenGL(mainwindow.windowhandle,mainwindow.hDC,mainwindow.hRC);
    DestroyWindow(mainwindow.windowhandle);
    return 0;
}
 

ważniejsze rzeczy z definitions.hpp:

class Object
{
public:
    vector <Block> blocks;
    double rotation;
    double vx,vy;
    double rspeed;
    double displayrange;
    Position position;
    void recalculaterange()
    {
        displayrange=0;
        for (unsigned int i=0; i<blocks.size(); i++)
        {
            if (sqrt(pow(blocks[i].coords.x,2)+pow(blocks[i].coords.y,2))>displayrange)
            {
                displayrange=sqrt(pow(blocks[i].coords.x,2)+pow(blocks[i].coords.y,2));
            }
        }
    }
    Object()
    {
        vx=0;
        vy=0;
        rspeed=0;
        rotation=0;
        position.coords.x=0;
        position.coords.y=0;
        position.chunk.x=0;
        position.chunk.y=0;
        position.sector.x=0;
        position.sector.y=0;
    }
    Object(long long int X,long long int Y)
    {
        vx=0;
        vy=0;
        rspeed=0;
        rotation=0;
        position.chunk.x=X%960;
        position.chunk.y=Y%540;
        position.coords.x=X-position.chunk.x*960;
        position.coords.y=Y-position.chunk.y*540;
        position.sector.x=position.chunk.x%100;
        position.sector.y=position.chunk.y%100;
        position.chunk.x=position.chunk.x-position.sector.x*100;
        position.chunk.y=position.chunk.y-position.sector.y*100;
    }
    Object(double X,double Y,double chunkx,double chunky)
    {
        vx=0;
        vy=0;
        rspeed=0;
        rotation=0;
        position.coords.x=X;
        position.coords.y=Y;
        position.chunk.x=chunkx;
        position.chunk.y=chunky;
        position.sector.x=position.chunk.x%100;
        position.sector.y=position.chunk.y%100;
        position.chunk.x=position.chunk.x-position.sector.x*100;
        position.chunk.y=position.chunk.y-position.sector.y*100;
    }
    Object(double X,double Y,double chunkx,double chunky,double sectorx,double sectory)
    {
        vx=0;
        vy=0;
        rspeed=0;
        rotation=0;
        position.coords.x=X;
        position.coords.y=Y;
        position.chunk.x=chunkx;
        position.chunk.y=chunky;
        position.sector.x=sectorx;
        position.sector.y=sectory;
    }
    ~Object()
    {
        blocks.clear();
    }
};

class Window
{
private:
    Mause gamemouse;
public:
    bool active;
    bool cursor;
    int number;
    Mousestate mousestate;
    HWND windowhandle;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    WNDCLASSEX wcex;
    bool error;
    int mode;
    static LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
    void setmouseposition(int x,int y)
    {
        gamemouse.setposition(windowhandle,x*(gamemouse.Width/2)/(960),-y*(gamemouse.Hight/2)/(540));
    }
    void calculatemouse(int Mode)
    {
        gamemouse.calculate(windowhandle,Mode);
    }
    void updatemouse()
    {
        calculatemouse(MENU);
        mousestate.x=960*gamemouse.gamemouse_x/(gamemouse.Width/2);
        mousestate.y=540*gamemouse.gamemouse_y/(gamemouse.Hight/2);
        mousestate.lkey=GetAsyncKeyState(VK_LBUTTON);
        mousestate.rkey=GetAsyncKeyState(VK_RBUTTON);
    }
    void displayobject(Object object,vector <dBlock> models,Position position,int displayrange,bool itself,double angle,bool rot)
    {
        Coords helpcoords;
        if (itself or sqrt(pow(object.position.chunk.x*200+object.position.sector.x*2000+object.position.coords.x-position.chunk.x*200+position.sector.x*2000+position.coords.x,2)+pow(object.position.chunk.y*200+object.position.sector.y*2000+object.position.coords.y-position.chunk.y*200+position.sector.y*2000+position.coords.y,2))<2000+object.displayrange+displayrange)
        {
            for (unsigned int i=0; i<object.blocks.size(); i++)
            {
                for (unsigned int j=0; j<models[object.blocks[i].id].walls.size(); j++)
                {
                    glBegin(GL_POLYGON);
                    for (unsigned int k=0; k<models[object.blocks[i].id].walls[j].points.size(); k++)
                    {
                        helpcoords.x=models[object.blocks[i].id].walls[j].points[k].x;
                        helpcoords.y=models[object.blocks[i].id].walls[j].points[k].y;
                        rotation(object.blocks[i].angle,helpcoords.x,helpcoords.y);
                        helpcoords.x+=object.blocks[i].coords.x;
                        helpcoords.y+=object.blocks[i].coords.y;
                        if (itself==false or (itself==true and rot==true))
                        {
                            rotation(object.rotation,helpcoords.x,helpcoords.y);
                        }
                        if (itself==false)
                        {
                            helpcoords.x+=object.position.coords.x+object.position.chunk.x*960+96000*object.position.sector.x-(position.coords.x+position.chunk.x*960+96000*position.sector.x);
                            helpcoords.y+=object.position.coords.y+object.position.chunk.y*540+54000*object.position.sector.y-(position.coords.y+position.chunk.y*540+54000*position.sector.y);
                            if (rot==false)
                            {
                                rotation(270+angle,helpcoords.x,helpcoords.y);
                            }
                        }
                        helpcoords.x/=960;
                        helpcoords.y/=540;
                        glColor4d(models[object.blocks[i].id].walls[j].points[k].r,models[object.blocks[i].id].walls[j].points[k].g,models[object.blocks[i].id].walls[j].points[k].b,0.85);
                        glVertex2d(helpcoords.x,helpcoords.y);
                    }
                    glEnd();

                    glBegin(GL_LINE_LOOP);
                    for (unsigned int k=0; k<models[object.blocks[i].id].walls[j].points.size(); k++)
                    {
                        for (unsigned int k=0; k<models[object.blocks[i].id].walls[j].points.size(); k++)
                        {
                        helpcoords.x=models[object.blocks[i].id].walls[j].points[k].x;
                        helpcoords.y=models[object.blocks[i].id].walls[j].points[k].y;
                        rotation(object.blocks[i].angle,helpcoords.x,helpcoords.y);
                        helpcoords.x+=object.blocks[i].coords.x;
                        helpcoords.y+=object.blocks[i].coords.y;
                        if (itself==false or (itself==true and rot==true))
                        {
                            rotation(object.rotation,helpcoords.x,helpcoords.y);
                        }
                        if (itself==false)
                        {
                            helpcoords.x+=object.position.coords.x+object.position.chunk.x*960+96000*object.position.sector.x-(position.coords.x+position.chunk.x*960+96000*position.sector.x);
                            helpcoords.y+=object.position.coords.y+object.position.chunk.y*540+54000*object.position.sector.y-(position.coords.y+position.chunk.y*540+54000*position.sector.y);
                            if (rot==false)
                            {
                                rotation(270+angle,helpcoords.x,helpcoords.y);
                            }
                        }
                        helpcoords.x/=960;
                        helpcoords.y/=540;
                        glColor4d(models[object.blocks[i].id].walls[j].points[k].r,models[object.blocks[i].id].walls[j].points[k].g,models[object.blocks[i].id].walls[j].points[k].b,0.0);
                        glVertex2d(helpcoords.x,helpcoords.y);
                        }
                    }
                    glEnd();
                }
            }
        }
    }
    bool maximize()
    {
        mode=1;
        int width=0,hight=0;
        width=GetSystemMetrics(SM_CXSCREEN);
        hight=GetSystemMetrics(SM_CYSCREEN);
        if (SetWindowLongPtr(windowhandle,GWL_STYLE,WS_VISIBLE|WS_MAXIMIZE)!=0)
        {
            if (SetWindowPos(windowhandle,HWND_TOPMOST,0,0,width,hight,SWP_FRAMECHANGED)!=0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        else
        {
            return true;
        }
        return false;
    }
    bool normalize()
    {
        mode=0;
        if (SetWindowLongPtr(windowhandle,GWL_STYLE,WS_VISIBLE|WS_OVERLAPPEDWINDOW)!=0)
        {
            if (SetWindowPos(windowhandle,HWND_TOP,0,0,CW_USEDEFAULT,CW_USEDEFAULT,SW_SHOW)!=0)
            {
                ShowWindow(windowhandle,SW_MAXIMIZE);
                return false;
            }
            else
            {
                return true;
            }
        }
        else
        {
            return true;
        }
        return false;
    }
    bool refresh(vector <Object> object,vector <dBlock> models,Player player,bool rotobject)
    {
        cout << object[0].rotation << endl;
        Coords helpcoords;
        bool quit=false;
        if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
        {
            if (msg.message==WM_QUIT)
            {
                quit=true;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        else
        {
            glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
            glClearColor(0.05f,0.05f,0.15f,0.0f);
            glPushMatrix();
            if (active==1 and cursor==true)
            {
                calculatemouse(MENU*(rotobject==true));
                glBegin(GL_LINE_LOOP);
                for (int i=0; i<3; i++)
                {
                    helpcoords.x=0-(i==0 or i==1)*7*sqrt(3)+(i==2)*14*sqrt(3);
                    helpcoords.y=0+(i==0)*15-(i==1)*15;
                    //helpcoords.x=1;
                    //helpcoords.y=1;
                    if (GetAsyncKeyState(VK_LBUTTON))
                    {
                        glColor4f(1.0f,0.0f,0.0f,0.7f);
                    }
                    else
                    {
                        glColor4f(1.0f,1.0f,1.0f,0.2f);
                    }
                    rotation(getrotation(gamemouse.gamemouse_x,gamemouse.gamemouse_y),helpcoords.x,helpcoords.y);
                    helpcoords.x=/*object[player.objectid].displayrange+*/140-i*15;
                    helpcoords.y=0-15-(2-i)*5;
                    rotation(object[player.objectid].rotation,helpcoords.x,helpcoords.y);
                    helpcoords.x/=960;
                    helpcoords.y/=540;
                    //cout << helpcoords.x << "|" << helpcoords.y << "|" << object[1].rotation << endl;
                    glVertex2d((gamemouse.gamemouse_x)/(gamemouse.Width/2)+helpcoords.x,(gamemouse.gamemouse_y)/(gamemouse.Hight/2)+helpcoords.y);
                }
                glEnd();
                for (int i=0; i<3; i++)
                {
                    glBegin(GL_LINE_STRIP);
                    object[player.objectid].recalculaterange();
                    helpcoords.x=/*object[player.objectid].displayrange+*/140-i*15;
                    helpcoords.y=15.0+(2-i)*5.0;
                    glColor4f(1.0f,1.0f,1.0f,1.0f);
                    rotation(object[player.objectid].rotation,helpcoords.x,helpcoords.y);
                    helpcoords.x/=960;
                    helpcoords.y/=540;
                    //cout << helpcoords.x << "|";
                    glVertex2d(helpcoords.x,helpcoords.y);

                    helpcoords.x=/*object[player.objectid].displayrange+*/150-i*15;
                    helpcoords.y=0;
                    rotation(object[player.objectid].rotation,helpcoords.x,helpcoords.y);
                    helpcoords.x/=960.0;
                    helpcoords.y/=540.0;
                    glVertex2d(helpcoords.x,helpcoords.y);
                    //cout << helpcoords.x << "|";

                    helpcoords.x=/*object[player.objectid].displayrange+*/140-i*15;
                    helpcoords.y=0-15-(2-i)*5;
                    rotation(object[player.objectid].rotation,helpcoords.x,helpcoords.y);
                    helpcoords.x/=960;
                    helpcoords.y/=540;
                    //cout << helpcoords.x << endl;
                    glVertex2d(helpcoords.x,helpcoords.y);
                    glEnd();
                }
            }
            player.position=object[player.objectid].position;
            for (unsigned int i=0; i<object.size(); i++)
            {
                displayobject(object[i],models,player.position,player.getrange(object),player.objectid==(int)i,object[player.objectid].rotation,rotobject);
            }
            glPopMatrix();
            SwapBuffers(hDC);
            if(active==1)
            {
                calculatemouse(MENU);
                ShowCursor(0);
            }
            else
            {
                ShowCursor(1);
            }
        }
        return quit;
    }
    bool initialwindow(HINSTANCE hInstance,int Mode)
    {
        mode=0;
        cursor=true;
        wcex.cbSize=sizeof(WNDCLASSEX);
        wcex.style=CS_OWNDC;
        wcex.lpfnWndProc=WindowProc;
        wcex.cbClsExtra=0;
        wcex.cbWndExtra=0;
        wcex.hInstance=hInstance;
        wcex.hIcon=LoadIcon(NULL, IDI_APPLICATION);
        wcex.hCursor=LoadCursor(NULL, IDC_ARROW);
        wcex.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
        wcex.lpszMenuName=NULL;
        wcex.lpszClassName="MainWindow";
        wcex.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
        if (!RegisterClassEx(&wcex)) {return true;}
        windowhandle=CreateWindowEx(0,"MainWindow","Space Mission",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
        if (windowhandle==NULL)
        {
            return true;
        }
        ShowWindow(windowhandle,SW_SHOW);
        ShowWindow(windowhandle,Mode);
        RECT rect;
        GetWindowRect(windowhandle,&rect);
        gamemouse.insertsize(rect.right-rect.left,rect.bottom-rect.top);
        EnableOpenGL(windowhandle, &hDC, &hRC);
        glOrtho(-1,1,-1,1,-1,1);
        glEnable(GL_DEPTH_TEST);
        glShadeModel(GL_SMOOTH);
        glEnable(GL_BLEND);
        glEnable(GL_POINT_SMOOTH);
        glEnable(GL_LINE_SMOOTH);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        return false;
    }
    Window()
    {
        gamemouse.insertsize(1920,1080);
        error=false;
        mode=0;
    }
    Window(int width,int hight)
    {
        gamemouse.insertsize(width,hight);
        error=false;
        mode=0;
    }
    Window(HINSTANCE hInstance,int nCmdShow)
    {
        gamemouse.insertsize(1920,1080);
        error=false;
        mode=0;
        error=initialwindow(hInstance,nCmdShow);
    }
}; 
1

bez czytania kodu, gdzies w trakcie obliczen prawdopodobnie pojawia Ci sie NaN (not a number) czyli specjalna wartosc float ktora mowi Ci ze masz popsute obliczenia (np. dzielenie przez zero, pierwiastek z ujemnej liczby albo jakies inne cyrki).

0

no wiem co robi nan ale droga mojego rotation(póki co jedynej zmiennej która się rozwala) to deklaracja, ustawienie na 0 i przekazanie do funkcji a potem jest rozwalony... może coś pominąłem ale tego znaleźć nie mogę

0

nazywałbyś jakoś rozsądniej klasy i obiekty - klasa obiekt ma vector, więc przy przekazywaniu gdziekolwiek wymaga konstruktora kopiującego.

3

Masakra, jaki ten kod jest nieczytelny :-)

Przenieś to wielkie else z funkcji refresh() do osobnej funkcji.

Wywal z klasy wszystkie pola, które mogą być zmiennymi lokalnymi, jak msg i wcex. hDC i hRC też można się pozbyć.

if (itself or sqrt(pow(object.position.chunk.x*200+object.position.sector.x*2000+object.position.coords.x-position.chunk.x*200+position.sector.x*2000+position.coords.x,2)+pow(object.position.chunk.y*200+object.position.sector.y*2000+object.position.coords.y-position.chunk.y*200+position.sector.y*2000+position.coords.y,2))<2000+object.displayrange+displayrange)

Tego się naprawdę nie da czytać.

0

1.msg faktycznie niepotrzebnie dałem bo obsługuje przeważnie gdzie indziej.
2.wcex nie mogę przenieść bo za jakiś czas będą zmienne parametry i będzie możliwość stworzenia różnych okien.
3.hdc i/lub hrc wykorzystuje przy rysowaniu okna, każdy obiekt klasy okno ma mieć możliwość rysowania bez podawania mu buforu do rysowania. Nie jestem pewien czy moja klasa umożliwia rysowanie po paru oknach, ale z tego co mi się wydaje to po wywołaniu refresh narysuje coś na danym oknie, tak to ma działać...

0
Niikelion napisał(a)

no ta linijka to akurat sprawdzanie, czy obiekt jest w zasięgu widzenia

No ale jak to wygląda? Wyciągnij sobie współrzędne do osobnych zmiennych:

double x = object.position.chunk.x*200
         + object.position.sector.x*2000
         + object.position.coords.x
         - position.chunk.x*200
         + position.sector.x*2000
         + position.coords.x;

double y = object.position.chunk.y*200
         + object.position.sector.y*2000
         + object.position.coords.y
         - position.chunk.y*200
         + position.sector.y*2000
         + position.coords.y;

Trzeba by się też zastanowić nad tymi magicznymi wartościami, pełno masz w kodzie takich 200, 2000, 540, 54000... WTF.
Jak będziesz chciał zmienić 540 na 550 (cokolwiek to jest) to będziesz biegał po całym kodzie i zmieniał wszystkie 540 na 550 a 54000 na 55000?

double d = sqrt(x*x + y*y);
double limit = 2000 + object.displayrange + displayrange;

if (itself or d < limit)

prawda że lepiej? a i tak nadal nie idealnie.

0

no może i lepiej... te magiczne wartości są potrzebne do przeliczeń... mam taki podział mapy-sektory mają chunki, sektor ma ileś na ileś chunków a chunk ma ileś na ileś pikseli

0

ale nadal nie wiem jak ten konstruktor kopiujący tutaj dać...

0

no może i lepiej... te magiczne wartości są potrzebne do przeliczeń...

Ja nawet nie pytam do czego są potrzebne. Zdefiniuj stałe po prostu.
Jeśli jedna zależy od drugiej (jest wielokrotnością, sumą, różnicą...) to umieść to działanie w kodzie (bezpośrednio albo jako nową stałą), a nie wyliczoną liczbę.

Niektórzy uważają że w kodzie nie powinno być magicznych wartości z wyjątkiem 0, 1 i ewentualnie -1. Myślę że do tego powinieneś dążyć.

ale nadal nie wiem jak ten konstruktor kopiujący tutaj dać...
W kodzie są bardziej palące problemy niż konstruktor kopiujący. Póki wygląda jak wygląda, nie oczekuj że ktokolwiek będzie się chciał weń wgryzać i szukać błędów.

0

po paru testach skróciłem listę funkcji w których psuję liczbę... okazało się, że po wywołaniu calculate_physics rozwalam tę zmienną...

0
object.rotation+=object.rspeed*time; 

time typu double ustawiona na 0.01(zawsze taka jest) i rspeed typu double(zmienia się często ale na początku programu 0)

0

no to teraz znowu szukanie... tym razem co robię z rspeed

0

dobra błąd naprawiony,rozwalałem zmienną na obliczeniach fizycznych, a potem resztę zmiennych przez tę zmienną

1 użytkowników online, w tym zalogowanych: 0, gości: 1