Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[C++] TritEngine - Silnik Graficzny z wykorzystaniem matematyki niższej ( czyli jak ominąć macierze )

Ostatnio zmodyfikowano 2023-11-22 15:17
Autor Wiadomość
pekfos
» 2023-09-07 22:40:19
Chcesz obrócić punkt A dookoła punktu C.
1. Obliczasz odległość A od C (len1) i kąt wektora CA
2. Modyfikujesz kąt
3. Obliczasz A' jako punkt odległy od C o len1, pod zmodyfikowanym kątem. Dlaczego u ciebie jest tu A zamiast C?
P-180361
tBane
Temat założony przez niniejszego użytkownika
» 2023-09-07 22:51:41
Rotacja działa odrebnie, tzn :

https://drive.google.com/file/d/1BiNbJSiub4OoQ7HpyQOVh6bjVD5Lr8Im/view?usp=sharing

Ale razem nie działają.
Tu kod działającej tylko rotacji wokół osi Y.

C/C++
void model::rotatey()
{
   
for( trit * t = mesh; t != NULL; t = t->next )
   
{
       
len1 = sqrt( pow( cx - t->v1x, 2 ) + pow( cy - t->v1y, 2 ) + pow( cz - t->v1z, 2 ) );
       
len2 = sqrt( pow( cx - t->v2x, 2 ) + pow( cy - t->v2y, 2 ) + pow( cz - t->v2z, 2 ) );
       
len3 = sqrt( pow( cx - t->v3x, 2 ) + pow( cy - t->v3y, 2 ) + pow( cz - t->v3z, 2 ) );
       
       
// ROTATE Y ( adding vector of movement y )
       
deg1y =( atan2( cz - t->v1z, cx - t->v1x ) + M_PI ) * toDegrees;
       
deg2y =( atan2( cz - t->v2z, cx - t->v2x ) + M_PI ) * toDegrees;
       
deg3y =( atan2( cz - t->v3z, cx - t->v3x ) + M_PI ) * toDegrees;
       
       
fullAngley1 =( deg1y + angley ) * toRads;
       
fullAngley2 =( deg2y + angley ) * toRads;
       
fullAngley3 =( deg3y + angley ) * toRads;
       
       
t->r1x = cx + len1 * cos( fullAngley1 );
       
//t->r1y = t->r1y;
       
t->r1z = cz + len1 * sin( fullAngley1 );
       
       
t->r2x = cx + len2 * cos( fullAngley2 );
       
//t->r2y = t->r2y;
       
t->r2z = cz + len2 * sin( fullAngley2 );
       
       
t->r3x = cx + len3 * cos( fullAngley3 );
       
//t->r3y = t->r3y;
       
t->r3z = cz + len3 * sin( fullAngley3 );
   
}
}
P-180362
tBane
Temat założony przez niniejszego użytkownika
» 2023-09-07 22:54:29
Czyli chodzi o to że nie mam dodawać przeksztalconych odcinków a wektory przesunięć z odcinka oryginalnego do nowo utworzonego?
P-180363
pekfos
» 2023-09-07 23:03:10
Czyli chodzi o to że nie mam dodawać przeksztalconych odcinków a wektory przesunięć z odcinka oryginalnego do nowo utworzonego?
Nic z tego pytania nie rozumiem. Jakich znowu odcinków? Na pewno nie masz dodawać do siebie wektorów (więcej niż jednego) bo wszystkie są tu długości len1.

Ale razem nie działają.
Bo jak pisałem nie ma zgody co do wejść i wyjść. Obliczasz punkt rN, z punktu vN. Powinieneś na początku przekształceń skopiować vN do rN i potem niech wszystkie transformacje biorą rN jako input i generują rN' jako output.
P-180364
tBane
Temat założony przez niniejszego użytkownika
» 2023-09-08 19:21:01
Czyli chodzi o to, że nie mam dodawać przeksztalconych wektorow a wektory przesunięć wektorów ( odcinka oryginalnego do nowo utworzonego)?
P-180366
pekfos
» 2023-09-09 13:03:16
Lepiej podaj kod.
P-180367
tBane
Temat założony przez niniejszego użytkownika
» 2023-09-09 21:37:13
C/C++
/*
 trit Engine
 All rights reserved by BaneFTS - Bartosz Boguslawski
*/

