2,712 Posted Topics
Re: Yea so this is a problem of collision response. Once a collision is detected what do you do? Well in this case you should move your player back just before the collision point. So if there is a collision, shift back the player's position so that there is not a … | |
This question is from code chef, named Odd. I believe this is a good problem to play with for all levels. If I can solve it surely anyone else can, cough * only if pi is fake* cough*. Here is the question : [ICODE]The captain of the ship TITANIC is … | |
Re: I think the syntax is int rowSize = 5; int colSize = 5; float **matrix = new float*[rowSize]; for(int i = 0; i < rowSize; ++i){ matrix[i] = new float[colSize]; } //do stuff with matrix[i][j] //delete for(int i = 0; i < rowSize; ++i){ delete [] matrix[i]; } delete [] … | |
Re: You can think an Abstract class as a class that combines the similarity of many things into one object. Thus when inheriting from the ABC, you will have to type less redundent code. | |
Re: Please reformat your code. What is the problem you are having? | |
Re: If you convert the matrix of double into a matrix of chars, you might lose some data since char cannot hold the same range of data as double can. You can copy like so `std::vetor<unsigned char> pixels(matrix.begin(),matrix.end())`. What problem are you having exactly? | |
Re: glTranslate translate the current view matrix, not just one object. So it can be used for different things | |
Re: How are the commands stored? One approach is to do something of the following: struct Command{ /* whatever makes a command, insert variables here */ friend ostream& operator>>(ostream&, Command& cmd){ //given a stream, try to read in a command } } int main(){ //open file and stuff std::vector<Command> commands; Command … | |
Re: Your Edge class can be stripped down to this class Edge { public: Edge() { } Edge(int from, int to, double weight = -1) : from (from), to (to), weight (weight) { } int from; int to; bool directed; double weight; }; Since the compiler generated functions will suffice. In … | |
Re: So you are trying to read in a input from cin and you want to save only the inputs that starts with a number or a negative sign, and any other type of input you want to insert back into istream? Is that right? Do you have to reinsert them … | |
Re: >>Why are you taking pain by handling memory yourself. Use power of STL. Its ironic, because C++ has a stack implementation already. So why even do what you did above? | |
Re: [URL="http://msdn.microsoft.com/en-us/library/ewwyfdbe(v=vs.80).aspx"]Bit Fields[/URL] | |
Re: You probably forgot to seed it. Try this: [code] #include <iostream> #include <ctime> using namespace std; int main(){ srand( time(0) ); //seed the RGN for(int i = 0; i < 10; ++i){ std::cout << (rand() % 100 + 1) << std::endl; } return 0; } [/code] | |
Re: [QUOTE=Chuckleluck;1779100]Can someone give me some resources (books, online tutorials, etc.) on algorithms for 2D collision detection? I've searched a little, and all the ones I can find are for 3D collision detection. Thanks in advance. EDIT: Just to clarify, I know [I]how[/I] to do collision detection, just not efficiently.[/QUOTE] which … | |
Re: [URL="http://stackoverflow.com/questions/369438/smooth-spectrum-for-mandelbrot-set-rendering"]http://stackoverflow.com/questions/369438/smooth-spectrum-for-mandelbrot-set-rendering[/URL] | |
Re: >>Now, all my pieces have no unique "rules" on how they act Well it should if c_ChessPiece has proper virtual functions? Btw, not a fan of the class-prefix. For example take a look at [URL="https://github.com/dchhetri/SFML-Chess/blob/master/ChessGame/ChessPiece.h"]this[/URL] interface. A ChessPiece should at least have some uniform functions, like move and such. So … | |
![]() | Re: First you should be using templates. But the solution to your problem is to provide a virtual clone function. Look [URL="http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.8"]here[/URL] for more information. |
Re: >>I am storing many variables of different types. Can you convert/encode all those variables to a string version? | |
Re: Not sure what technique you used, but in comp Sci its usually done by making the matrix in echelon form and multiplying the diagonal numbers Nice job though. | |
Re: what is data-type for your list? | |
Re: [QUOTE=triumphost;1772191]Uhh well that's the thing.. I want to allow "empty parameters" and that's why I need to check.. so that I can do: [CODE] class DoStuff { private: void Insert(){} vector<Types> Meh; public: DoStuff() {} //This constructor doesn't get kicked in due to the one below it.. template<typename T, typename... … | |
Re: I'm not sure what exactly you are saying. What is a binary tree with 1 and 2? Maybe a picture would help. | |
Re: You would want to use the concept of iterators, and just assume certain property like being able to move forward. Check out [URL="http://www.cplusplus.com/reference/algorithm/find/"]http://www.cplusplus.com/reference/algorithm/find/[/URL] for more reference. | |
Re: [QUOTE=BDove;1766255]In my opinion [B]"++"[/B] in C/C++ is just terrible. I don't even know why they allow it to be part of the language. Try [CODE]pID = pID + 1;[/CODE] [B]"++"[/B] increment its value by 1 and assigns it to the variable. However, if the operator is inserted inside a conditional … | |
Re: >>[B]M- happens to be a unknown function of N[/B] That means, M = f(N), and you can't assume anything about f(N), so the runtime would be O(N * f(N)). That could be linear, polynomial, quadratice, factorial, or whatever; all depending on f(N) | |
Re: What do you need help with? Maybe this will get you started. [code] #include <iostream> using namespace std; bool isPrime(int number){ bool isPrimeNumber = false; //do logic here return isPrimeNumber; } int main(){ cout << boolalpha << "Is 5 prime : " << isPrime(5) << endl; //should be true cout … | |
Re: Maybe someone will correct me, but I believe its just convention. But WinMain does have extra parameter options than int main() which might become useful. But a thing to note is that returning in WinMain really doesn't do much since its returned value is passed to ExitThread instead of ExitProcess. ![]() | |
Re: I still don't know what 0R1,0R2,0S4,1S4 does! Can you give an example of what each of the instruction should do on some input | |
Re: If you want to read the file into a vector, then you can represent each pixel as a char or int. For example you can have something like so, [icode] std::vector<char> pixels; [/icode] and read from file into that vector. For example: [code] std::vector<char> pixels; ifstream fileInput("imagefile.txt"); //read from file … | |
Re: [CODE]INPUT-BUFFER: 973 456.2 77F NEWLINE 973 456.2 77F 1) cin>> m; //m = 973 INPUT-BUFFER: 456.2 77F NEWLINE 973 456.2 77F 2) cin.clear (); //clears the state bits INPUT-BUFFER: 456.2 77F NEWLINE 973 456.2 77F 3) cin.ignore (200, '\n'); //ignores 200 characters or until a new line is reached INPUT-BUFFER: … | |
Re: Check out [URL="http://www.cplusplus.com/reference/string/string/erase/"]string::erase[/URL] | |
Re: You know if you use std::vector, it does that for you. [code] int main(){ std::vector<int> array; //size = 0; array.push_back( 1) ; //size = 1, [1] array.push_back(5); //size = 2, [1,5] } [/code] | |
Re: There are better ways of doing it, here is one examples. [code] typedef std::vector<int> Matrix; //alias Matrix getMatrix(){ return Matrix(10,1); //returns an array with 10 elements each initialized to 1 } int main(){ Matrix m = getMatrix(); for(int i = 0; i < m.size(); ++i){ cout << m[i] << endl; … | |
Re: [QUOTE]Matrix 1: 0 1 0 1 0 1 0 1 0 1 1 1 1 0 1 [/QUOTE] What's the data type of Matrix? | |
Re: >>//Given x=10 and y=5 y = 2*y++ + --x; y = (2*y++) + (--x) //substitute, not valid but easier to see y = (2 * 5++) + (--10); y = (2 * 5) + (--10) //5++ returns 5 first then increments, so 5 will be multiplied to 2 y = … | |
Re: Adding to above, change this [code] ANew() : ArrayOfTypes(0) {}[/code] to this [code] ANew(){} [/code] The vector will be default constructed already | |
Re: Maybe you should look at the definition of artificial. Here it is. [b]Artificial:[/b] 1) Made or produced by human beings rather than occurring naturally, typically as a copy of something natural: "artificial light". 2) Not existing naturally; contrived or false: "the artificial division of people into age groups". * found … | |
Re: [QUOTE=yongj;1757973]Thank you all for the replies. Do you guys have any online references? I'm mainly trying to find online resources.[/QUOTE] [URL="http://en.wikipedia.org/wiki/Hash_table"]Wiki[/URL] is usually a good place to start! | |
Check out the [URL="http://en.wikipedia.org/wiki/Boggle"]wiki[/URL] for boggle. You job is to create a program that generates all possible words that can be constructed given the boggle board and a dictionary. A word has to be of length three or greater and the word has to exist in the dictionary. For example … | |
Re: Learn the concept first! When I say learn it, I mean know it inside and out. Its easy to pick up a language once you get the concept down. Stick with one language for now, and use it for your needs. Program data structures using that language and become a … | |
Re: When you run a program, it creates a process for that program. So when you call exit within that process, the os kills that process and cleans up memory. As for its actual implementation, I do not know. It is most likely implementation specific, that is I don't think there … | |
Re: [URL="http://www.boost.org/doc/libs/1_48_0/doc/html/any/s02.html"]example[/URL] | |
Re: You can look at previous days/weeks/months/years data and observe the context at which the price was stated and then look at the current situation of the stock/company then make a educated prediction based on the information. | |
Re: Sometimes it helps to see concrete examples: [code] int r1 = rand() ; //random number from [0 , RAND_MAX] int r2 = rand() % 100; // random number from [0,100); Note doesn't include 100 int r3 = rand() % 100 + 1; //random number from [1,100]; Note includes 100 const … | |
Re: [URL="http://codepad.org/edEYoes9"]http://codepad.org/edEYoes9[/URL] | |
Re: [URL="http://www.cplusplus.com/reference/iostream/ios_base/precision/"]http://www.cplusplus.com/reference/iostream/ios_base/precision/[/URL] | |
Re: [QUOTE=NathanOliver;1752223]Yes you can Overide any operator you want. This can be done globally or at a specific level.[/QUOTE] [url]http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.5[/url] | |
Re: You can basically do a 'binary split adding the middle every split. I tried coding something real quick and here it is: [code] #include <iostream> #include <cmath> #include <iterator> #include <vector> using namespace std; template<typename T, typename Result> void _splitImpl(T begin, T end, Result& result); template<typename RandomAccessIterator> std::vector<int> binarySplit(RandomAccessIterator begin, … |
The End.