50_Cal

Member
  • Content count

    7
  • Joined

  • Last visited

Community Reputation

116 Neutral

About 50_Cal

  • Rank
    Newbie
  1. Thanks man. The usage of const is a thing that should be considered and I missed it before For the last one, I just don't know why I did that yesterday. Just want to check if Customer is added?
  2. Is there a reply or @ function here?   Thanks for the advises, they are extremely helpful to me. One thing, imo, for the line 14-17. I thing it's fine to write a constructor in this way, it's just and other way to initial some member variables. It works on Visual Studio Thanks again, I'm going to redesign the thing 
  3. I recently finished some C++ practices from my teacher and he told me my answers got a classic issues. I'm pretty new and I really can't figure it out, so, give me a hand please. Thanks.   Here is the question: Describe the bad design of the following codes and redesign the classes. class Customer { public: int birthYear; bool isCurrentMember; int numberOfPurchases; Customer() { // Test data. birthYear = 1963; isCurrentMember = false; numberOfPurchases = 33; } void DisplayDetails() { printf( "Birth Year: %ld\r\n", birthYear ); printf( "Current Member: %s\r\n", isCurrentMember ? "Yes" : "No" ); printf( "Number Of Purchases: %ld\r\n\r\n", numberOfPurchases ); } }; class Salesman { private: Customer bestCustomer; Customer worstCustomer; public: int id; Salesman( int initialID ) { id = initialID; } Customer BestCustomer() { return bestCustomer; } Customer* WorstCustomer() { return &worstCustomer; } }; class SalesTeam { public: Salesman salesman1; Salesman salesman2; SalesTeam() : salesman1(1000), salesman2(1001) {} void DisplayTeam() { printf( "Salesman 1: %ld\r\n", salesman1.id ); printf( "Salesman 2: %ld\r\n", salesman2.id ); } }; void TestSalesmanCustomers() { SalesTeam ourTeam; int medianSales_1 = (ourTeam.salesman1.BestCustomer().numberOfPurchases + ourTeam.salesman1.WorstCustomer()->numberOfPurchases) / 2; int medianSales_2 = (ourTeam.salesman2.BestCustomer().numberOfPurchases + ourTeam.salesman2.WorstCustomer()->numberOfPurchases) / 2; printf( "Salesman median sales = %ld\r\n", medianSales_1); printf( "Salesman median sales = %ld\r\n", medianSales_2); }   And here is my answer Header: #ifndef _REDESIGN_H #define _REDESIGN_H #include <stdio.h> #include <list> // Customer class // *In the future this class should provide functions to set // m_birthYear, m_isCurrentMember and m_numberOfPurchases values // in case of changes. class Customer { public: Customer( int birthYear, bool isMember, int numOfPurchases ): m_birthYear(birthYear), m_isCurrentMember(isMember), m_numberOfPurhchases(numOfPurchases) {} ~Customer() {} // functions to get private member variables int getBirthYear() { return m_birthYear; } int getNumOfPurchases() { return m_numberOfPurhchases; } bool checkCurrentMember() { return m_isCurrentMember; } void displayDetails(); private: int m_birthYear; bool m_isCurrentMember; int m_numberOfPurhchases; }; // Salesman class // *In the future, function to search customers by their birthYear, NumberOfPurchases and // memberStats could be added. // *Comparison in function addCustomer() could be extended to consider more // situations include membership status. class Salesman { public: Salesman( int initialID ); ~Salesman() { m_customerList.clear(); } Customer* getBestCustomer() { return m_bestCustomer; } Customer* getWorstCustomer() { return m_worstCustomer; } bool addCustomer( Customer* cust ) int getID(); private: Customer* m_bestCustomer; Customer* m_worstCustomer; int m_id; // Container to store list of customer pointers std::list<Customer*> m_customerList; bool m_firstTime; }; // SalesTeam class // *Function to remove a salesman from saleteam by id could be implemented // in the future. // *Function to calculte particular salesman's median sales nunmber can be implemented class SalesTeam { public: SalesTeam() {} ~SalesTeam() { m_salesmanList.clear(); } bool addSalesman( Salesman* sales ); Salesman* getSalesman( int id ); void displayTeam(); private: // *Container to store list of salesman pointers. // *Makes the class more flexible and easier to // handle. std::list<Salesman*> m_salesmanList; }; #endif  CPP: #include "Redesign.h" //-------------------------------------------------------------------- // Customer class implementations void Customer::displayDetails() { printf( "Birth Year: %ld\r\n", m_birthYear ); printf( "Current Member: %s\r\n", m_isCurrentMember ? "Yes" : "No" ); printf( "Number Of Purchases: %ld\r\n\r\n", m_numberOfPurhchases ); } //------------------------------------------------------------------- // Salesman class implementations Salesman::Salesman( int initialID ) { m_id = initialID; m_firstTime = true; m_bestCustomer = 0; m_worstCustomer = 0; } int Salesman::getID() { return m_id; } bool Salesman::addCustomer( Customer* cust ) { // Finds out best and worst customer by comparing their // number of purchases if( cust ) { // First time initials if( m_firstTime ) { m_bestCustomer = cust; m_worstCustomer = cust; m_firstTime = false; } m_customerList.push_back( cust ); // comparison if( cust->getNumOfPurchases() >= m_bestCustomer->getNumOfPurchases() ) m_bestCustomer = cust; else if( cust->getNumOfPurchases() <= m_worstCustomer->getNumOfPurchases() ) m_worstCustomer = cust; return true; } else return false; } //------------------------------------------------------------------ // SalesTeam class implementation bool SalesTeam::addSalesman( Salesman* sales ) { // Check if pointer valid if( sales ) { m_salesmanList.push_back( sales ); return true; } else return false; } Salesman* SalesTeam::getSalesman( int id ) { auto it = m_salesmanList.begin(); while( it != m_salesmanList.end() ) { if( (*it)->getID() == id ) return (*it); ++it; } return 0; } void SalesTeam::displayTeam() { auto it = m_salesmanList.begin(); while( it != m_salesmanList.end() ) { printf( "Salesman: %ld\r\n", (*it)->getID() ); ++it; } }   Thank you guys
  4. [quote name='Hodgman' timestamp='1346390321' post='4975044'] You need to use the ModelViewProjection matrix, and divide by [font=courier new,courier,monospace]w[/font], not [font=courier new,courier,monospace]z[/font], to get it into screen space. [/quote] [quote name='BLM768' timestamp='1346390761' post='4975045'] To properly obtain the coordinates, I think that you need to multiply the vertex coordinates by the projection matrix and then divide the x/y values by -z. However, I'd recommend considering using the stencil buffer to mask out the non-mirror areas, render the reflection, then render the unreflected scene. It's a bit more complex than that, but that's the general idea. The advantage to this method is that you don't need an additional texture, and the stencil test prevents some of the unnecessary fragment processing from happening. [/quote] Thanks for your help, I will try these methods.
  5. Hello guys. I used FBO to render the reflected stuff to a texture, after that I was confusing how to compute the correct texture coordinate for the texture? Here is the main stuff I wrote in GLSL and it didnt give me the right thing: // VERTEX SHADER varying vec2 v; vec4 vertex = gl_ModelVIewMatrix * gl_Vertex; v.x = vertex.x/vertex.z; v.y = vertex.y/vertex.z; // FRAGMENT SHADER texture2D( reflectTex, vec2((v.x+1) * 0.5, (v.y+1) * 0.5) ); What is wrong with the calculation? or is there another way to achieve it?
  6. Thanks for your replies. Now I get the differences between them.
  7. As the title, im wondering whats the difference between them. Cuz vertex shader deals with every vertex the program transfers, and how can it deal with the pixels ?