#include <iostream>
using namespace std;
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengles2.h>
#include "shaders.cpp"
#include "camera.cpp"


float toDegrees = 180.f / M_PI;
float toRads = M_PI / 180.f;
float dz = 2.f; // delta z

float deg1z, deg2z, deg3z; // angle in degrees
float deg1y, deg2y, deg3y;
float deg1x, deg2x, deg3x;

float len1, len2, len3; // dlugosc odcinka miedzy centerModel a verticeOfModel

float fullAnglez1, fullAnglez2, fullAnglez3; // ( current angle + addedAngle ) w radianach
float fullAngley1, fullAngley2, fullAngley3;
float fullAnglex1, fullAnglex2, fullAnglex3;

int testindex;

float camx, camy, camz;

class trit
{
public:
   
float v1x, v1y, v1z, v2x, v2y, v2z, v3x, v3y, v3z; // vertexes (the fastest than class vector3)
   
float r, g, b, a; // colors: red green blue
   
trit * next;
   
   
float rz1x, rz1y, rz1z, rz2x, rz2y, rz2z, rz3x, rz3y, rz3z; // movement of rotated vertexes about Z axis
   
float ry1x, ry1y, ry1z, ry2x, ry2y, ry2z, ry3x, ry3y, ry3z; // movement of rotated vertexes about Y axis
   
float rx1x, rx1y, rx1z, rx2x, rx2y, rx2z, rx3x, rx3y, rx3z; // movement of rotated vertexes about X axis
   
float r1x, r1y, r1z, r2x, r2y, r2z, r3x, r3y, r3z; // rotated vertexes
   
   
float p1x, p1y, p2x, p2y, p3x, p3y; // projection
   
float cx, cy, cz; // used to sorting
   
trit( float, float, float, float, float, float, float, float, float, float, float, float, float );
   
trit( trit * );
   
~trit();
};

class model
{
public:
   
trit * mesh;
   
model * next;
   
float cx, cy, cz; // center to rotate
   
   
float anglex, angley, anglez; // current angle of rotate
   
float rotx, roty, rotz; // speed of zmiany rotate
   
   
model();
   
~model();
   
void addTrit( float, float, float, float, float, float, float, float, float, float, float, float, float );
   
void addTrit( trit * );
   
void setCenter( float, float, float ); // set center of model
   
void translate();
   
void rotatez();
   
void rotatey();
   
void rotatex();
   
void rotateSum();
   
void projection();
   
void calcCenterOfTriangles();
   
void sortTrits();
   
void calculate(); // calculate all vertices ( ... rotation, etc ... )
   
void render();
};

class tritEngine
{
public:
   
model * models;
   
camera * cam;
   
tritEngine();
   
~tritEngine();
   
void setCamera( camera * );
   
void addModel( model * );
   
void calculate(); // calculating vertices for any model
   
void sortModels(); // sorting models by distance to screen
   
void render();
};

float dist( float x1, float y1, float z1, float x2, float y2, float z2 )
{
   
return sqrt( pow( x2 - x1, 2 ) + pow( y2 - y1, 2 ) + pow( z2 - z1, 2 ) );
}

float dist( camera * cam, trit * t )
{
   
return sqrt( pow( cam->x - t->cx, 2 ) + pow( cam->y - t->cy, 2 ) + pow( cam->z - t->cz, 2 ) );
}


trit::trit( float v1x, float v1y, float v1z, float v2x, float v2y, float v2z, float v3x, float v3y, float v3z, float r = 128, float g = 128, float b = 128, float a = 256 )
{
   
this->v1x = v1x; this->v1y = v1y; this->v1z = v1z;
   
this->v2x = v2x; this->v2y = v2y; this->v2z = v2z;
   
this->v3x = v3x; this->v3y = v3y; this->v3z = v3z;
   
this->r = r; this->g = g; this->b = b; this->a = a;
   
   
next = NULL;
}

trit::trit( trit * t )
{
   
this->v1x = t->v1x; this->v1y = t->v1y; this->v1z = t->v1z;
   
this->v2x = t->v2x; this->v2y = t->v2y; this->v2z = t->v2z;
   
this->v3x = t->v3x; this->v3y = t->v3y; this->v3z = t->v3z;
   
this->r = t->r; this->g = t->g; this->b = t->b; this->a = t->a;
   
   
this->rz1x = rz1x; this->rz1y = rz1y; this->rz1z = rz1z;
   
this->rz2x = rz2x; this->rz2y = rz2y; this->rz2z = rz2z;
   
this->rz3x = rz3x; this->rz3y = rz3y; this->rz3z = rz3z;
   
   
next = NULL;
}

