16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-21 13:39:18 +02:00

merge2 (incomplete)

This commit is contained in:
VB
2017-06-20 23:05:07 +02:00
38 changed files with 3068 additions and 4144 deletions

283
Model3d.h
View File

@@ -7,8 +7,7 @@ obtain one at
http://mozilla.org/MPL/2.0/.
*/
#ifndef Model3dH
#define Model3dH
#pragma once
#include "GL/glew.h"
#include "Parser.h"
@@ -19,82 +18,6 @@ http://mozilla.org/MPL/2.0/.
using namespace Math3D;
struct GLVERTEX
{
vector3 Point;
vector3 Normal;
float tu, tv;
};
class TMaterialColor
{
public:
TMaterialColor() {};
TMaterialColor(char V)
{
r = g = b = V;
};
// TMaterialColor(double R, double G, double B)
TMaterialColor(char R, char G, char B)
{
r = R;
g = G;
b = B;
};
char r, g, b;
};
/*
struct TMaterial
{
int ID;
AnsiString Name;
//McZapkie-240702: lepiej uzywac wartosci float do opisu koloru bo funkcje opengl chyba tego na ogol
uzywaja
float Ambient[4];
float Diffuse[4];
float Specular[4];
float Transparency;
GLuint TextureID;
};
*/
/*
struct THitBoxContainer
{
TPlane Planes[6];
int Index;
inline void Reset() { Planes[0]= TPlane(vector3(0,0,0),0.0f); };
inline bool Inside(vector3 Point)
{
bool Hit= true;
if (Planes[0].Defined())
for (int i=0; i<6; i++)
{
if (Planes[i].GetSide(Point)>0)
{
Hit= false;
break;
};
}
else return(false);
return(Hit);
};
};
*/
/* Ra: tego nie będziemy już używać, bo można wycisnąć więcej
typedef enum
{smt_Unknown, //nieznany
smt_Mesh, //siatka
smt_Point,
smt_FreeSpotLight, //punkt świetlny
smt_Text, //generator tekstu
smt_Stars //wiele punktów świetlnych
} TSubModelType;
*/
// Ra: specjalne typy submodeli, poza tym GL_TRIANGLES itp.
const int TP_ROTATOR = 256;
const int TP_FREESPOTLIGHT = 257;
@@ -127,24 +50,24 @@ enum TAnimType // rodzaj animacji
at_Undefined = 0x800000FF // animacja chwilowo nieokreślona
};
class TModel3d;
class TSubModel
{ // klasa submodelu - pojedyncza siatka, punkt świetlny albo grupa punktów
//m7todo: zrobić normalną serializację
friend class opengl_renderer;
friend class TModel3d; // temporary workaround. TODO: clean up class content/hierarchy
private:
int iNext;
int iChild;
int eType; // Ra: modele binarne dają więcej możliwości niż mesh złożony z trójkątów
int iName; // numer łańcucha z nazwą submodelu, albo -1 gdy anonimowy
int iNext{ NULL };
int iChild{ NULL };
int eType{ TP_ROTATOR }; // Ra: modele binarne dają więcej możliwości niż mesh złożony z trójkątów
int iName{ -1 }; // numer łańcucha z nazwą submodelu, albo -1 gdy anonimowy
public: // chwilowo
TAnimType b_Anim;
TAnimType b_Anim{ at_None };
private:
int iFlags; // flagi informacyjne:
int iFlags{ 0x0200 }; // bit 9=1: submodel został utworzony a nie ustawiony na wczytany plik
// flagi informacyjne:
// bit 0: =1 faza rysowania zależy od wymiennej tekstury 0
// bit 1: =1 faza rysowania zależy od wymiennej tekstury 1
// bit 2: =1 faza rysowania zależy od wymiennej tekstury 2
@@ -159,94 +82,85 @@ private:
// bit 15: =1 wymagane przechowanie macierzy (transform niejedynkowy)
union
{ // transform, nie każdy submodel musi mieć
float4x4 *fMatrix; // pojedyncza precyzja wystarcza
// matrix4x4 *dMatrix; //do testu macierz podwójnej precyzji
float4x4 *fMatrix = nullptr; // pojedyncza precyzja wystarcza
int iMatrix; // w pliku binarnym jest numer matrycy
};
int iNumVerts; // ilość wierzchołków (1 dla FreeSpotLight)
int iNumVerts{ -1 }; // ilość wierzchołków (1 dla FreeSpotLight)
int tVboPtr; // początek na liście wierzchołków albo indeksów
int iTexture; // numer nazwy tekstury, -1 wymienna, 0 brak
float fVisible; // próg jasności światła do załączenia submodelu
float fLight; // próg jasności światła do zadziałania selfillum
float f4Ambient[4];
float f4Diffuse[4]; // float ze względu na glMaterialfv()
float f4Specular[4];
float f4Emision[4];
float fWireSize; // nie używane, ale wczytywane
float fSquareMaxDist;
float fSquareMinDist;
int iTexture{ 0 }; // numer nazwy tekstury, -1 wymienna, 0 brak
float fVisible{ 0.0f }; // próg jasności światła do załączenia submodelu
float fLight{ -1.0f }; // próg jasności światła do zadziałania selfillum
glm::vec4
f4Ambient{ 1.0f,1.0f,1.0f,1.0f },
f4Diffuse{ 1.0f,1.0f,1.0f,1.0f },
f4Specular{ 0.0f,0.0f,0.0f,1.0f },
f4Emision{ 1.0f,1.0f,1.0f,1.0f };
float fWireSize{ 0.0f }; // nie używane, ale wczytywane
float fSquareMaxDist{ 10000.0f * 10000.0f };
float fSquareMinDist{ 0.0f };
// McZapkie-050702: parametry dla swiatla:
float fNearAttenStart;
float fNearAttenEnd;
bool bUseNearAtten; // te 3 zmienne okreslaja rysowanie aureoli wokol zrodla swiatla
int iFarAttenDecay; // ta zmienna okresla typ zaniku natezenia swiatla (0:brak, 1,2: potega 1/R)
float fFarDecayRadius; // normalizacja j.w.
float fCosFalloffAngle; // cosinus kąta stożka pod którym widać światło
float fCosHotspotAngle; // cosinus kąta stożka pod którym widać aureolę i zwiększone natężenie światła
float fCosViewAngle; // cos kata pod jakim sie teraz patrzy
float fNearAttenStart{ 40.0f };
float fNearAttenEnd{ 80.0f };
bool bUseNearAtten{ false }; // te 3 zmienne okreslaja rysowanie aureoli wokol zrodla swiatla
int iFarAttenDecay{ 0 }; // ta zmienna okresla typ zaniku natezenia swiatla (0:brak, 1,2: potega 1/R)
float fFarDecayRadius{ 100.0f }; // normalizacja j.w.
float fCosFalloffAngle{ 0.5f }; // cosinus kąta stożka pod którym widać światło
float fCosHotspotAngle{ 0.3f }; // cosinus kąta stożka pod którym widać aureolę i zwiększone natężenie światła
float fCosViewAngle{ 0.0f }; // cos kata pod jakim sie teraz patrzy
TSubModel *Next;
TSubModel *Child;
TSubModel *Next{ nullptr };
TSubModel *Child{ nullptr };
/*
intptr_t iVboPtr;
texture_manager::size_type TextureID; // numer tekstury, -1 wymienna, 0 brak
bool bWire; // nie używane, ale wczytywane
// short TexAlpha; //Ra: nie używane już
*/
geometry_handle m_geometry{ NULL, NULL }; // geometry of the submodel
texture_handle TextureID{ NULL }; // numer tekstury, -1 wymienna, 0 brak
bool bWire{ false }; // nie używane, ale wczytywane
/*
GLuint uiDisplayList; // roboczy numer listy wyświetlania
float Opacity; // nie używane, ale wczytywane //m7todo: wywalić to
// ABu: te same zmienne, ale zdublowane dla Render i RenderAlpha,
// bo sie chrzanilo przemieszczanie obiektow.
// Ra: już się nie chrzani
float f_Angle;
float3 v_RotateAxis;
float3 v_Angles;
*/
float Opacity{ 1.0f };
float f_Angle{ 0.0f };
float3 v_RotateAxis{ 0.0f, 0.0f, 0.0f };
float3 v_Angles { 0.0f, 0.0f, 0.0f };
public: // chwilowo
float3 v_TransVector;
float8 *Vertices; // roboczy wskaźnik - wczytanie T3D do VBO
size_t iAnimOwner; // roboczy numer egzemplarza, który ustawił animację
TAnimType b_aAnim; // kody animacji oddzielnie, bo zerowane
float3 v_TransVector{ 0.0f, 0.0f, 0.0f };
/*
basic_vertex *Vertices; // roboczy wskaźnik - wczytanie T3D do VBO
*/
vertex_array Vertices;
size_t iAnimOwner{ NULL }; // roboczy numer egzemplarza, który ustawił animację
TAnimType b_aAnim{ at_None }; // kody animacji oddzielnie, bo zerowane
public:
float4x4 *mAnimMatrix; // macierz do animacji kwaternionowych (należy do AnimContainer)
float4x4 *mAnimMatrix{ nullptr }; // macierz do animacji kwaternionowych (należy do AnimContainer)
public:
TSubModel **
smLetter; // wskaźnik na tablicę submdeli do generoania tekstu (docelowo zapisać do E3D)
TSubModel *Parent; // nadrzędny, np. do wymnażania macierzy
int iVisible; // roboczy stan widoczności
// AnsiString asTexture; //robocza nazwa tekstury do zapisania w pliku binarnym
// AnsiString asName; //robocza nazwa
TSubModel **smLetter{ nullptr }; // wskaźnik na tablicę submdeli do generoania tekstu (docelowo zapisać do E3D)
TSubModel *Parent{ nullptr }; // nadrzędny, np. do wymnażania macierzy
int iVisible{ 1 }; // roboczy stan widoczności
std::string pTexture; // robocza nazwa tekstury do zapisania w pliku binarnym
std::string pName; // robocza nazwa
private:
// int SeekFaceNormal(DWORD *Masks, int f,DWORD dwMask,vector3 *pt,GLVERTEX
// *Vertices);
int SeekFaceNormal(unsigned int *Masks, int f, unsigned int dwMask, float3 *pt, float8 *Vertices);
int SeekFaceNormal( std::vector<unsigned int> const &Masks, int const Startface, unsigned int const Mask, glm::vec3 const &Position, vertex_array const &Vertices );
void RaAnimation(glm::mat4 &m, TAnimType a);
public:
static size_t iInstance; // identyfikator egzemplarza, który aktualnie renderuje model
static texture_manager::size_type const *ReplacableSkinId;
static texture_handle const *ReplacableSkinId;
static int iAlpha; // maska bitowa dla danego przebiegu
static double fSquareDist;
static TModel3d *pRoot;
static std::string *pasText; // tekst dla wyświetlacza (!!!! do przemyślenia)
TSubModel();
~TSubModel();
void FirstInit();
int Load(cParser &Parser, TModel3d *Model, int Pos, bool dynamic);
int Load(cParser &Parser, TModel3d *Model, /*int Pos,*/ bool dynamic);
void ChildAdd(TSubModel *SubModel);
void NextAdd(TSubModel *SubModel);
TSubModel * NextGet()
{
return Next;
};
TSubModel * ChildGet()
{
return Child;
};
int TriangleAdd(TModel3d *m, texture_manager::size_type tex, int tri);
float8 * TrianglePtr(int tex, int pos, int *la, int *ld, int *ls);
// float8* TrianglePtr(const char *tex,int tri);
// void SetRotate(vector3 vNewRotateAxis,float fNewAngle);
TSubModel * NextGet() { return Next; };
TSubModel * ChildGet() { return Child; };
int TriangleAdd(TModel3d *m, texture_handle tex, int tri);
/*
basic_vertex * TrianglePtr(int tex, int pos, glm::vec3 const &Ambient, glm::vec3 const &Diffuse, glm::vec3 const &Specular );
*/
void SetRotate(float3 vNewRotateAxis, float fNewAngle);
void SetRotateXYZ(vector3 vNewAngles);
void SetRotateXYZ(float3 vNewAngles);
@@ -255,18 +169,10 @@ public:
void SetRotateIK1(float3 vNewAngles);
TSubModel * GetFromName(std::string const &search, bool i = true);
TSubModel * GetFromName(char const *search, bool i = true);
// inline matrix4x4* GetMatrix() {return dMatrix;};
inline float4x4 * GetMatrix()
{
return fMatrix;
};
// matrix4x4* GetTransform() {return Matrix;};
inline void Hide()
{
iVisible = 0;
};
void RaArrayFill(CVertNormTex *Vert);
// void Render();
inline float4x4 * GetMatrix() { return fMatrix; };
inline void Hide() { iVisible = 0; };
void create_geometry( std::size_t &Dataoffset, geometrybank_handle const &Bank );
int FlagsCheck();
void WillBeAnimated()
{
@@ -274,26 +180,18 @@ public:
iFlags |= 0x4000;
};
void InitialRotate(bool doit);
void DisplayLists();
void BinInit(TSubModel *s, float4x4 *m, float8 *v,
std::vector<std::string> *t, std::vector<std::string> *n, bool dynamic);
void ReplacableSet(texture_manager::size_type const *r, int a)
void BinInit(TSubModel *s, float4x4 *m, std::vector<std::string> *t, std::vector<std::string> *n, bool dynamic);
void ReplacableSet(texture_handle const *r, int a)
{
ReplacableSkinId = r;
iAlpha = a;
};
void TextureNameSet(const char *n);
void NameSet(const char *n);
void TextureNameSet( std::string const &Name );
void NameSet( std::string const &Name );
// Ra: funkcje do budowania terenu z E3D
int Flags()
{
return iFlags;
};
void UnFlagNext()
{
iFlags &= 0x00FFFFFF;
};
void ColorsSet(int *a, int *d, int *s);
int Flags() { return iFlags; };
void UnFlagNext() { iFlags &= 0x00FFFFFF; };
void ColorsSet( glm::vec3 const &Ambient, glm::vec3 const &Diffuse, glm::vec3 const &Specular );
inline float3 Translation1Get()
{
return fMatrix ? *(fMatrix->TranslationGet()) + v_TransVector : v_TransVector;
@@ -307,15 +205,17 @@ public:
return TextureID;
}
void ParentMatrix(float4x4 *m);
float MaxY(const float4x4 &m);
float MaxY( float4x4 const &m );
void AdjustDist();
void deserialize(std::istream&);
void TSubModel::serialize(std::ostream&,
void serialize(std::ostream&,
std::vector<TSubModel*>&,
std::vector<std::string>&,
std::vector<std::string>&,
std::vector<float4x4>&);
void serialize_geometry( std::ostream &Output );
};
class TModel3d : public CMesh
@@ -323,9 +223,6 @@ class TModel3d : public CMesh
friend class opengl_renderer;
private:
// TMaterial *Materials;
// int MaterialsCount; //Ra: nie używane
// bool TractionPart; //Ra: nie używane
TSubModel *Root; // drzewo submodeli
int iFlags; // Ra: czy submodele mają przezroczyste tekstury
public: // Ra: tymczasowo
@@ -338,39 +235,23 @@ private:
std::string asBinary; // nazwa pod którą zapisać model binarny
std::string m_filename;
public:
inline TSubModel * GetSMRoot()
{
return (Root);
};
// double Radius; //Ra: nie używane
inline TSubModel * GetSMRoot() { return (Root); };
TModel3d();
TModel3d(char *FileName);
~TModel3d();
TSubModel * GetFromName(const char *sName);
// TMaterial* GetMaterialFromName(char *sName);
TSubModel * AddToNamed(const char *Name, TSubModel *SubModel);
void AddTo(TSubModel *tmp, TSubModel *SubModel);
void LoadFromTextFile(std::string const &FileName, bool dynamic);
void LoadFromBinFile(std::string const &FileName, bool dynamic);
bool LoadFromFile(std::string const &FileName, bool dynamic);
void SaveToBinFile(char const *FileName);
void SaveToBinFile(std::string const &FileName);
void BreakHierarhy();
// inline int GetSubModelsCount() { return (SubModelsCount); };
int Flags() const
{
return iFlags;
};
int Flags() const { return iFlags; };
void Init();
std::string NameGet()
{
// return Root ? Root->pName : NULL;
return m_filename;
};
std::string NameGet() { return m_filename; };
int TerrainCount();
TSubModel * TerrainSquare(int n);
void TerrainRenderVBO(int n);
void deserialize(std::istream &s, size_t size, bool dynamic);
};
//---------------------------------------------------------------------------
#endif