• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=^-^;26629720]What exactly is the difference between "." and "->"[/QUOTE] [cpp]foo->bar[/cpp] is equivalent to [cpp](*foo).bar[/cpp] The dot accesses a member of an object. The arrow dereferences a pointer and accesses a member of the thing it points to.
[url]http://www.stackoverflow.com[/url] /thread [editline]11th December 2010[/editline] I didn't know SFML was that popular. I'm very OCD about using what is the most "standard" lib or whatever. I use SDL with all of its little extras. (SDL_ttf, SDL_mixer, and SDL_image) Also if I feel the odd urge to use C instead of C++ I can do that in SDL. With SFML it has you get CSFML which I've heard is pretty shoddy. Something else I'd like to add is that since SFML is so object-oriented it feels like it restricts itself in where you can put things and how things can/should be written. Like you're even more restricted than in SDL. [u]And that is fucking restricting.[/u]
Yeah. It's called proper design. You shouldn't be able to do everything anywhere. If you want though, you could just have everything as a global.
[QUOTE=ZeekyHBomb;26642978]Yeah. It's called proper design. You shouldn't be able to do everything anywhere. If you want though, you could just have everything as a global.[/QUOTE]Proper design means to restrict the user to only be able to do things a certain way and only be able to put (or write) code in certain places even though you should be able to put those certain things elsewhere? No that's just annoying. :smile:
Proper design means to restrict the user to only be able to do things a certain way, which makes sense for a logical structure and/or has benefits in resource-usage (performance, memory) and/or extendability and/or maintainability, possibly also to force the user to write code easily understandable by others.
[QUOTE=Shotgunz;26643869]Proper design means to restrict the user to only be able to do things a certain way and only be able to put (or write) code in certain places even though you should be able to put those certain things elsewhere? No that's just annoying. :smile:[/QUOTE] I bet you're the kind of guy that never writes comments anywhere, or uses annoying variables names.
Wow, what's with the sudden influx of idiots in this thread? We have someone rating everyone dumb for no reason, people criticising proper design... It's like fast threads have moved in here or something
[code] -- -- MySQL 5.0.75 -- Sun, 12 Dec 2010 12:21:06 +0000 -- CREATE TABLE `cities` ( `id` int(10) not null auto_increment, `city` tinytext, `country` tinytext, `province` tinytext, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=swe7 AUTO_INCREMENT=1; CREATE TABLE `patterns` ( `id` int(10) not null auto_increment, `pattern` tinytext, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=swe7 AUTO_INCREMENT=1; CREATE TABLE `items` ( `id` int(10) not null auto_increment, `type_id` int(10) FOREIGN KEY('type_id') REFERENCES types('id'), `pattern_id` int(10) FOREIGN KEY('pattern_id') REFERENCES patterns('id'), `length` float, `cost` float, `total_rings` bigint(10), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=swe7 AUTO_INCREMENT=1; CREATE TABLE `types` ( `id` int(10) not null auto_increment, `type` tinytext, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=swe7 AUTO_INCREMENT=1; CREATE TABLE `orders` ( `id` int(10) not null auto_increment, `type_id` int(10) FOREIGN KEY('type_id') REFERENCES types('id'), `item_id` int(10) FOREIGN KEY('item_id') REFERENCES items('id'), `status` int(10), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=swe7 AUTO_INCREMENT=1; CREATE TABLE `users` ( `id` int(10) not null auto_increment, `first_name` tinytext, `surname` tinytext, `street` tinytext, `street_number` int(10), `city_id` int(10) FOREIGN KEY('city_id') REFERENCES cities('id'), `postal_code` int(10), `current_order_id` int(10) FOREIGN KEY('current_order_id') REFERENCES orders('id'), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=swe7 AUTO_INCREMENT=1; [/code] I'm trying to use foreign keys, is this correct?
[QUOTE=Armandur;26644535] I'm trying to use foreign keys, is this correct?[/QUOTE] You might have more luck asking this in web dev.
[QUOTE=sim642;26646769]You might have more luck asking this in web dev.[/QUOTE] I'll try that.
I'm having some problems with collisions, I have an array of bullets that all need bounding boxes and I have a ship that also needs a bounding box. I need to detect when they collide so the ship can either lose health or die. I'm used to creating them on XNA where you just created a rectangle and then detected collision if they hit each other but C++ doesn't seem to have this feature.
So I was working on Project Euler problem 52. I need to find the first number that when multiplied by 2 contains the same numbers as when it's multiplied by 3, 4, 5, and 6. I really can't figure out what I'm doing wrong here, so if you see any obvious errors, please point them out. [code] public static void main(String[] args) { int[][] numCounts = new int[7][10]; char[] temp; boolean equal; for(long i = 1; i<10000000; i++){ if(i%10000 == 0){ System.out.println(i); } for(int j = 2; j<7; j++){ temp = String.valueOf(j*i).toCharArray(); for(char num : temp){ numCounts[j][num-'0']++; } } equal = true; for(int j = 0; j<10; j++){ for(int k = 3; k<7; k++){ if(numCounts[2][j] != numCounts[k][j]){ equal = false; break; } } if(!equal){ break; } } if(equal){ System.out.println(i); break; } } } [/code]
What exactly is the problem? Getting a wrong answer? What's the answer your program prints?
[QUOTE=ZeekyHBomb;26654468]What exactly is the problem? Getting a wrong answer? What's the answer your program prints?[/QUOTE] It doesn't find an answer at all.
Have you considered that it might not below 10000000? ;) (I don't know whether or not it is, but it's a valid assumption.)
Excuse my newbie question but I'm in the process of learning C++ and was wondering which is more 'acceptable' design. Declaring a function prototype before [code]int main(){}[/code] and defining the function below main. Or would it be better to just define the function above main?
[QUOTE=Jimmylaw;26649394]I'm having some problems with collisions, I have an array of bullets that all need bounding boxes and I have a ship that also needs a bounding box. I need to detect when they collide so the ship can either lose health or die. I'm used to creating them on XNA where you just created a rectangle and then detected collision if they hit each other but C++ doesn't seem to have this feature.[/QUOTE] As it doesn't need to be precise I would suggest using octrees and then bounding spheres. You have to write the code yourself but there is loads about it online.
[QUOTE=lazypenguin;26654633]Excuse my newbie question but I'm in the process of learning C++ and was wondering which is more 'acceptable' design. Declaring a function prototype before [code]int main(){}[/code] and defining the function below main. Or would it be better to just define the function above main?[/QUOTE] I usually define it above main if it's small enough, probably less than 10 lines.
[QUOTE=lazypenguin;26654633]Excuse my newbie question but I'm in the process of learning C++ and was wondering which is more 'acceptable' design. Declaring a function prototype before [code]int main(){}[/code] and defining the function below main. Or would it be better to just define the function above main?[/QUOTE] Usually you have a set of different files, say you had a bunch of math-related functions you might have math.cpp (the functions are defined here) and math.hpp (the functions are declared here). Then in main.cpp or whatever you would #include math.hpp and when building you'd link main.cpp and math.cpp together.
[QUOTE=ZeekyHBomb;26654736]Usually you have a set of different files, say you had a bunch of math-related functions you might have math.cpp (the functions are defined here) and math.hpp (the functions are declared here). Then in main.cpp or whatever you would #include math.hpp and when building you'd link main.cpp and math.cpp together.[/QUOTE] math[b].hpp[/b]?
Yeah. What's wrong with that?
[QUOTE=ZeekyHBomb;26654608]Have you considered that it might not below 10000000? ;) (I don't know whether or not it is, but it's a valid assumption.)[/QUOTE] I looked up the answer and it's around 140000.
I think I found the bugger: You should reset numCounts after each iteration.
[QUOTE=ZeekyHBomb;26655315]I think I found the bugger: You should reset numCounts after each iteration.[/QUOTE] Thanks a bunch! It works now and it got the right answer. I'll have to remember to watch out for that.
[QUOTE=Jimmylaw;26649394]I'm having some problems with collisions, I have an array of bullets that all need bounding boxes and I have a ship that also needs a bounding box. I need to detect when they collide so the ship can either lose health or die. I'm used to creating them on XNA where you just created a rectangle and then detected collision if they hit each other but C++ doesn't seem to have this feature.[/QUOTE] You mean like this? [url]http://www.sfml-dev.org/documentation/2.0/classsf_1_1Rect.htm#a63ad921f63da1183baa87f9e246cab6b[/url]
[QUOTE=Richy19;26656849]You mean like this? [url]http://www.sfml-dev.org/documentation/2.0/classsf_1_1Rect.htm#a63ad921f63da1183baa87f9e246cab6b[/url][/QUOTE] Yea that's how XNA can do it, but I'm using directx.
Hello guys, hope you don't mind if I drop in with a quick problem. Recently I've began trying out 3D programming. It was confusing at first, but I get it now. But what's keeping me from doing any more work is collisions. I modified some code that I used long ago on a previous game that had some basic collisions and tried to configure it as much as I could to work in 3D. But the problem is that it's very buggy; two of the sides are almost perfect, one is slightly buggy, and one is just fucked to the point where I wonder if I should even bother with it. The code in question: [cpp] if((x + 0.1 > -xx) && (x < -xx + 1) && (y + 2.5 > -yy) && (y < -yy + 1) && (z + 1 > -zz) && (z < -zz + 1)) x = -xx + 1; if((x + 2 > -xx) && (x < -xx + 0.1) && (y + 2.5 > -yy) && (y < -yy + 1) && (z + 1 > -zz) && (z < -zz + 1)) x = -xx - 2; if((x + 1 > -xx) && (x < -xx + 1) && (y + 2.5 > -yy) && (y < -yy + 1) && (z + 0.1 > -zz) && (z < -zz + 1)) z = -zz + 1; if((x + 1 > -xx) && (x < -xx + 1) && (y + 2.5 > -yy) && (y < -yy + 1) && (z + 2 > -zz) && (z < -zz + 0.1)) z = -zz - 2; [/cpp] I name my variables in a very bad way, sorry. x, y, and z are the camera's coordinates while xx, yy, and zz is the block's coordinates. And I bet I'm doing something terribly wrong here, oh well. Thanks! :buddy:
With 3D it is better to use more complex collision detection. Look into using Octrees to see where a collision will occur (basically split the screen up into 8 sections and check for collisions in each section). Then use bounding boxes on each object that will collide with OBB so that the bounding boxes can rotate. It requires quite a lot of code to get there, I just had to do something similar in my game. What type of game are you making? If it is 3D but the characters can never move off the same level as each other then you can still use 2D.
I was mainly just practicing some basic 3D programming, I don't think I will do anything series (I'm making a world consisting out of cubes like Minecraft (I'm so original)) so I thought the way I was doing it would be a lot easier.
If they are just cubes then just normal bounding boxes should be fine. You can work out what face is facing what face and do less collision tests that way, I am sure something will come up on google about it.
Sorry, you need to Log In to post a reply to this thread.