trit::~trit()
{
}

model::model()
{
   
mesh = NULL;
   
next = NULL;
   
cx = cy = cz = 0;
   
anglex = angley = anglez = 0;
   
rotx = roty = rotz = 0;
}

model::~model()
{
}

void model::addTrit( float v1x, float v1y, float v1z, float v2x, float v2y, float v2z, float v3x, float v3y, float v3z, float r = 128, float g = 128, float b = 128, float a = 256 )
{
   
trit * t = new trit( v1x, v1y, v1z, v2x, v2y, v2z, v3x, v3y, v3z, r, g, b, a );
   
   
if( mesh != NULL )
       
 t->next = mesh;
   
   
mesh = t;
}

void model::addTrit( trit * t )
{
   
if( mesh != NULL )
       
 t->next = mesh;
   
   
mesh = t;
}

void model::setCenter( float cx, float cy, float cz )
{
   
this->cx = cx;
   
this->cy = cy;
   
this->cz = cz;
}

void model::translate()
{
   
for( trit * t = mesh; t != NULL; t = t->next )
   
{
       
t->r1x = t->v1x;
       
t->r1y = t->v1y;
       
t->r1z = t->v1z;
       
       
t->r2x = t->v2x;
       
t->r2y = t->v2y;
       
t->r2z = t->v2z;
       
       
t->r3x = t->v3x;
       
t->r3y = t->v3y;
       
t->r3z = t->v3z;
   
}
}

void model::rotatez()
{
   
for( trit * t = mesh; t != NULL; t = t->next )
   
{
       
len1 = sqrt( pow( cx - t->v1x, 2 ) + pow( cy - t->v1y, 2 ) + pow( cz - t->v1z, 2 ) );
       
len2 = sqrt( pow( cx - t->v2x, 2 ) + pow( cy - t->v2y, 2 ) + pow( cz - t->v2z, 2 ) );
       
len3 = sqrt( pow( cx - t->v3x, 2 ) + pow( cy - t->v3y, 2 ) + pow( cz - t->v3z, 2 ) );
       
       
// ROTATE Z ( adding vector of movement z )
       
deg1z =( atan2( cy - t->v1y, cx - t->v1x ) + M_PI ) * toDegrees;
       
deg2z =( atan2( cy - t->v2y, cx - t->v2x ) + M_PI ) * toDegrees;
       
deg3z =( atan2( cy - t->v3y, cx - t->v3x ) + M_PI ) * toDegrees;
       
       
if( testindex++ < 360 * 2 )
       
{
           
cout << deg1z << ", " << deg2z << ", " << deg3z << endl;
       
}
       
fullAnglez1 =( deg1z + anglez ) * toRads;
       
fullAnglez2 =( deg2z + anglez ) * toRads;
       
fullAnglez3 =( deg3z + anglez ) * toRads;
       
       
t->rz1x = t->v1x -( cx + len1 * sin( fullAnglez1 ) );
       
t->rz1y = t->v1y -( cy + len1 * cos( fullAnglez1 ) );
       
t->rz1z = 0;
       
       
t->rz2x = t->v2x -( cx + len2 * sin( fullAnglez2 ) );
       
t->rz2y = t->v2y -( cy + len2 * cos( fullAnglez2 ) );
       
t->rz2z = 0;
       
       
t->rz3x = t->v3x -( cx + len3 * sin( fullAnglez3 ) );
       
t->rz3y = t->v3y -( cy + len3 * cos( fullAnglez3 ) );
       
t->rz3z = 0;
   
}
}

