Brauche dringend hilfe (Vererbung)



  • Also ich habe c++ schon mal gelernt jedoch habe ich das wesentliche vergessen. ich habe hier eine aufgabe die eigentlich ganz einfach sein muss.

    Erzeugen Sie eine neue Klasse fwAutorot, die Sie von fwRotation erben lassen. Somit erbt die neue Klasse die vier Attribute _xa, _ya, _za und _theta, sowie die Render-Methode. Fügen Sie dieser Klasse ein fünftes Attribut vom Typ float hinzu, dass die Winkelgeschwindigkeit enthält, mit der sich um die Rotationsachse gedreht werden soll. Das Attribut _theta soll nun nicht mehr im
    Konstruktor als Parameter mit übergegen werden, stattdessen soll der neu zu
    implementierende Konstruktor von fwAutorot neben der Drehachse die Winkelgeschwindigkeit als Parameter übernemen und das neue, fünfte Attribut damit initialisieren. Das Attribut _theta soll mit 0 initialisiert werden. Ändern Sie die Render-Mehode von fwAutorot so, dass dort zunächst _theta in Abhängigkeit der
    Winkelgeschwindigkeit neu gesetzt wird und dann mit dem dann aktuellen Wert _theta die Rotationsmatrix gesetzt wird.

    class fwRotation : public fwNode
    {
    public:
    	fwRotation(float xa, float ya, float za, float theta);
    	virtual ~fwRotation();
    
    	void SetRotation(float xa, float ya, float za, float theta);
    	virtual bool Render();
    
    	float _xa;
    	float _ya;
    	float _za;
    	float _theta;
    };
    
    //Def. von fwRotation
    fwRotation::fwRotation(float xa,float ya,float za,float theta)
    {
    	SetRotation(xa, ya, za, theta);
    }
    
    void fwRotation::SetRotation(float xa,float ya,float za,float theta)
    {
    	_xa=xa;
    	_ya=ya;
    	_za=za;
    	_theta=theta;
    }
    
    fwRotation::~fwRotation()
    {
    }
    
    bool fwRotation::Render()
    {
    	glRotatef(_theta, _xa, _ya, _za);
    	return true;
    }
    

    kann mir da irgendwer helfen, der grad zeit und lust hat. ich wäre sooo dankbar

    mladdi



  • Wohlwissend, dass ich grade Deine Hausaufgaben mache... und wohlwissend, dass mir auch keine passenden Begriffe für google einfallen, schreibe ich mal 'ne Antwort.

    1. Die Klassendefinition leitet sich von fwRotation ab und der Konstruktor benötigt theta nicht mehr als Übergabeparameter.

    class fwAutorot : public fwRotation
    {
      public:
        float _omega;
    
        fwAutorot( float xa, float ya, float za, float omega );
        bool Render();
    };
    
    fwAutorot::fwAutorot( float xa, float ya, float za, float omega )
      : fwRotation( xa, ya, za, 0 /* theta */ )  // Konstruktor der Basisklasse rufen
    {
      _omega : omega; 
    }
    
    bool fwAutorot::Render(void)
    {
      /* theta Umrechnen und eintragen */
    
      fwRotation::Render(); // überladene Basisfunktion rufen.
    }
    

    Theta darfst dann noch selber berechnen.


Anmelden zum Antworten