"Einfacher" Viewer in OpenGL mit QT C++

xxcuratorxx

Grünschnabel
Hallo liebe Gemeinde,

ich beschäftige mich gerade mit der GUI Programmierung mit C++ und qt4.

Hab ein kleines Tool, was ein 2D Geometrie anzeigt mit Qpainter.

Ich will jetzt qut qt umsteigen.

Das eigentliche Plotten glCube etc. ist auch nicht das Problem, ich verstehe das mit den Matrixen Projektionen etc leider nicht.

Grundlage ist folgendes.

Ich habe eine "Bild" was durch zwei Punkte unten links und oben rechts [x_min, y_min] [x_max y_max] begrenz ist. Darin sind Dreiecke und würfel kreise etc.

Dann hab ich ein fenster mit den abmessungen w x h.

So ich ich OpenGL verstanden habe, müsste ich jetzt die Grafik beispielsweise 1:1 malen können [z.B. im Bereich [-100 -100] [-10 -20]. Und dann mit den Projektionsmatrixen einstellen, "welchen Teil davon er wie skaliert" aus gibt.

Beginnen soll Bild mittig das Fenster ausfüllend ("letterbox") und dann mit Pfeiltasten bewegbar und skalierbar sein. Man denke an einen Browserroutenplaner.

Ich suche mich zum armen Mann, und werde leider nicht fündig.

Bin für jeden Tipp dankbar.

Zu implementieren wären die funktionen "plot" und "ändere position(bewegung, skalierung)"

Gruß
Alex
 
Ich habe eine "Bild" was durch zwei Punkte unten links und oben rechts [x_min, y_min] [x_max y_max] begrenz ist. Darin sind Dreiecke und würfel kreise etc.

Dann hab ich ein fenster mit den abmessungen w x h.

So ich ich OpenGL verstanden habe, müsste ich jetzt die Grafik beispielsweise 1:1 malen können [z.B. im Bereich [-100 -100] [-10 -20]. Und dann mit den Projektionsmatrixen einstellen, "welchen Teil davon er wie skaliert" aus gibt.
Irgendwie verstehe ich dich nicht. Ansonten könnte ich dir helfen.
Bild? Sind die dreiecke würfel im Bild dargestellt? das du lädst? Oder meinst du mit "Bild" die Scene die du renderst?
Inwiefern Grafik? Du lädst also ein Bild hast welche du als Texure speicherst?
Und als nächste ordnest du diese einem Objekt zu auf welchem diese gezeichnet wird? wenn ja welchem oder möchtest du eine art Sprites verwenden? oder einfach nur auf verschieden Objekte die slebe Texture allerdings einen anderen Teil dieser?
 
Zunächst Vielen Dank das du mir helfen willst.

Ich gehe mal langsam durch. Also mit Minimum und Maximum meine ich die Begrenzungen der zu Rendernden Szene, also der Welt. Sagen vier die Welt bestehe aus vier Würfeln, bei mir als Quadrate zu sehen. Oben links, oben rechts, unten links und unten rechts. Diese sollen Einfarbig sein, keine Texturen.

Beispiel Cube1: [-2 -2] [-2 -1] [-1 -1] [-1 -2]
Cube2: [-2 2] [-1 2] [-1 1] [-1 2]
Cube3: [ 1 1] [ 1 2] [ 2 2] [ 2 1]
Cube4: [1 -1] [2 -1] [2 -2] [1 -2]
{jeweils von -delta_z bis +delta_z}
Damit ergibt sich min = -2, -2 und max = 2, 2

Habe ich nun ein Fenster von 40 x 40 pixeln soll der punkt es wie folgt dargestellt werden.

[-2 -2] --> [0,40]
[ 2 2] --> [40,0]

hab ich beispielweise ein fenster von 120 x 60
[-2 -2] --> [ 30, 60]
[ 2 2] --> [90, 0]

Das ist der start.

Wenn ich jetzt Pfeil Links drücke soll daraus werden:
[-2 -2] --> [-10,40]
[ 2 2] --> [ 30, 0]
bzw.
[-2 -2] --> [ 20, 60]
[ 2 2] --> [ 80, 0]

Bei Plus soll dann etwa folgendes passieren
[-2 -2] --> [-10,50]
[ 2 2] --> [ 50, -10]
bzw.
[-2 -2] --> [ 20, 70]
[ 2 2] --> [ 100, -10]

Will also die beiden Funktionen "male dasSzenario" und "zeige anderen Teil des Szenarios" seperat implementieren.

Also Beispiel Stelle man sich eine weltkarte vor, wo statt karte wild verteilt 15 dreiecke sind. Dann starte man damit n navi, das diese 15 dreicke darstellt. man kann nun z.b. dreieck 5 mit den pfeiltasten in die mitte veschieden und dieses dann herauszoomen.

Hoffe es ist etwas klarer, was ich meine.

Dankbar
 
Was du ja weißt nur nochmal für Leute die den Beitrag lesen:
In OpenGL ist es so das dich Kamera statisch ist und nicht bewegt werden kann, man muss also die Objekte bewegen. Bei DirectX ist dies nicht so. Dort hat mein eine bewegliche Kamera^.

So nun:
In dern Render funkion machst du folgendes:
C++:
glMultMatrixf(m_gViewMatrix.m_matrix);
// draw
Am Anfang erstellen:
C++:
CMatrix	m_gViewMatrix;
So nun würde ich mir eine OnKey Funktion schreiben:
C++:
void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	switch (nChar)
	{
		case VK_UP:
			            m_gViewMatrix.SetTranslation(CVector(m_gViewMatrix.m_matrix[12],                   m_gViewMatrix.m_matrix[13] + 1.0f,  m_gViewMatrix.m_matrix[14])); 
		break;

		case VK_DOWN:
			m_gViewMatrix.SetTranslation(CVector(m_gViewMatrix.m_matrix[12], m_gViewMatrix.m_matrix[13] - 1.0f,  m_gViewMatrix.m_matrix[14])); 
		break;

		case VK_LEFT:
			m_gViewMatrix.SetTranslation(CVector(m_gViewMatrix.m_matrix[12] - 1.0f, m_gViewMatrix.m_matrix[13],  m_gViewMatrix.m_matrix[14])); 
		break;

		case VK_RIGHT:
			m_gViewMatrix.SetTranslation(CVector(m_gViewMatrix.m_matrix[12] + 1.0f, m_gViewMatrix.m_matrix[13],  m_gViewMatrix.m_matrix[14])); 
		break;

		case VK_ADD:
			m_gViewMatrix.SetTranslation(CVector(m_gViewMatrix.m_matrix[12], m_gViewMatrix.m_matrix[13],  m_gViewMatrix.m_matrix[14] + 1.0f));
		break;
		case 187:	// + zoom in
			m_gViewMatrix.SetTranslation(CVector(m_gViewMatrix.m_matrix[12], m_gViewMatrix.m_matrix[13],  m_gViewMatrix.m_matrix[14] + 1.0f)); 
		break;
		
		case VK_SUBTRACT:
			m_gViewMatrix.SetTranslation(CVector(m_gViewMatrix.m_matrix[12], m_gViewMatrix.m_matrix[13],  m_gViewMatrix.m_matrix[14] - 1.0f)); 
		break;
		case 189:
			m_gViewMatrix.SetTranslation(CVector(m_gViewMatrix.m_matrix[12], m_gViewMatrix.m_matrix[13],  m_gViewMatrix.m_matrix[14] - 1.0f)); 
		break;
	}
  // hier deine Render-FUnkion aufrufe:n Render();
}
So das ist einfach mal rechts links oben unten und auf + und - zoom-in zoom-out.






C++:
class CMatrix;
class CVector;

/* --------------------------------- VECTOR CLASS ----------------------------------------//
//----------------------------------------------------------------------------------------*/

class CVector
{

public:
	union
	{
		struct
		{
			float x;
			float y;
			float z;
			float w;	// HOMOGENEOUS COORDINATE
		};
	float m_pos[4];
	};
		

	// Constructors
	CVector(float x=0, float y=0, float z=0, float w=1) : x(x), y(y), z(z), w(w) {  }
	CVector(const CVector &V) : x(V.x), y(V.y), z(V.z), w(V.w) { }
	const CVector& operator = (const CVector& V);
	const CVector& operator = (const float *d);
	//	Add & Substract, Positive & Negative
	const CVector operator + (const CVector& Vector) const;
	const CVector operator + () const;
	const CVector& operator += (const CVector& Vector);
	
	// minus vector 
	const CVector operator - (const CVector& Vector) const;
	const CVector operator - () const;
	const CVector &operator -= (const CVector& Vector);
	
	//	Multiply & Divide
	const CVector operator * (const CVector& Vector) const;
	const CVector& operator *= (const CVector& Vector);
	const CVector operator * (const float d) const;
	const CVector& operator *= (const float d);
	const CVector operator / (const CVector& Vector) const;
	const CVector &operator /= (const CVector& Vector);
	const CVector operator / (const float d) const;
	const CVector& operator /= (const float d);
	
	const float operator[]( int index ) const { return m_pos[index]; }

	const bool operator > (const CVector& Vector);
	const bool operator < (const CVector& Vector);
	//	Dot Product
	const float Dot (const CVector& Vector) const;
	//	Cross Product
	const CVector Cross(const CVector& Vector) const;
	
	void Transform(CMatrix *matrix);
	void Transform3(CMatrix *matrix);

	const float Magnitude() const;
	
	//	Set length (Normalize if 1) or Magnitude of vector
	void Normalize();
		
	const void SetNormal(CVector vTriangle0, CVector vTriangle1, CVector vTriangle2 );
	
	//	The angle between two vectors in radians
	const float Angle(const CVector& Normal) const;
	
	//	Reflect in Normal Vector
	const CVector Reflection(const CVector& PlaneNormal) const;

	//	Rotate dAngle Degrees (radians) Around Normal
	const CVector Rotate(const float dAngle, const CVector& Normal) const;
	
	// Plane Distance
	float PlaneDistance(CVector Normal, CVector Point);
	
	// Is Plane intersected?
	bool IntersectedPlane(CVector vTriangle[], CVector vLine[]);
};

/* --------------------------------- END VECTOR CLASS ------------------------------------//
//----------------------------------------------------------------------------------------*/

/* --------------------------------- MATRIX CLASS ----------------------------------------//
//----------------------------------------------------------------------------------------*/

class CMatrix
{
public:
	float m_matrix[16];	// matrix structure
	CVector m_rot;		// stored as degrees
	CVector m_pos;
	CVector m_scale;

	CMatrix(){Identity();}; // load identity when created
		
	__inline CMatrix& operator = (CMatrix& Matrix)	// copy matrix operator
	{
		for (int i=0; i<16; i++)
			m_matrix[i] = Matrix.m_matrix[i];
		
		m_rot = Matrix.m_rot;	m_pos = Matrix.m_pos;	m_scale = Matrix.m_scale;
		return *this;
	};
	float __inline operator[](int i) {	return m_matrix[i];  };	// similar to m_matrix[i], where m_matrix is CMatrix class

	void Multiply(CMatrix *matrix);	// multiply this matrix with pointed matrix
	void SetTranslation(CVector pos);	// translation property of matrix
	void SetInvTranslation(CVector pos);
	
	void __inline Scale(float x, float y, float z)	// scale property of matrix
	{
		m_matrix[0] = x;   
		m_matrix[5] = y;
		m_matrix[10] = z;  
		m_scale = CVector(x,y,z);
	};
	void __inline Identity()	// load identity
	{
		for (int i=0; i<16; i++)
			m_matrix[i] = 0.0;

		m_matrix[0] = m_matrix[5] = m_matrix[10] = m_matrix[15] = 1;

		m_rot = CVector(0,0,0);
		m_pos = CVector(0,0,0);
		m_scale = CVector(1,1,1);
		
	};
	// rotation operations
	void RotateDegrees(double dAngleX, double dAngleY, double dAngleZ);
	void RotateRadians(double dAngleX, double dAngleY, double dAngleZ);
	void RotateInvDegrees(double dAngleX, double dAngleY, double dAngleZ);
	void RotateInvRadians(double dAngleX, double dAngleY, double dAngleZ);

	void __inline InverseTranslateVect(float *pVect)
	{
		pVect[0] = pVect[0]-m_matrix[12];
		pVect[1] = pVect[1]-m_matrix[13];
		pVect[2] = pVect[2]-m_matrix[14];
	};

	void __inline InverseRotateVect(float *pVect)
	{
		float vec[3];

		vec[0] = pVect[0]*m_matrix[0]+pVect[1]*m_matrix[1]+pVect[2]*m_matrix[2];
		vec[1] = pVect[0]*m_matrix[4]+pVect[1]*m_matrix[5]+pVect[2]*m_matrix[6];
		vec[2] = pVect[0]*m_matrix[8]+pVect[1]*m_matrix[9]+pVect[2]*m_matrix[10];

		for (int i=0; i<3; i++)
			pVect[i] = vec[i];
	};
};

/* ---------------------------------END MATRIX CLASS -------------------------------------//
//----------------------------------------------------------------------------------------*/


// falls du das ganze speichern willst^^
bool SaveMatrix(CMatrix *tmp, char *filename, FILE *file = NULL);
bool LoadMatrix(CMatrix *tmp, char *filename, FILE *file = NULL);
C++:
/* --------------------------------- VECTOR IMPLEMENTATION -------------------------------//
//----------------------------------------------------------------------------------------*/
const CVector& CVector::operator = (const CVector& V)
{
	x = V.x;
	y = V.y;
	z = V.z;
		
	return *this;
}

const CVector& CVector::operator = (const float * d)
{
	x = d[0];
	y = d[1];
	z = d[2];
		
	return *this;
}

void CVector::Transform(CMatrix *m)
{
	double vector[4];
	const float *matrix = m->m_matrix;

	vector[0] = m_pos[0]*matrix[0]+m_pos[1]*matrix[4]+m_pos[2]*matrix[8]+matrix[12];
	vector[1] = m_pos[0]*matrix[1]+m_pos[1]*matrix[5]+m_pos[2]*matrix[9]+matrix[13];
	vector[2] = m_pos[0]*matrix[2]+m_pos[1]*matrix[6]+m_pos[2]*matrix[10]+matrix[14];
	vector[3] = m_pos[0]*matrix[3]+m_pos[1]*matrix[7]+m_pos[2]*matrix[11]+matrix[15];

	m_pos[0] = ( float )( vector[0] );
	m_pos[1] = ( float )( vector[1] );
	m_pos[2] = ( float )( vector[2] );
	m_pos[3] = ( float )( vector[3] );
}

void CVector::Transform3(CMatrix *m)
{
	double vector[3];
	const float *matrix = m->m_matrix;

	vector[0] = m_pos[0]*matrix[0]+m_pos[1]*matrix[4]+m_pos[2]*matrix[8];
	vector[1] = m_pos[0]*matrix[1]+m_pos[1]*matrix[5]+m_pos[2]*matrix[9];
	vector[2] = m_pos[0]*matrix[2]+m_pos[1]*matrix[6]+m_pos[2]*matrix[10];

	m_pos[0] = ( float )( vector[0] );
	m_pos[1] = ( float )( vector[1] );
	m_pos[2] = ( float )( vector[2] );
	m_pos[3] = 1;
}

	//	Add & Substract, Positive & Negative
	const CVector CVector::operator + (const CVector& Vector) const
	{	return CVector(x + Vector.x, y + Vector.y, z + Vector.z);
	}
	const CVector CVector::operator + () const
	{	return CVector(*this);
	}
	const CVector& CVector::operator += (const CVector& Vector)
	{	x += Vector.x;
		y += Vector.y;
		z += Vector.z;
		
		return *this;
	}
	// minus vector 
	const CVector CVector::operator - (const CVector& Vector) const
	{	return CVector(x - Vector.x, y - Vector.y, z - Vector.z);
	}
	const CVector CVector::operator - () const
	{	return CVector(-x, -y, -z);
	}
	const CVector &CVector::operator -= (const CVector& Vector)
	{	x -= Vector.x;
		y -= Vector.y;
		z -= Vector.z;
		
		return *this;
	}

	//	Multiply & Divide
	const CVector CVector::operator * (const CVector& Vector) const
	{	return CVector(x * Vector.x, y * Vector.y, z * Vector.z);
	}
	const CVector &CVector::operator *= (const CVector& Vector)
	{	x *= Vector.x;
		y *= Vector.y;
		z *= Vector.z;
		
		return *this;
	}
	const CVector CVector::operator * (const float d) const
	{	return CVector(x * d, y * d, z * d);
	}
	const CVector &CVector::operator *= (const float d)
	{	x *= d;
		y *= d;
		z *= d;
		
		return *this;
	}
	const CVector CVector::operator / (const CVector& Vector) const
	{	return CVector(x / Vector.x, y / Vector.y, z / Vector.z);
	}
	
	const CVector &CVector::operator /= (const CVector& Vector)
	{	x /= Vector.x;
		y /= Vector.y;
		z /= Vector.z;
		
		return *this;
	}
	const CVector CVector::operator / (const float d) const
	{	const float _d = 1.0f / d;
		return CVector(x * _d, y * _d, z * _d);
	}
	const CVector &CVector::operator /= (const float d)
	{	const float _d = 1.0f / d;
		x *= _d;
		y *= _d;
		z *= _d;
		
		return *this;
	}
	
	//	Dot Product
	const float CVector::Dot(const CVector& Vector) const
	{	return x*Vector.x + y*Vector.y + z*Vector.z;
	}
	//	Cross Product
	const  CVector CVector::Cross(const CVector& Vector) const
	{	return CVector(
				y * Vector.z - Vector.y * z,
				z * Vector.x - Vector.z * x,
				x * Vector.y - Vector.x * y);
	}
	
	const bool CVector::operator > (const CVector& v)
	{
		return (x>v.x && y>v.y && z>v.z);
	}
	
	const bool CVector::operator < (const CVector& v)
	{
		return (x<v.x && y<v.y && z<v.z);
	}

	
	const float CVector::Magnitude() const
	{	return sqrtf(x*x + y*y + z*z);
	}
		
	//	Set length (Normalize if 1) or Magnitude of vector
	void CVector::Normalize()
	{
		float magnitude=this->Magnitude();
		*this/=magnitude;
	}


	const void CVector::SetNormal(CVector vTriangle0, CVector vTriangle1, CVector vTriangle2 )
	{
		*this = CVector((vTriangle2-vTriangle0)).Cross(vTriangle1-vTriangle0);				// Cross Product
		this->Normalize();						// Use our function we created to normalize the normal (Makes it a length of one)
	}

	//	The angle between two vectors in radians
	const float CVector::Angle(const CVector& Normal) const
	{	return acosf((*this).Dot(Normal));
	}
	//	Reflect in Normal Vector
	const CVector CVector::Reflection(const CVector& PlaneNormal) const
	{	return (*this - PlaneNormal * 2.0 * ((*this).Dot(PlaneNormal))) * (*this).Magnitude();
	}
	//	Rotate dAngle Degrees (radians) Around Normal
	const CVector CVector::Rotate(const float dAngle, const CVector& Normal) const
	{	const float dCos = cosf(dAngle);
		const float dSin = sinf(dAngle);
		return CVector(
				*this * dCos +
				((Normal * *this) * (1.0f - dCos)) * Normal +
				((*this).Dot(Normal)) * dSin);
	}


/* -------------------------------END VECTOR IMPLEMENTATION ------------------------------//
//----------------------------------------------------------------------------------------*/

/* --------------------------------- MATRIX IMPLEMENTATION -------------------------------//
//----------------------------------------------------------------------------------------*/

//---------------------------------------------------------------------------
//	MATRIX MULTIPLICATION OPERATORS
//---------------------------------------------------------------------------
void CMatrix::Multiply (CMatrix *matrix)
{
	float newMatrix[16];
	const float *m1 = m_matrix, *m2 = matrix->m_matrix;

	newMatrix[0] = m1[0]*m2[0] + m1[4]*m2[1] + m1[8]*m2[2];
	newMatrix[1] = m1[1]*m2[0] + m1[5]*m2[1] + m1[9]*m2[2];
	newMatrix[2] = m1[2]*m2[0] + m1[6]*m2[1] + m1[10]*m2[2];
	newMatrix[3] = 0;

	newMatrix[4] = m1[0]*m2[4] + m1[4]*m2[5] + m1[8]*m2[6];
	newMatrix[5] = m1[1]*m2[4] + m1[5]*m2[5] + m1[9]*m2[6];
	newMatrix[6] = m1[2]*m2[4] + m1[6]*m2[5] + m1[10]*m2[6];
	newMatrix[7] = 0;

	newMatrix[8] = m1[0]*m2[8] + m1[4]*m2[9] + m1[8]*m2[10];
	newMatrix[9] = m1[1]*m2[8] + m1[5]*m2[9] + m1[9]*m2[10];
	newMatrix[10] = m1[2]*m2[8] + m1[6]*m2[9] + m1[10]*m2[10];
	newMatrix[11] = 0;

	newMatrix[12] = m1[0]*m2[12] + m1[4]*m2[13] + m1[8]*m2[14] + m1[12];
	newMatrix[13] = m1[1]*m2[12] + m1[5]*m2[13] + m1[9]*m2[14] + m1[13];
	newMatrix[14] = m1[2]*m2[12] + m1[6]*m2[13] + m1[10]*m2[14] + m1[14];
	newMatrix[15] = 1;

	for (int i=0; i<16; i++)
		this->m_matrix[i] = newMatrix[i];
}


void CMatrix::SetTranslation(CVector pos)
{
	m_matrix[12] = pos.x;
	m_matrix[13] = pos.y;
	m_matrix[14] = pos.z;
	m_pos = pos;
}

void CMatrix::SetInvTranslation(CVector pos)
{
	m_matrix[12] = -pos.x;
	m_matrix[13] = -pos.y;
	m_matrix[14] = -pos.z;
	m_pos = pos;
}
	
void CMatrix::RotateDegrees(double dAngleX, double dAngleY, double dAngleZ)
{
	// 1 radian = 180 degrees/PI;
	float vec[3] = {0,0,0};

	vec[0] = ( float )( dAngleX*PI/180 );
	vec[1] = ( float )( dAngleY*PI/180 );
	vec[2] = ( float )( dAngleZ*PI/180 );

	RotateRadians( vec[0], vec[1], vec[2] );
}

void CMatrix::RotateInvDegrees(double dAngleX, double dAngleY, double dAngleZ)
{
	float vec[3];

	vec[0] = ( float )( dAngleX*PI/180 );
	vec[1] = ( float )( dAngleY*PI/180 );
	vec[2] = ( float )( dAngleZ*PI/180 );

	RotateInvRadians( vec[0], vec[1], vec[2] );
}


void CMatrix::RotateRadians(double dAngleX, double dAngleY, double dAngleZ)
{
	m_rot = CVector(dAngleX*180/PI, dAngleY*180/PI, dAngleZ*180/PI);

	double cr = FastCos1( dAngleX );
	double sr = FastSin1( dAngleX );
	double cp = FastCos1( dAngleY );
	double sp = FastSin1( dAngleY );
	double cy = FastCos1( dAngleZ );
	double sy = FastSin1( dAngleZ );

	m_matrix[0] = ( float )( cp*cy );
	m_matrix[1] = ( float )( cp*sy );
	m_matrix[2] = ( float )( -sp );

	double srsp = sr*sp;
	double crsp = cr*sp;

	m_matrix[4] = ( float )( srsp*cy-cr*sy );
	m_matrix[5] = ( float )( srsp*sy+cr*cy );
	m_matrix[6] = ( float )( sr*cp );

	m_matrix[8] = ( float )( crsp*cy+sr*sy );
	m_matrix[9] = ( float )( crsp*sy-sr*cy );
	m_matrix[10] = ( float )( cr*cp );
}


void CMatrix::RotateInvRadians(double dAngleX, double dAngleY, double dAngleZ)
{
	m_rot = CVector(dAngleX*180/PI, dAngleY*180/PI, dAngleZ*180/PI);

	double cr = cos( dAngleX );
	double sr = sin( dAngleX );
	double cp = cos( dAngleY );
	double sp = sin( dAngleY );
	double cy = cos( dAngleZ );
	double sy = sin( dAngleZ );

	// matrix0 = cos(y)*cos(z)
	//y = inv_cos(matrix0/cos(z))
	m_matrix[0] = ( float )( cp*cy );
	m_matrix[4] = ( float )( cp*sy );
	m_matrix[8] = ( float )( -sp );

	double srsp = sr*sp;
	double crsp = cr*sp;

	m_matrix[1] = ( float )( srsp*cy-cr*sy );
	m_matrix[5] = ( float )( srsp*sy+cr*cy );
	m_matrix[9] = ( float )( sr*cp );

	m_matrix[2] = ( float )( crsp*cy+sr*sy );
	m_matrix[6] = ( float )( crsp*sy-sr*cy );
	m_matrix[10] = ( float )( cr*cp );
}

//---------------------------------------------------------------------------

/* -------------------------------END MATRIX IMPLEMENTATION ------------------------------//
//----------------------------------------------------------------------------------------*/

bool SaveMatrix(CMatrix *mat, char *filename, FILE *f)
{
	if(mat == NULL)
		return false;

	FILE *file = NULL;
	
	if(f == NULL)
	{
		if(filename == NULL)
			return false;
		else
			file = fopen(filename,"w+t");
	}
	else
		file = f;
	
	if(file !=NULL)
	{
		fprintf(file, "%f %f %f %f %f %f %f %f %f\n", 
						mat->m_pos.x, mat->m_pos.y, mat->m_pos.z,
						mat->m_rot.x, mat->m_rot.y, mat->m_rot.z,
						mat->m_scale.x, mat->m_scale.y, mat->m_scale.z);
	}
	
	if(f == NULL)
		fclose(file);

	return true;
}


bool LoadMatrix(CMatrix *mat, char *filename, FILE *f)
{

	if(mat == NULL)
		return false;

	FILE *file = NULL;
	
	if(f == NULL)
	{
		if(filename == NULL)
			return false;
		else
			file = fopen(filename,"r+t");
	}
	else
		file = f;
	
	if(file !=NULL)
	{
		fscanf(file, "%f %f %f %f %f %f %f %f %f\n", 
						&mat->m_pos.x, &mat->m_pos.y, &mat->m_pos.z,
						&mat->m_rot.x, &mat->m_rot.y, &mat->m_rot.z,
						&mat->m_scale.x, &mat->m_scale.y, &mat->m_scale.z);

		mat->SetTranslation(mat->m_pos);
		mat->RotateDegrees(mat->m_rot.x, mat->m_rot.y, mat->m_rot.z);
		mat->Scale(mat->m_scale.x, mat->m_scale.y, mat->m_scale.z);

		//fgetc(file);	// SKIP NEWLINE
	}

	if(f == NULL)
		fclose(file);

	return true;
}

Sag falls ich was vergessen habe oder du etwas nicht verstehst
 
Zuletzt bearbeitet von einem Moderator:
Das klingt doch mal verständlich.

Ich definiere mir als meine Matrix (mache das per Mausauslesen und Versatz, aber das ja egal) und plotte dann. Nac hjedem Tastendruck mach ich repaint und gut ist.

Ich will ne Legende Machen, die ich aber links mache, dazu habe ich vor dieser Matrixenmultikpliationssache gearbeitet.

So weit geht das also alles.

Nun will ich auch Strahlen darstellen, dass können paar 1000 sein --> sehr viele.

Prinzip das gleiche, funktioniert auch, aber leider ruckelt es. Ist ja auch klar, bei jeder mausbewegung mit gedrückter taste zeichnet der irrsinnig viele Strahlen (glBegin(GL_LINES)) neu.

Nun die letzte Frage dazu. Dann ich dieses repainten verhindern, also praktisch das vorhandene Bild nehmen, verschieben und darstellen, ohne alles neu zuzeichnen.
Klar muss auf dem bildschirm im worst case jedes Pixel geändert werden, aber halt nur durch das "daneben" ersetzt werden.

Die Legende soll jedoch ortsfest sein.

zZ.
Code:
paintGL()
{
        glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,this->width(),this->height(),0,-1,m_zMax);

        //Legende malen

        // Jetzt machen wir machen die neue Matrix
       glLoadIdentity();
	glOrtho(-this->width()/2,this->width()/2,-this->height()/2,this->height()/2,-1,m_zMax);

        //Translation
	glTranslatef(m_Translation);
	
        //Skalierung
	glScalef(m_Scale,m_Scale,m_Scale);

        //Verschiebung auf den Mittelpunkt (damit wird um die mitte der Geometry skaliert)         glTranslatef(-Mittelpunkt der Grafik);

       for (i=1;i<100000000;++i)
                //male Strahl
}