void model::rotatey()
{
   
for( trit * t = mesh; t != NULL; t = t->next )
   
{
       
len1 = sqrt( pow( cx - t->v1x, 2 ) + pow( cy - t->v1y, 2 ) + pow( cz - t->v1z, 2 ) );
       
len2 = sqrt( pow( cx - t->v2x, 2 ) + pow( cy - t->v2y, 2 ) + pow( cz - t->v2z, 2 ) );
       
len3 = sqrt( pow( cx - t->v3x, 2 ) + pow( cy - t->v3y, 2 ) + pow( cz - t->v3z, 2 ) );
       
       
// ROTATE Y ( adding vector of movement y )
       
deg1y =( atan2( cz - t->v1z, cx - t->v1x ) + M_PI ) * toDegrees;
       
deg2y =( atan2( cz - t->v2z, cx - t->v2x ) + M_PI ) * toDegrees;
       
deg3y =( atan2( cz - t->v3z, cx - t->v3x ) + M_PI ) * toDegrees;
       
       
fullAngley1 =( deg1y + angley ) * toRads;
       
fullAngley2 =( deg2y + angley ) * toRads;
       
fullAngley3 =( deg3y + angley ) * toRads;
       
       
t->r1x = cx + len1 * cos( fullAngley1 );
       
//t->r1y = t->r1y;
       
t->r1z = cz + len1 * sin( fullAngley1 );
       
       
t->r2x = cx + len2 * cos( fullAngley2 );
       
//t->r2y = t->r2y;
       
t->r2z = cz + len2 * sin( fullAngley2 );
       
       
t->r3x = cx + len3 * cos( fullAngley3 );
       
//t->r3y = t->r3y;
       
t->r3z = cz + len3 * sin( fullAngley3 );
   
}
}

void model::rotatex()
{
   
for( trit * t = mesh; t != NULL; t = t->next )
   
{
       
       
// ROTATE X ( adding vector of movement x )
       
deg1x = atan2( cy - t->r1y, cz - t->r1z ) * toDegrees;
       
deg2x = atan2( cy - t->r2y, cz - t->r2z ) * toDegrees;
       
deg3x = atan2( cy - t->r3y, cz - t->r3z ) * toDegrees;
       
       
fullAnglex1 =( deg1x + anglex ) * toRads;
       
fullAnglex2 =( deg2x + anglex ) * toRads;
       
fullAnglex3 =( deg3x + anglex ) * toRads;
       
       
//t->r1x = t->r1x;
       
t->r1y = t->r1y + len1 * sin( fullAnglex1 );
       
t->r1z = t->r1z + len1 * cos( fullAnglex1 );
       
       
//t->r2x = t->r2x;
       
t->r2y = t->r2y + len2 * sin( fullAnglex2 );
       
t->r2z = t->r2z + len2 * cos( fullAnglex2 );
       
       
//t->r3x = t->r3x;
       
t->r3y = t->r3y + len3 * sin( fullAnglex3 );
       
t->r3z = t->r3z + len3 * cos( fullAnglex3 );
   
}
}

void model::rotateSum()
{
   
for( trit * t = mesh; t != NULL; t = t->next )
   
{
       
t->r1x = t->v1x + t->rz1x; // + t->ry1x + t->rx1x;
       
t->r1y = t->v1y + t->rz1y; // + t->ry1y + t->rx1y;
       
t->r1z = t->v1z + t->rz1z; // + t->ry1z + t->rx1z;
       
       
t->r2x = t->v2x + t->rz2x; // + t->ry2x + t->rx2x;
       
t->r2y = t->v2y + t->rz2y; // + t->ry2y + t->rx2y;
       
t->r2z = t->v2z + t->rz2z; // + t->ry2z + t->rx2z;
       
       
t->r3x = t->v3x + t->rz3x; // + t->ry3x + t->rx3x;
       
t->r3y = t->v3y + t->rz3y; // + t->ry3y + t->rx3y;
       
t->r3z = t->v3z + t->rz3z; // + t->ry3z + t->rx3z;
   
}
}


void model::projection()
{
   
for( trit * t = mesh; t != NULL; t = t->next )
   
{
       
// PROJECTION 3D
       
t->p1x = t->rz1x;
       
t->p1y = t->rz1y;
       
       
t->p2x = t->rz2x;
       
t->p2y = t->rz2y;
       
       
t->p3x = t->rz3x;
       
t->p3y = t->rz3y;
       
       
/*
  // PROJECTION 3D->2D ( procjection 3 to 2D ) ( for tests the model )
   t->p1x = t->r1x + t->r1z/dz; t->p1y = t->r1y + t->r1z/dz;
   t->p2x = t->r2x + t->r2z/dz; t->p2y = t->r2y + t->r2z/dz;
   t->p3x = t->r3x + t->r3z/dz; t->p3y = t->r3y + t->r3z/dz;
  */
   
}
}

