• What do you need help with? V. 3.0
    4,884 replies, posted
[QUOTE=vexx21322;33104959]I've having a real problem finding the exact regular expression to do what I need. I need a regular expression to give me just the domain name of whatever url I input. for example: [url]http://google.com/search?blahblahblah[/url] = google.com [url]http://www.something.more.com/blah[/url] = more.com[/QUOTE] I honestly can't think of one without it being complex and breakable, seeing as there's valid domains like .co.uk.
[QUOTE=vexx21322;33104959]I've having a real problem finding the exact regular expression to do what I need. I need a regular expression to give me just the domain name of whatever url I input. for example: [url]http://google.com/search?blahblahblah[/url] = google.com [url]http://www.something.more.com/blah[/url] = more.com[/QUOTE] Found this page that has regular expressions that seem to do what is asked ([url]http://weblogtoolscollection.com/regex/regex.php?page=3[/url]). [code] /^(http:\/\/)?([^\/]+)/i (Gets hostname from URL) /[^\.\/]+\.[^\.\/]+$/ (Gets last two segments of hostname) [/code]
[QUOTE=calzoneman;33097859]Does anyone have ideas for how to randomly generate a polygon that is guaranteed to be convex? What I'm doing now is creating a regular polygon and randomly moving the vertices radially outward from the center, but sometimes that results in concave shapes and Box2D shits itself with assertion failures. I've looked into ways of testing whether a polygon is convex but I'm looking for something more efficient than "while the shape is not convex generate another one" Relevant code: [cpp] for(double ang = 0.0; ang < 2*PI; ang += interval) { int length = maxW/2 + rand() % maxH; points.push_back(Vector2(length*cos(ang), length*sin(ang))); n++; } [/cpp][/QUOTE] I didn't see any replies to this. I don't have pseudo-code yet, but if you drew a line through every other point, there should only be one point on one side of it (unless it makes a straight line). amiright?
[QUOTE=AaRoNg11;33113712]Personally I would recommend C++ over C as taking an object oriented aproach to graphical simulations (such as games) makes things much easier in the long run. A good idea for a simple(ish) project is some kind of text based adventure game. You can implement file input / output (game saving / loading), practise handling user input (parsing strings) and lots of other stuff like that. [/QUOTE] Okay, I'll give that a try, thanks!
[QUOTE=Richy19;33113439]Im trying to draw stuff to an openGL ready renderwindow but it wont draw anything. Found out its this: [b]glEnable(GL_CULL_FACE);[/b] Not sure why that would make it not draw. Had to do this, bit anoying: [cpp]App.SaveGLStates(); glDisable(GL_CULL_FACE); App.Draw(backGroundSprite); App.RestoreGLStates(); glEnable(GL_CULL_FACE);[/cpp][/QUOTE] Actually you were drawing your polys the wrong way, their surface normals were facing away from the viewport. Culling is a rendering optimization where the backfaces of polys are ignored as usually they're on the inside of your model anyway.
[QUOTE=subenji99;33117145]Actually you were drawing your polys the wrong way, their surface normals were facing away from the viewport. Culling is a rendering optimization where the backfaces of polys are ignored as usually they're on the inside of your model anyway.[/QUOTE] I was using the SFML::App.Draw method. I have no play on how the quad is drawn [editline]4th November 2011[/editline] How can I write say a string into a file in binary? Or some other non human readable form? I tried ios::binary but it doesnt do what I thought it did. I thought I could do something like: myFile.write((char *)&string, sizeof(string)); C++ [editline]4th November 2011[/editline] Also to avoid errors and such should you try and have all your includes in the Cpp file or the header?
Okay, can anyone link me to a good Perlin Noise tutorial for land generation (2D only). Google results tend to turn up articles about how Perlin Noise came about, and not how to use it. If there is a better alternative than Perlin Noise, could you tell me that to?
Hi, I'm trying to create a Mandelbrot set in XNA, just because I'm bored. I understand how the set works and how I would calculate whether a given point is part of the set or not, but I have no clue how to colour in XNA. As in, I don't know how to set pixel [0;0] to be a given colour, and then draw that. How would I do such a thing? Sorry if I haven't explained myself too well
[QUOTE=AntonFTW;33105186]New C++ programmer here, I am working on a simple text based game to help me understand C++ better, I recently I found out how to do stuff when a key is pressed rather than when you type something in. I am currently re-doing my navigation system to be arrow-key selection based rather than typing-based. It works great except for a huge problem, in some places I have a getline cin for stuff like choosing a name, and after I select something in the menu by pressing enter, the cin that comes ~10 seconds after that picks up the enter and attempts to select a blank name, I use GetAsyncKeyState to pick up keyboard presses, I assume the problem is because the cin picks up stuff that's been written before it appears, is there some way to empty what has been typed in before the cin appears?[/QUOTE] Anyone? I've been googling for a solution for days, still can't find it. I'm sure it's very easy for you people who know programming, I just need a way to empty what the user has typed in before a cin appears.
[QUOTE=Richy19;33121109]I was using the SFML::App.Draw method. I have no play on how the quad is drawn[/QUOTE] I meant you were supplying the vertices in the wrong order, it's being created facing away from your viewport rather than towards.
[QUOTE=subenji99;33122472]I meant you were supplying the vertices in the wrong order, it's being created facing away from your viewport rather than towards.[/QUOTE] Again, i simply suply an image, SFML does all of the verticie(?) drawing internally
[QUOTE=Richy19;33122634]Again, i simply suply an image, SFML does all of the [b]verticie[/b](?) drawing internally[/QUOTE] Vertex.
[QUOTE=Richy19;33121109] How can I write say a string into a file in binary? Or some other non human readable form? I tried ios::binary but it doesnt do what I thought it did. I thought I could do something like: myFile.write((char *)&string, sizeof(string)); C++ [/QUOTE] Strings pretty much can't be written in binary at face value. When writing in binary, you're writing a file in hex and each "character" that's written is a number from 00 to FF. If you open a normal text file in a hex editor, you'll see what I mean. You'll have to look at data compression methods to make the strings into some sort of non human readable form.
[QUOTE=Niteshifter;33124811]When writing in binary, you're writing a file in hex[/QUOTE] Wait what, which one was I using again [editline]5th November 2011[/editline] (Protip: Binary and hexadecimal are the base2 and base16 number systems, respectively)
Question about Lua: How would I request a PHP script using POST and some data, and storing the returned value as a string?
[QUOTE=Richy19;33121109]How can I write say a string into a file in binary? Or some other non human readable form? I tried ios::binary but it doesnt do what I thought it did. I thought I could do something like: myFile.write((char *)&string, sizeof(string)); C++ [/QUOTE] All of the data you write is binary on the disk. std::ios::binary only enforces writing newlines and other strange characters exactly as they appear on your OS. (\n -> \r\n on Windows etc.) It's not particularly "non- human readable" even if you for some reason decide to output a large binary digit string, either; There's a million converters out there and making one yourself is trivial. You probably want to encrypt your strings. [editline]5th November 2011[/editline] [QUOTE=Darkwater124;33124895]Question about Lua: How would I request a PHP script using POST and some data, and storing the returned value as a string?[/QUOTE] Get LuaSocket and use [url=http://w3.impa.br/~diego/software/luasocket/http.html]socket.http[/url] (Disclaimer: Linked site might not be up to date)
[QUOTE=esalaka;33124923]Get LuaSocket and use [url=http://w3.impa.br/~diego/software/luasocket/http.html]socket.http[/url] (Disclaimer: Linked site might not be up to date)[/QUOTE] I have that, but I dont know how to use it with POST.
[url=http://lua-users.org/lists/lua-l/2006-02/msg00014.html]Could this possibly help[/url]? Basically you set { url = "url", request_body="parameters", method="POST" } and other things you possibly want to.
[QUOTE=esalaka;33124854]Wait what, which one was I using again [editline]5th November 2011[/editline] (Protip: Binary and hexadecimal are the base2 and base16 number systems, respectively)[/QUOTE] When a file is opened with the ios::binary flag, you read and write to it using hex. If I wrote 0x61 to a file with the binary flag, it would come out as 'a'. It also works vice versa where if I read 'a' from a file opened with the binary flag, I would get 0x61.
[QUOTE=Niteshifter;33125299]When a file is opened with the ios::binary flag, you read and write to it using hex. If I wrote 0x61 to a file with the binary flag, it would come out as 'a'. It also works vice versa where if I read 'a' from a file opened with the binary flag, I would get 0x61.[/QUOTE] What the hell are you on? That [B]always[/B] works. The ASCII charcode for 'a' is 0x61. You can check this. ( 'a' == 0x61 ) is true. [url=http://www.cplusplus.com/doc/tutorial/files/]Read[/url] the part about binary files. Also, here's just [url=http://www.cplusplus.com/reference/iostream/ios_base/openmode/]std::ios_base::openmode[/url].
[QUOTE=esalaka;33125287][url=http://lua-users.org/lists/lua-l/2006-02/msg00014.html]Could this possibly help[/url]? Basically you set { url = "url", request_body="parameters", method="POST" } and other things you possibly want to.[/QUOTE] That did it, thank you!
[QUOTE=esalaka;33125402]What the hell are you on? That [B]always[/B] works. The ASCII charcode for 'a' is 0x61. You can check this. ( 'a' == 0x61 ) is true. [url=http://www.cplusplus.com/doc/tutorial/files/]Read[/url] the part about binary files. Also, here's just [url=http://www.cplusplus.com/reference/iostream/ios_base/openmode/]std::ios_base::openmode[/url].[/QUOTE] I never said that it only works for that case, I'm aware of what the ascii codes are. I understand that when opening a file with the binary flag, they're read/written with binary numbers. However, while the file itself is in binary, most people will be reading/writing to them in hex as it's easier to understand a number like 6F rather than 01101111.
[QUOTE=Niteshifter;33126157]I understand that when opening a file with the binary flag, they're read/written with binary numbers. However, while the file itself is in binary, most people will be reading/writing to them in hex as it's easier to understand a number like 6F rather than 01101111.[/QUOTE] [B]NO YOU DO NOT GET IT AT ALL.[/B] The binary flag is there only so that platforms like Windows could properly read binary files in; In text mode, on Windows, \r\n is turned into \n when reading and vice versa when writing because that's what it means - a line break. In binary mode, it's not, because in a binary file it might not be a line break at all. It has nothing to do with "writing in binary numbers". You can do that in text mode. You can do anything you want in either mode but you usually want to go text mode for text and binary mode for binary because chances are something is going to fuck up with the transforms if you don't. [editline]5th November 2011[/editline] Besides, the current standard C++ doesn't even [B]allow[/B] binary integer constants. [editline]5th November 2011[/editline] How the hell are you even giving out advice on C++ when you clearly have no idea of what you're talking about
[QUOTE=Richy19;33113439]Im trying to draw stuff to an openGL ready renderwindow but it wont draw anything. Found out its this: [B]glEnable(GL_CULL_FACE);[/B] Not sure why that would make it not draw. Had to do this, bit anoying: App.SaveGLStates(); glDisable(GL_CULL_FACE); App.Draw(backGroundSprite); App.RestoreGLStates(); glEnable(GL_CULL_FACE);[/QUOTE] I'm fairly sure that the default winding order for opengl is anti clockwise, and I think sfml creates vertices clockwise and expects no culling. Use glFrontFace(GL_CW) if you want to enable it.
[QUOTE=calzoneman;33097859]Does anyone have ideas for how to randomly generate a polygon that is guaranteed to be convex? What I'm doing now is creating a regular polygon and randomly moving the vertices radially outward from the center, but sometimes that results in concave shapes and Box2D shits itself with assertion failures. I've looked into ways of testing whether a polygon is convex but I'm looking for something more efficient than "while the shape is not convex generate another one" Relevant code: [cpp] for(double ang = 0.0; ang < 2*PI; ang += interval) { int length = maxW/2 + rand() % maxH; points.push_back(Vector2(length*cos(ang), length*sin(ang))); n++; } [/cpp][/QUOTE] I have an idea. Start with a circle, put a number of dots at a random angle on it's circumference, then connect them clockwise or counter-clockwise, i.e. next point = closest as you go in the chosen direction along the circumference. That way the polygon is guaranteed to be convex.
[QUOTE=esalaka;33126759][B]NO YOU DO NOT GET IT AT ALL.[/B] The binary flag is there only so that platforms like Windows could properly read binary files in; In text mode, on Windows, \r\n is turned into \n when reading and vice versa when writing because that's what it means - a line break. In binary mode, it's not, because in a binary file it might not be a line break at all. It has nothing to do with "writing in binary numbers". You can do that in text mode. You can do anything you want in either mode but you usually want to go text mode for text and binary mode for binary because chances are something is going to fuck up with the transforms if you don't. [editline]5th November 2011[/editline] Besides, the current standard C++ doesn't even [B]allow[/B] binary integer constants. [editline]5th November 2011[/editline] How the hell are you even giving out advice on C++ when you clearly have no idea of what you're talking about[/QUOTE] Oh, I see. I was wrong. I was misinterpreting what the binary flag does. Although, there's no need to call me stupid while calling me out.
Quick question about Java. In my code, I want my program to pause for a second or two. How does one do this?
How would I detect collisions with borders of a window in XNA?
[QUOTE=Mr. Smartass;33129417]How would I detect collisions with borders of a window in XNA?[/QUOTE] Not exactly sure how in XNA but if there's a function for returning the width and height of the window you can write something to check if the x position of the right side of the object is within 1 or 2 pixels of the window position, and the same thing for the other extreme positions of your objects in each axis. Not sure if that's what you meant, sorry I couldn't be of more help.
[QUOTE=Mr. Smartass;33129417]How would I detect collisions with borders of a window in XNA?[/QUOTE] This is a pretty vague question. What are you trying to detect collisions for? A sprite, a box, the cursor?
Sorry, you need to Log In to post a reply to this thread.