• What do you need help with? V. 3.0
    4,884 replies, posted
[QUOTE=Metroid48;30205360][url=http://www.metanetsoftware.com/technique/tutorialA.html]This[/url]?[/QUOTE] Yes, thank you.
How do I generate a number between 3 and 4? It's something like generator.nextInt(3) + 4, but I have forgotten.
[QUOTE=Staneh;30200344]I need some way to limit my framerate for my game to 60. Because I have 850 FPS atm, and my game is running like speedy gonzalez.[/QUOTE] You multiply with The DeltaFrameTime. I think you where using love so for example [lua] function love.update( dt ) -- dt = DeltaFrameTime myobject.x = myobject.x + 3 * dt -- 3 is the speed of the object we multiply this with deltaframetime. here we go from moving 3 pixels a frame to moving 3 pixels a second. end[/lua] DeltaFrameTime is the time it took the frame to render/run completely. For example if we run at 10 frames a second delta frame time will be 1/10 = 0.1 if we for example say we move the pad down when the 'down' key is down we move the object 3 pixels down. When you are not multiplying with delta frame time you will move the object 3 pixels every [b]frame[/b] on a slow pc this might be with 10 frames a second, on a fast pc this might be with a 100 frames a second. So if we multiply with dt instead of moving 3 pixels that frame it will move 3 * 0.1 = 0.3 pixels. and that way make sure we always move at the same speed a second FPS goes up, DT goes down.
[QUOTE=Smashmaster;30204236]Quick Java question: Does the number of functions a non-static class has affect its performance?[/QUOTE] On initialization-time, yes, a negligible cost. On run-time - nothing, a little bit when debugging perhaps; again negligible. [editline]3rd June 2011[/editline] [QUOTE=Staneh;30207959]How do I generate a number between 3 and 4? It's something like generator.nextInt(3) + 4, but I have forgotten.[/QUOTE] generator.nextInt(1)+3, assuming that nextInt(1) outputs a number within [0..1]. Not really rocket science o.O
[QUOTE=ZeekyHBomb;30208304]On initialization-time, yes, a negligible cost. On run-time - nothing, a little bit when debugging perhaps; again negligible. [editline]3rd June 2011[/editline] generator.nextInt(1)+3, assuming that nextInt(1) outputs a number within [0..1]. Not really rocket science o.O[/QUOTE] Yeah, sorry, i'm just really tired, and I can't think straight. [editline]2nd June 2011[/editline] Wait. This IS rocket science, your solution didn't work for me, it only generates 3 atm. Also, my way of generating them is: [cpp] Random generator = new Random(); int random1 = generator.nextInt(1) + 3;[/cpp] This always gives me 3.
[QUOTE=Staneh;30208360]Yeah, sorry, i'm just really tired, and I can't think straight. [editline]2nd June 2011[/editline] Wait. This IS rocket science, your solution didn't work for me, it only generates 3 atm. Also, my way of generating them is: [cpp] Random generator = new Random(); int random1 = generator.nextInt(1) + 3;[/cpp] This always gives me 3.[/QUOTE] [QUOTE=ZeekyHBomb;30208304]assuming that nextInt(1) outputs a number within [0..1].[/QUOTE] It probably outputs [0..1[. Or just bad luck .. you never know. int random2 = generator.nextInt(2) + 3;
This worked, thanks.
[QUOTE=NotoriousSpy;30180737]How would I move an item along a vector. I have a starting vector and a destination vector. I know how to move it in the direction, but I'm not sure how to move it directly onto the other vector, or to check when it's close (to check for overlap).[/QUOTE] By vector... do you mean coordinate? If you know how to move it in the direction (linear interpolation (lerp?)) then you must be able to just set the item's position to the destination vector, no?
With node.js, I'm trying to do a POST request and this works fine when it's done on my local server. Yet whenever I try to do it on this remote server, it just fails to connect. What makes it all the more strange is that GET requests work perfectly fine. The exact same request done using cURL in PHP works fine. I've checked and both node.js and cURL send the same request data. node.js: [cpp]var postRequest = { host: "www.facepunch.com", path: "/newreply.php?do=postreply&t=" + threadid, port: 80, method: "POST", headers: { Cookie: "cookie", 'Content-Type': 'application/x-www-form-urlencoded' } }; buffer = ""; var req = http.request( postRequest, function( res ) { console.log( res ); res.on( "data", function( data ) { buffer = buffer + data; } ); res.on( "end", function() { require( "fs" ).writeFile( "output.html", buffer ); } ); } ); var body = "postdata\r\n"; postRequest.headers["Content-Length"] = body.length; req.write( body ); req.end();[/cpp] [i]The console.log function is never actually reached.[/i] cURL: [php]<?php if ( $_SERVER["REMOTE_ADDR"] == "127.0.0.1" ) { $body = "body"; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, "http://www.facepunch.com/newreply.php?do=postreply&t=" . $threadid ); curl_setopt( $ch, CURLOPT_POST, 15 ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $body ); curl_setopt( $ch, CURLOPT_COOKIE, "cookie" ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); $result = curl_exec( $ch ); curl_close( $ch ); } ?>[/php]
[QUOTE=ZeekyHBomb;30208304]generator.nextInt(1)+3, assuming that nextInt(1) outputs a number within [0..1].[/QUOTE] nextInt(n) produces an integer, so that'll always return 0. [QUOTE=Staneh;30208360]This always gives me 3.[/QUOTE] That's because 3 is the only integer in the range you specified. You probably want to use nextFloat() instead.
Well, what I thought was, that nextInt(1) produces an integer within [0..1], meaning either 0 or 1. Since Staneh already used nextInt instead of nextFloat I presumed an integer is the desired datatype, further reassured by the code-sample given using int and not float (or different floating-point type).
I seem to be having stack troubles with a garrysmod binary module. Note that ILuaInterface hides the return values so i have no way of know how many return values there actually are, i'm assuming no one will return 100 different values. [cpp] LUA_FUNCTION( ProfileFunction ) { ILuaInterface* g_Lua = Lua(); g_Lua->CheckType( 1 , GLua::TYPE_FUNCTION ); float time = 0; timer->Start(); g_Lua->Call(g_Lua->Top() - 1, -1 ); time = timer->Stop(); int i = 0; for (i = 100 ; 0 ; i--) { ILuaObject* retval = g_Lua->GetReturn(i); if (retval == NULL) { continue; } g_Lua->Push(retval); } g_Lua->Push(time); g_Lua->Push("Testing"); return g_Lua->Top(); } [/cpp] no matter where I push the time and string "testing" they still end up getting returned last, also this is my first cpp project, please be easy.
I'm having a problem with fullscreen and SFML with OpenGL. It seems when I'm running fullscreen, everything flickers between the desktop and the fullscreen picture.
[QUOTE=ZeekyHBomb;30210327]Well, what I thought was, that nextInt(1) produces an integer within [0..1], meaning either 0 or 1.[/QUOTE] No, the upper-bound is non-inclusive. nextInt(n) is similar to nextInt()%n, except it avoids a slight bias toward lower numbers that occurs with nextInt()%n when n isn't a power of two.
[QUOTE=Mr. Smartass;30194557]I was using [url]http://www.opentk.com/project/TexLib[/url] to load textures for my openTK project, but after I had set everything up, I noticed that there were errors on every single line refrencing things that had to do with textures. What did I do wrong?[/QUOTE] Double retoast.
I have this macro: [code] #define ADD_ENTITY( EntityName, EntityClass ) \ extern "C" _declspec( dllexport ) CBaseEntity &EntityName( void ); \ CBaseEntity &EntityName( void ) { CBaseEntity *Ent = new EntityClass; return *(Ent); } [/code] Now I want to call the function "CBaseEntity &MyEntity( void )" within the same exe I used that macro in. I tried using GetProcAddress, but it keeps coming up null.
-snip-
I did PHP for five years before moving onto C++; and although there are some little things of PHP I miss... Actually I don't think there are. It doesn't really matter which you pick, once you have become fluent in one it is but a mere process of extremely fast learning to adapt to another. Personally, out of your two choices, I would choose C++ as I don't understand the syntax of Python at all - but that is, of course, personal preference - if you like the syntax of Python then perhaps you should pick that one.
-missed a page-
Can anyone help me, I'm a new programmer and I've been learning to use classes so I made a program to see if I could implement them properly (obviously not), I'm using VC++ express and I'm getting loads of errors when I debug the program.Here is the code, it's quite simple all I'm trying to do is implement classes properly before I try anything bigger, the debug log is shown at the bottom, help would be much appreciated. [url]http://pastebin.com/dF0jBCKV[/url]
Try putting #include <iostream> after #include "stdafx.h" rather than before.
Nope still getting all the same errors
Create an "Empty Project" instead.
Ah sorry Elffie your solution did work, I didn't know stdafx.h had to be before ALL of the #includes, thanks for the help it works perfectly. While i'm still talking about my program are the arguments in _tmain necessary? I haven't seen them in code blocks.
[QUOTE=Kondor58;30223457]Ah sorry Elffie your solution did work, I didn't know stdafx.h had to be before ALL of the #includes, thanks for the help it works perfectly. While i'm still talking about my program are the arguments in _tmain necessary? I haven't seen them in code blocks.[/QUOTE] No, they aren't necessary. These are both valid prototypes for your main function: [cpp]int main( int argc, const char* argv[] ); int main();[/cpp] You should always create an empty project and set things up yourself.
I need some help with farseer physics. I looked at the samples framework drawing stuff, and it's really complex. Is there some (simple..?) way to make a camera, and use it in conjunction with debugdraw such that when I move the camera, it moves what is being drawn by debugdraw, and if I zoom in, debugdraw zooms in too? When I looked at the sample framework, it was really difficult to follow the flow of the code.
I'm having some more collision trouble. I've figured out how to detect collisions between AABB's but I still don't know how to solve them. With the code I've created, everything is very buggy, it snaps a lot and it doesn't work if the rectangle is on top of the other. Please help me fix this code... [cpp] public void Think(Rect other) { float xDist = (Pos.x + Size.x / 2) - (other.Pos.x + other.Size.x / 2); float yDist = (Pos.y + Size.y / 2) - (other.Pos.y + other.Size.y / 2); float halfWs = Size.x / 2 + other.Size.x / 2; float halfHs = Size.y / 2 + other.Size.y / 2; if (halfWs > abs(xDist) && halfHs > abs(yDist)) { float xTranslate1 = halfWs - xDist; float xTranslate2 = halfWs + xDist; float yTranslate1 = halfHs - yDist; float yTranslate2 = halfHs + yDist; if (xTranslate1 > yTranslate1) { if (xTranslate1 < xTranslate2) other.Pos.x -= xTranslate1; else other.Pos.x += xTranslate2; } else { if (yTranslate1 < yTranslate2) other.Pos.y -= yTranslate1; else other.Pos.y += yTranslate2; } col = color(0, 255, 0); } else col = color(0, 0, 80); }[/cpp] (it's Processing but this is pretty much language independent) [editline]4th June 2011[/editline] Alright, now it's a bit better, but I still think I'm doing something wrong... [cpp]public void Think(Rect other) { float xDist = (Pos.x + Size.x / 2) - (other.Pos.x + other.Size.x / 2); float yDist = (Pos.y + Size.y / 2) - (other.Pos.y + other.Size.y / 2); float halfWs = Size.x / 2 + other.Size.x / 2; float halfHs = Size.y / 2 + other.Size.y / 2; if (halfWs > abs(xDist) && halfHs > abs(yDist)) { float xTranslate1 = halfWs - xDist; float xTranslate2 = halfWs + xDist; float yTranslate1 = halfHs - yDist; float yTranslate2 = halfHs + yDist; if (abs(xDist) > abs(yDist)) { if (xTranslate1 < xTranslate2) other.Pos.x -= xTranslate1; else other.Pos.x += xTranslate2; } else { if (yTranslate1 < yTranslate2) other.Pos.y -= yTranslate1; else other.Pos.y += yTranslate2; } col = color(0, 255, 0); } else col = color(0, 0, 80); }[/cpp]
So I was looking for some game engines that use C#, and I found this one; [url]http://www.neoaxis.com/[/url] . It seems too good to be true, with all of its features and what it supports. Is it? Or is it actually as good as it seems?
I'm trying to integrate Lua into a simple test application. I used the [url=http://code.google.com/p/luaforwindows/]Lua for Windows[/url] installer. When using this code: [cpp]extern "C" { #include <lua.h> #include <lualib.h> #include <lauxlib.h> } int main( int argc, char **argv ) { lua_State *L = luaL_newstate(); if ( L == NULL ) printf("\nLua state is null."); luaL_openlibs(L); if ( luaL_dofile(L, "foo.lua") != 0 ) printf("\nCouldn't find file."); printf("\nEnd lua.\n"); lua_close(L); return 0; }[/cpp] I get no compiler/linker errors. The program, however, says that it can't find the file. I tried putting the foo.lua file in the Debug folder and running the generated executable but it still says it can't find it. I looked around a bit and tried emptying the file - it can't even load an empty Lua file. Does anyone have any ideas as to why the file refuses to load?
Do printf("\nLua error: %s", lua_tostring(L, -1)); instead of printing "\nCouldn't find the file."; it could be a different problem.
Sorry, you need to Log In to post a reply to this thread.