void model::calcCenterOfTriangles()
{
   
for( trit * t = mesh; t != NULL; t = t->next )
   
{
       
// POSITION OF TRIANGLE ( CENTER )
       
t->cx =( t->r1x + t->r2x + t->r3x ) / 3.f;
       
t->cy =( t->r1y + t->r2y + t->r3y ) / 3.f;
       
t->cz =( t->r1z + t->r2z + t->r3z ) / 3.f;
   
}
}


void model::sortTrits()
{
   
trit * orNewFirst, * orCurrent, * orSearch, * orNext;
   
   
if( mesh != NULL && mesh->next != NULL )
   
{
       
orNewFirst = mesh;
       
orCurrent = mesh->next;
       
orNewFirst->next = NULL;
       
       
while( orCurrent != NULL )
       
{
           
orNext = orCurrent->next;
           
if( orCurrent->cz > orNewFirst->cz )
           
{
               
orCurrent->next = orNewFirst;
               
orNewFirst = orCurrent;
           
} else
           
{
               
orSearch = orNewFirst;
               
while( orSearch->next != NULL && orSearch->next->cz > orCurrent->cz )
                   
 orSearch = orSearch->next;
               
               
orCurrent->next = orSearch->next;
               
orSearch->next = orCurrent;
           
};
           
           
orCurrent = orNext;
       
}
       
       
mesh = orNewFirst;
   
}
}


void model::calculate()
{
   
// atan2( x2-x1, y2-y1 ); - funkcja zwraca kat miedzy dwoma punktmi (x1,y1), (x2,y2)  
   
    // ROTATIONS OF VERTICES
   
translate();
   
rotatez();
   
//rotatey();
    //rotatex();
   
rotateSum();
   
projection();
   
calcCenterOfTriangles();
   
sortTrits();
   
}

void model::render()
{
   
float dz = 2.f; // delta z
   
   
for( trit * t = mesh; t != NULL; t = t->next )
   
drawTritColor(
   
t->p1x, t->p1y,
   
t->p2x, t->p2y,
   
t->p3x, t->p3y,
   
t->r, t->g, t->b, t->a
         );
   
}

tritEngine::tritEngine()
{
   
models = NULL;
   
cam = new camera( 480, 720 );
}

tritEngine::~tritEngine()
{
}

void tritEngine::addModel( model * m )
{
   
if( models != NULL )
       
 m->next = models;
   
   
models = m;
}

void tritEngine::calculate()
{
   
for( model * m = models; m != NULL; m = m->next )
   
{
       
m->anglez += m->rotz; if( m->anglez >= 360 ) m->anglez = int( m->anglez ) % 360;
       
       
m->angley += m->roty; if( m->angley >= 360 ) m->angley = int( m->angley ) % 360;
       
       
m->anglex += m->rotx; if( m->anglex >= 360 ) m->anglex = int( m->anglex ) % 360;
       
       
m->calculate();
   
}
}


void tritEngine::sortModels()
{
   
// TO-DO
}

void tritEngine::render()
{
   
for( model * m = models; m != NULL; m = m->next )
       
 m->render();
   
}

SDL_Window * window;
bool programRun;
float screenWidth, screenHeight;

void initSDL()
{
   
//program graphics init
   
SDL_Init( SDL_INIT_EVERYTHING );
   
// We use OpenGL ES 2.0
   
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
   
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 0 );
   
   
// We want at least 8 bits per color, alpha and depth
   
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
   
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
   
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
   
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
   
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 8 );
   
   
// get current display settings
   
SDL_DisplayMode DM;
   
SDL_GetCurrentDisplayMode( 0, & DM );
   
   
window = SDL_CreateWindow(
   
"tritEngine",
   
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
   
int( DM.w ), int( DM.h ),
   
SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN );
   
   
// and now can use OpenGles 2.0 !! :D
   
SDL_GL_CreateContext( window );
   
   
// for the transparency in shaders
   
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
}

void initProgram()
{
   
SDL_DisplayMode DM;
   
SDL_GetCurrentDisplayMode( 0, & DM );
   
   
screenWidth = int( DM.w );
   
screenHeight = int( DM.h );
   
   
programRun = true;
}

void drawBackground()
{
   
glClearColor( 0.125f, 0.125f, 0.125f, 1.0f );
   
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}