Bei Key oder Mausevents werden immer m_Scale und m_Translation auf den neuesten Stand gebracht, dann repaint

Ziel:
Update bei umskalierung bzw. bewegung ohne alles neu zu zeichnen
 
Was benutzt du den für ein Buffering System?
Ach und ab welcher Maus-Bewegung wird denn bei dir neu gezeichnet?
Darüber würde ich das ganze regeln. Wenn du die Maus nur ein mm bewegst würde ich noch nicht neu zeichnen.
 
Hi, welches Buffering System gute Frage. Das was bei qt dabei ist *fragend_guck*

http://doc.troll.no/qtjambi-4.3.5_01/com/trolltech/qt/opengl/QGLWidget.html

Da steht was von double Buffering, das nutze ich aber nicht explizit.

Aber zZ kann es passieren, dass ein repaint event sogar 3 sekunden oder so dauert.

Man soll das ja mit der Maus ziehen können, bei mehr als 3 sekunden kann man da ja wohl nix machen mit nem schwellwert x_min meiner Meinung.

Man müsste die komplette Szene irgendwie in einen hintergrundbuffer schieben (alle Strahlen). Beim repaint event dann nur den buffer nehmen, verschieben und die legende dazu malen.

Bei QT mit QPainter könnte das vielleicht damit zu lösen sein, dass man die Strahlen auf ein Bitmap malt, und dieses das bei repaint ändert. Geht sowas auch in qglwidget? Spricht mit opengl?
 
Code:
Member Type Documentation
QGL::FormatOption

This enum specifies the format options.

    * QGL::DoubleBuffer
    * QGL::DepthBuffer
    * QGL::Rgba
    * QGL::AlphaChannel
    * QGL::AccumBuffer
    * QGL::StencilBuffer
    * QGL::StereoBuffers
    * QGL::DirectRendering
    * QGL::HasOverlay
    * QGL::SingleBuffer
    * QGL::NoDepthBuffer
    * QGL::ColorIndex
    * QGL::NoAlphaChannel
    * QGL::NoAccumBuffer
    * QGL::NoStencilBuffer
    * QGL::NoStereoBuffers
    * QGL::IndirectRendering
    * QGL::NoOverlay
EDIT:schön das aus dem ":"+"D" n smiley wurde^^

Nichts explizit gewählt? Wäre vielleicht mal eine maßnahme. Habe selber noch nie mit QGL gearbeitet.
 
Zuletzt bearbeitet:
Zurück