void createStandardCube( tritEngine * engine, float x, float y, float z, float side, float az = 0, float ay = 0, float ax = 0, float rz = 0, float ry = 0, float rx = 0 )
{
   
model * cube;
   
trit * t1, * t2, * t3, * t4, * t5, * t6, * t7, * t8, * t9, * t10, * t11, * t12;
   
// TO-DO ( troche mi osie pozmienial, ale co mi tam - piszemy dalej )
    // create triangles
   
t1 = new trit( x - side, y - side, z - side, x - side, y + side, z - side, x + side, y + side, z - side, 128, 48, 48, 256 );
   
t2 = new trit( x - side, y - side, z - side, x + side, y - side, z - side, x + side, y + side, z - side, 128, 48, 48, 256 );
   
t3 = new trit( x - side, y - side, z + side, x - side, y + side, z + side, x + side, y + side, z + side, 128, 48, 48, 256 );
   
t4 = new trit( x - side, y - side, z + side, x + side, y - side, z + side, x + side, y + side, z + side, 128, 48, 48, 256 );
   
t5 = new trit( x - side, y - side, z - side, x - side, y + side, z - side, x - side, y + side, z + side, 48, 128, 48, 256 );
   
t6 = new trit( x - side, y - side, z - side, x - side, y - side, z + side, x - side, y + side, z + side, 48, 128, 48, 256 );
   
t7 = new trit( x + side, y - side, z - side, x + side, y + side, z - side, x + side, y + side, z + side, 48, 128, 48, 256 );
   
t8 = new trit( x + side, y - side, z - side, x + side, y - side, z + side, x + side, y + side, z + side, 48, 128, 48, 256 );
   
t9 = new trit( x - side, y + side, z - side, x - side, y + side, z + side, x + side, y + side, z + side, 48, 48, 128, 256 );
   
t10 = new trit( x - side, y + side, z - side, x + side, y + side, z - side, x + side, y + side, z + side, 48, 48, 128, 256 );
   
t11 = new trit( x - side, y - side, z - side, x - side, y - side, z + side, x + side, y - side, z + side, 48, 48, 128, 256 );
   
t12 = new trit( x - side, y - side, z - side, x + side, y - side, z - side, x + side, y - side, z + side, 48, 48, 128, 256 );
   
   
//create cube
   
cube = new model();
   
cube->setCenter( x, y, z );
   
cube->addTrit( t1 ); cube->addTrit( t2 ); // FRONT
   
cube->addTrit( t3 ); cube->addTrit( t4 ); // BACK
   
cube->addTrit( t5 ); cube->addTrit( t6 ); // LEFT
   
cube->addTrit( t7 ); cube->addTrit( t8 ); // RIGHT    
   
cube->addTrit( t9 ); cube->addTrit( t10 ); // TOP
   
cube->addTrit( t11 ); cube->addTrit( t12 ); // BOTTOM
   
   
cube->anglez = az;
   
cube->angley = ay;
   
cube->anglex = ax;
   
   
cube->rotz = rz;
   
cube->roty = ry;
   
cube->rotx = rx;
   
   
engine->addModel( cube );
}

int main()
{
   
// MAIN INITIALIZE (oh yeah)
   
initSDL();
   
initProgram();
   
setScreen( screenWidth, screenHeight );
   
initShader();
   
   
tritEngine * engine = new tritEngine();
   
   
createStandardCube(
   
engine,
   
0, 0, 0, 100, // xyz side
   
0, 0, 0, // angles zyx
   
1, 0, 0 // rotates zyx
   
);
   
   
testindex = 0;
   
   
while( programRun )
   
{
       
drawBackground();
       
engine->calculate();
       
engine->sortModels();
       
engine->render();
       
SDL_GL_SwapWindow( window );
   
};
}
P-180368
pekfos
» 2023-09-09 23:02:36
Zdecydowanie nie o to chodzi. Funkcjonalnie powinno to działać tak
C/C++
Point rotatex( Point point, Point origin, float angle ); // etc

r = v;
r = rotatex( r, c, anglex );
r = rotatey( r, c, angley );
r = rotatez( r, c, anglez );
Takie wejścia i takie wyjścia operacji. Jeśli nie możesz się połapać w swoich stu widocznych zmiennych, to masz odpowiedź dlaczego kod tak nie powinien wyglądać.
P-180369
1 2 3 4 « 5 » 6 7 8
Poprzednia strona Strona 5 z 8 Następna strona