• What do you need help with? V. 3.0
    4,884 replies, posted
C#, I've made a copy function that returns a new copy of that class with all the variables the same and everything. I use this to do some stuff on the copy and then check some things, rather than doing it on the actual class and then undoing it. The problem is that at one point after using the copy function enough times, it just returns a reference. What could cause this, and what can I do?
A bug in the function, presumably. You'll need to post the code. BTW, you don't copy a class, you copy an object (which is an instance of a class).
[QUOTE=Wyzard;33369525]A bug in the function, presumably. You'll need to post the code. BTW, you don't copy a class, you copy an object (which is an instance of a class).[/QUOTE] [code] public ChessBoard copy() { return new ChessBoard(chessBoardTile, turn, BlackQueenCastling, BlackKingCastling, WhiteQueenCastling, WhiteKingCastling, EnPassant, MovesSincePawnOrCapture, moveList); }[/code] The copy function. It is used many places, but the place where it seems to use a reference is here: [code] if (PlayerInCheck(Move(copy(), new Vector2(x, y), tilePosition)) != chessBoardTile[x, y].PieceColor) { AddMove(new Vector2(x, y), tilePosition); }[/code] PlayerInCheck(ChessBoard) returns the color of the player currently in check, if any. Move(ChessBoard, Vector2, Vector2) returns a ChessBoard where a move has been made, with the Vector2s representing the from and to coordinates. The code here is to figure out if a move is made, will it then put the moving player in check. This code is inside a loop, but only at one run-through of the loop does it use a reference. I can see it because the move is actually made on the checkboard.
Programming in Java, printed out a long[] consisting of calculated average times in nanoseconds. When I try to get an average (again) out of the times in long[], I find out they have somehow been rounded. I wonder, how can the contents of the long[] that are not rounded, suddenly become rounded? Example: In the first iteration one of the components were 4524ns. Later it was 4000ns.
[QUOTE=UnMute;33369784]Programming in Java, printed out a long[] consisting of calculated average times in nanoseconds. When I try to get an average (again) out of the times in long[], I find out they have somehow been rounded. I wonder, how can the contents of the long[] that are not rounded, suddenly become rounded? Example: In the first iteration one of the components were 4524ns. Later it was 4000ns.[/QUOTE] Sounds suspiciously like some mistake somewhere involving integer division.
I have found the source of my problem. I did not realize that I was passing another object to the constructor of the copy, and that object was a reference. This was causing the whole problem. [editline]21st November 2011[/editline] Is there no way of assigning one object to another object without it being a reference in C#?
[QUOTE=Anonim;33370030]Sounds suspiciously like some mistake somewhere involving integer division.[/QUOTE] I found out that I made an int division and changed it, but it was before I made both averages, so it made no difference. The rest was in long, so it can't be that.
Does anyone know what this could be? [code]==30830== Memcheck, a memory error detector ==30830== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==30830== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info ==30830== Command: /home/richy/codeblocks/LoP/bin/Debug/LoP ==30830== ==30830== Invalid read of size 4 ==30830== at 0x04c730f2: _mesa_make_extension_string (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04c4d5f7: _mesa_make_current (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04b73850: intelMakeCurrent (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== by 0x04b6796e: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== Address 0x484f3c8 is 0 bytes inside a block of size 1 alloc'd ==30830== at 0x0402732c: calloc (vg_replace_malloc.c:467) ==30830== by 0x04c732be: _mesa_make_extension_string (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04c4d5f7: _mesa_make_current (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04b73850: intelMakeCurrent (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== ==30830== Invalid write of size 4 ==30830== at 0x04ced6a2: ??? (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04cee5d4: _mesa_texstore (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04b86c5f: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== by 0x04b8717a: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== Address 0xb7855000 is not stack'd, malloc'd or (recently) free'd ==30830== ==30830== Syscall param writev(vector[...]) points to uninitialised byte(s) ==30830== at 0x04321d84: writev (writev.c:51) ==30830== by 0x00040004: ??? ==30830== Address 0x6ec2f9c is 36 bytes inside a block of size 16,384 alloc'd ==30830== at 0x0402732c: calloc (vg_replace_malloc.c:467) ==30830== by 0x04594551: XOpenDisplay (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) ==30830== by 0x041080d0: sf::priv::WindowImplX11::WindowImplX11(sf::VideoMode, std::string const&, unsigned long) (WindowImplX11.cpp:114) ==30830== by 0x04103524: sf::priv::WindowImpl::New(sf::VideoMode, std::string const&, unsigned int) (WindowImpl.cpp:60) ==30830== ==30830== Mismatched free() / delete / delete [] ==30830== at 0x04027c02: free (vg_replace_malloc.c:366) ==30830== by 0x0458cb18: ??? (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) ==30830== by 0x0410322a: sf::Window::SetIcon(unsigned int, unsigned int, unsigned char const*) (Window.cpp:288) ==30830== by 0x080585c4: Engine::SetupOpenGL() (Engine.cpp:94) ==30830== Address 0x8bae388 is 0 bytes inside a block of size 4,096 alloc'd ==30830== at 0x04027f65: operator ==30830== by 0x041089b6: sf::priv::WindowImplX11::SetIcon(unsigned int, unsigned int, unsigned char const*) (WindowImplX11.cpp:352) ==30830== by 0x0410322a: sf::Window::SetIcon(unsigned int, unsigned int, unsigned char const*) (Window.cpp:288) ==30830== by 0x080585c4: Engine::SetupOpenGL() (Engine.cpp:94) ==30830== ==30830== Invalid read of size 4 ==30830== at 0x04cca9d4: ??? (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04cd5bba: _mesa_get_teximage (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04b84fe7: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== by 0x04cd6995: _mesa_GetnTexImageARB (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== Address 0xb7853000 is not stack'd, malloc'd or (recently) free'd ==30830== ==30830== Invalid write of size 4 ==30830== at 0x04ced6a2: ??? (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04cee5d4: _mesa_texstore (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04b8555c: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== by 0x04b862ca: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== Address 0xb7852000 is not stack'd, malloc'd or (recently) free'd ==30830== ==30830== Conditional jump or move depends on uninitialised value(s) ==30830== at 0x04075609: sf::Renderer::SetShader(sf::Shader const*) (Renderer.cpp:255) ==30830== by 0x040770dc: sf::RenderTarget::Draw(sf::Drawable const&) (RenderTarget.cpp:83) ==30830== by 0x0805e6d4: IntroState::DrawSFML() (IntroState.cpp:86) ==30830== by 0x0805d880: IGameStateManager::DrawSFML() (IGameStateManager.cpp:93) ==30830== ==30830== Conditional jump or move depends on uninitialised value(s) ==30830== at 0x0407510d: sf::Renderer::SetBlendMode(sf::Blend::Mode) (Renderer.cpp:190) ==30830== by 0x0405c965: sf::Drawable::Draw(sf::RenderTarget&, sf::Renderer&) ==30830== by 0x040770f8: sf::RenderTarget::Draw(sf::Drawable const&) (RenderTarget.cpp:86) ==30830== by 0x0805e6d4: IntroState::DrawSFML() (IntroState.cpp:86) ==30830== ==30830== Conditional jump or move depends on uninitialised value(s) ==30830== at 0x040754e1: sf::Renderer::SetTexture(sf::Texture const*) (Renderer.cpp:236) ==30830== by 0x0407f289: sf::Sprite::Render(sf::RenderTarget&, sf::Renderer&) ==30830== by 0x0405c985: sf::Drawable::Draw(sf::RenderTarget&, sf::Renderer&) ==30830== by 0x040770f8: sf::RenderTarget::Draw(sf::Drawable const&) (RenderTarget.cpp:86) ==30830==[/code] SFML wont draw anything on linux
I want to compile this little C++ program that runs a Lua script. I always get "undefined reference" errors at the linking step, and none of the solutions I found from Googling have helped. What am I doing wrong? [code] g++ -I ../include -L../lib -c -o load-helloworld.o load-helloworld.cpp g++ -I ../include -L../lib -o load-helloworld load-helloworld.o -llua load-helloworld.o: In function `main': load-helloworld.cpp:(.text+0x62): undefined reference to `luaL_newstate()' load-helloworld.cpp:(.text+0x7a): undefined reference to `luaL_loadfile(lua_State*, char const*)' load-helloworld.cpp:(.text+0xcd): undefined reference to `lua_pushstring(lua_State*, char const*)' load-helloworld.cpp:(.text+0xe9): undefined reference to `lua_setfield(lua_State*, int, char const*)' load-helloworld.cpp:(.text+0x105): undefined reference to `lua_call(lua_State*, int, int)' load-helloworld.cpp:(.text+0x111): undefined reference to `lua_close(lua_State*)' collect2: ld returned 1 exit status make: *** [load-helloworld] Error 1 [/code]
[QUOTE=UnMute;33370123]I found out that I made an int division and changed it, but it was before I made both averages, so it made no difference. The rest was in long, so it can't be that.[/QUOTE] Long is an integral type.
[QUOTE=MegaJohnny;33370380]I want to compile this little C++ program that runs a Lua script. I always get "undefined reference" errors at the linking step, and none of the solutions I found from Googling have helped. What am I doing wrong? [code] g++ -I ../include -L../lib -c -o load-helloworld.o load-helloworld.cpp g++ -I ../include -L../lib -o load-helloworld load-helloworld.o -llua load-helloworld.o: In function `main': load-helloworld.cpp:(.text+0x62): undefined reference to `luaL_newstate()' load-helloworld.cpp:(.text+0x7a): undefined reference to `luaL_loadfile(lua_State*, char const*)' load-helloworld.cpp:(.text+0xcd): undefined reference to `lua_pushstring(lua_State*, char const*)' load-helloworld.cpp:(.text+0xe9): undefined reference to `lua_setfield(lua_State*, int, char const*)' load-helloworld.cpp:(.text+0x105): undefined reference to `lua_call(lua_State*, int, int)' load-helloworld.cpp:(.text+0x111): undefined reference to `lua_close(lua_State*)' collect2: ld returned 1 exit status make: *** [load-helloworld] Error 1 [/code][/QUOTE] You need to link against the lua library (liblua.so or liblua5.1.so)
In C# you can populate some collections like this: [csharp]int[] numbers = new int[]{ 1, 2, 3, 4 }; List<int> moNumbers = new List<int>(){ 1, 2, 3, 4 }; Dictionary<int, int> numbars = new Dictionary<int, int>(){ { 1, 2 }, { 2, 3 }, { 3, 4 } };[/csharp] And so on. Is there a way to utilize this in my own classes? Or is it limited to only the classes in the standard library?
[QUOTE=Ziks;33373333]In C# you can populate some collections like this: [csharp]int[] numbers = new int[]{ 1, 2, 3, 4 }; List<int> moNumbers = new List<int>(){ 1, 2, 3, 4 }; Dictionary<int, int> numbars = new Dictionary<int, int>(){ { 1, 2 }, { 2, 3 }, { 3, 4 } };[/csharp] And so on. Is there a way to utilize this in my own classes? Or is it limited to only the classes in the standard library?[/QUOTE] According to [url]http://msdn.microsoft.com/en-us/library/bb384062.aspx[/url], you can do stuff like [cpp] List<Cat> cats = new List<Cat> { new Cat(){ Name = "Sylvester", Age=8 }, new Cat(){ Name = "Whiskers", Age=2 }, new Cat(){ Name = "Sasha", Age=14 } }; [/cpp] (borrowed their example)
[QUOTE=calzoneman;33373408]According to [url]http://msdn.microsoft.com/en-us/library/bb384062.aspx[/url], you can do stuff like [cpp] List<Cat> cats = new List<Cat> { new Cat(){ Name = "Sylvester", Age=8 }, new Cat(){ Name = "Whiskers", Age=2 }, new Cat(){ Name = "Sasha", Age=14 } }; [/cpp] (borrowed their example)[/QUOTE] I meant if I created my own collection type, if there would be a way to override the {} to populate it.
Going off the top of my head. I remember reading that C++0x has something called initializer list, which does exactly that. [editline]21st November 2011[/editline] Looking at C#, I'm not sure if you can make your own initializer list, which is a bit weird.
[QUOTE=Ziks;33373424]I meant if I created my own collection type, if there would be a way to override the {} to populate it.[/QUOTE] I would look into extending one of the interfaces on [url=http://msdn.microsoft.com/en-us/library/ybcx56wz(v=vs.80).aspx]this page[/url]
I found the answer, you need to implement IEnumerable and the Add() function. Which is a bit odd if you don't want your class to be enumerable or the operation you perform on all the items in the set can't be described as "adding" them.
[QUOTE=Map in a box;33368024]My socket seems to not be sending anything, I make one client and on the second connect to the server the server doesn't send the entities but does send the map name and etc. I even tried with 2 separate clients. I don't know why it does this since each client is handled separately. I don't know what I should be showing for this so please tell me what I should show first.[/QUOTE] Adding on to this, when I added a disconnect function(which removes the client from the client list/closes the socket) onto the server and client, whenever I reconnect on the client it loads all the entities and stuff now. I have no idea why, either.
What is the best way to parse HTML in Python 3? I need to get the value between a span tag that has a class set.
If it's XHTML, parse it as XML
[QUOTE=Richy19;33370309]Does anyone know what this could be? [code]==30830== Memcheck, a memory error detector ==30830== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==30830== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info ==30830== Command: /home/richy/codeblocks/LoP/bin/Debug/LoP ==30830== ==30830== Invalid read of size 4 ==30830== at 0x04c730f2: _mesa_make_extension_string (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04c4d5f7: _mesa_make_current (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04b73850: intelMakeCurrent (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== by 0x04b6796e: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== Address 0x484f3c8 is 0 bytes inside a block of size 1 alloc'd ==30830== at 0x0402732c: calloc (vg_replace_malloc.c:467) ==30830== by 0x04c732be: _mesa_make_extension_string (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04c4d5f7: _mesa_make_current (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04b73850: intelMakeCurrent (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== ==30830== Invalid write of size 4 ==30830== at 0x04ced6a2: ??? (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04cee5d4: _mesa_texstore (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04b86c5f: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== by 0x04b8717a: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== Address 0xb7855000 is not stack'd, malloc'd or (recently) free'd ==30830== ==30830== Syscall param writev(vector[...]) points to uninitialised byte(s) ==30830== at 0x04321d84: writev (writev.c:51) ==30830== by 0x00040004: ??? ==30830== Address 0x6ec2f9c is 36 bytes inside a block of size 16,384 alloc'd ==30830== at 0x0402732c: calloc (vg_replace_malloc.c:467) ==30830== by 0x04594551: XOpenDisplay (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) ==30830== by 0x041080d0: sf::priv::WindowImplX11::WindowImplX11(sf::VideoMode, std::string const&, unsigned long) (WindowImplX11.cpp:114) ==30830== by 0x04103524: sf::priv::WindowImpl::New(sf::VideoMode, std::string const&, unsigned int) (WindowImpl.cpp:60) ==30830== ==30830== Mismatched free() / delete / delete [] ==30830== at 0x04027c02: free (vg_replace_malloc.c:366) ==30830== by 0x0458cb18: ??? (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) ==30830== by 0x0410322a: sf::Window::SetIcon(unsigned int, unsigned int, unsigned char const*) (Window.cpp:288) ==30830== by 0x080585c4: Engine::SetupOpenGL() (Engine.cpp:94) ==30830== Address 0x8bae388 is 0 bytes inside a block of size 4,096 alloc'd ==30830== at 0x04027f65: operator ==30830== by 0x041089b6: sf::priv::WindowImplX11::SetIcon(unsigned int, unsigned int, unsigned char const*) (WindowImplX11.cpp:352) ==30830== by 0x0410322a: sf::Window::SetIcon(unsigned int, unsigned int, unsigned char const*) (Window.cpp:288) ==30830== by 0x080585c4: Engine::SetupOpenGL() (Engine.cpp:94) ==30830== ==30830== Invalid read of size 4 ==30830== at 0x04cca9d4: ??? (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04cd5bba: _mesa_get_teximage (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04b84fe7: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== by 0x04cd6995: _mesa_GetnTexImageARB (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== Address 0xb7853000 is not stack'd, malloc'd or (recently) free'd ==30830== ==30830== Invalid write of size 4 ==30830== at 0x04ced6a2: ??? (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04cee5d4: _mesa_texstore (in /usr/lib/i386-linux-gnu/dri/libdricore.so) ==30830== by 0x04b8555c: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== by 0x04b862ca: ??? (in /usr/lib/i386-linux-gnu/dri/i965_dri.so) ==30830== Address 0xb7852000 is not stack'd, malloc'd or (recently) free'd ==30830== ==30830== Conditional jump or move depends on uninitialised value(s) ==30830== at 0x04075609: sf::Renderer::SetShader(sf::Shader const*) (Renderer.cpp:255) ==30830== by 0x040770dc: sf::RenderTarget::Draw(sf::Drawable const&) (RenderTarget.cpp:83) ==30830== by 0x0805e6d4: IntroState::DrawSFML() (IntroState.cpp:86) ==30830== by 0x0805d880: IGameStateManager::DrawSFML() (IGameStateManager.cpp:93) ==30830== ==30830== Conditional jump or move depends on uninitialised value(s) ==30830== at 0x0407510d: sf::Renderer::SetBlendMode(sf::Blend::Mode) (Renderer.cpp:190) ==30830== by 0x0405c965: sf::Drawable::Draw(sf::RenderTarget&, sf::Renderer&) ==30830== by 0x040770f8: sf::RenderTarget::Draw(sf::Drawable const&) (RenderTarget.cpp:86) ==30830== by 0x0805e6d4: IntroState::DrawSFML() (IntroState.cpp:86) ==30830== ==30830== Conditional jump or move depends on uninitialised value(s) ==30830== at 0x040754e1: sf::Renderer::SetTexture(sf::Texture const*) (Renderer.cpp:236) ==30830== by 0x0407f289: sf::Sprite::Render(sf::RenderTarget&, sf::Renderer&) ==30830== by 0x0405c985: sf::Drawable::Draw(sf::RenderTarget&, sf::Renderer&) ==30830== by 0x040770f8: sf::RenderTarget::Draw(sf::Drawable const&) (RenderTarget.cpp:86) ==30830==[/code] SFML wont draw anything on linux[/QUOTE] What graphics drivers do you have, and are you loading the textures/sprites appropriately?
[QUOTE=vexx21322;33374889]What is the best way to parse HTML in Python 3? I need to get the value between a span tag that has a class set.[/QUOTE] [url=http://www.crummy.com/software/BeautifulSoup/]BeautifulSoup[/url] is good, unless you want validation too.
Trying to make a freely movable camera in OpenGL, I have two 3d vectors determining the position of the camera and the position where it is looking at, so far I figured out how to "zoom in" and "zoom out" towards that point (decrease vector length then move view point further away). Trying to figure out how to rotate the camera though, my guess is that I'm gonna have to rotate the point where the camera is looking at around the position of the camera, right?
I'm using python and I am having a problem with the def that I'm making. What I think is happening is that when usrInput is called recursively it is being buried in the functions recursive namespace so it cant return the value back to the main namespace. I don't know how to fix this please help. Code: [code] def numericTest(go): usrInput = raw_input('Number: ') try: bob = int(usrInput) except ValueError, TypeError: numericTest(go) else: return int(usrInput) print numericTest(0) [/code] Console: [code] >>> Number: f Number: 3 None >>> [/code]
[QUOTE=DeanWinchester;33376786]Trying to figure out how to rotate the camera though, my guess is that I'm gonna have to rotate the point where the camera is looking at around the position of the camera, right?[/QUOTE] Yes, or you could point it in this direction. [code] X = change in X input Y = change in Y input CameraDirection = ( sin(X)*cos(Y), cos(X)*cos(Y) , sin(Y) ) [/code]
[QUOTE=Dark7533;33377438]I'm using python and I am having a problem with the def that I'm making. What I think is happening is that when usrInput is called recursively it is being buried in the functions recursive namespace so it cant return the value back to the main namespace. I don't know how to fix this please help. Code: [code] def numericTest(go): usrInput = raw_input('Number: ') try: bob = int(usrInput) except ValueError, TypeError: numericTest(go) else: return int(usrInput) print numericTest(0) [/code] Console: [code] >>> Number: f Number: 3 None >>> [/code][/QUOTE] Why use recursion for that, just make a loop and continually take input. You only use recursion when you pass a different argument to it that's generated in the function itself. (such as the factorial function)
Anyone have experience with Ogg theora encoding? I don't know why my encoded Ogg doesn't work properly in Chrome: [vid]http://triebr.com/Test.ogv[/vid] If your not using chrome, it looks like this: [IMG]http://i.imgur.com/LQveU.png[/IMG]
First things first: This is not for any kind of homework. I'm currently trying to implement CSS3-like cubic bezier stuff into a C# program that does pretty color transitions, but fail due to my lacking knowledge of cubic bezier curves. In fact, I have never heard of them until today. Assuming that they basically consist of four points with X and Y values that are between 0 and 1, and that the first and last points are (0, 0) and (1, 1) respectively, how would I calculate the Y value for a given X if points 2 and 3 had these X and Y values? Point 2: (0.42, 0) Point 3: (1, 1) Point 2: (0, 0) Point 3: (0.58, 1) Point 2: (0.42, 0) Point 3: (0.58, 1) (Before you go "BUT Y CAN HAVE MULTIPLE VALUES UNDER CERTAIN CIRCUMSTANCES", yeah, I know. But I'm not trying to achieve pinpoint accuracy, it just needs to be accurate [i]enough[/i].) There has to be some kind of formula that allows me to insert X somewhere, calculate a bit and then get Y. Please explain this for dummies, as I really don't know shit about this. Oh, and I found this link already: [url]http://paulbourke.net/miscellaneous/interpolation/[/url] but it's not really helping me since I have two points = X1, Y1, X2, Y2 and not four points = Y0-3. [editline]22nd November 2011[/editline] [QUOTE=thisBrad;33377615]Anyone have experience with Ogg theora encoding? I don't know why my encoded Ogg doesn't work properly in Chrome: [vid]http://triebr.com/Test.ogv[/vid][/QUOTE] As far as I know, only Firefox supported OGG stuff. I think you have to use H264 video for Chrome. (Editedit: Your video works fine in my Firefox, it doesn't look like your screenshot.)
[QUOTE=Octave;33377529]Why use recursion for that, just make a loop and continually take input. You only use recursion when you pass a different argument to it that's generated in the function itself. (such as the factorial function)[/QUOTE] It looks nicer this way and I don't have to use an extra variable for the loop. Edit: I will just use the while loop method for now. But does any one know how to get it to return usrInput with the recursive method
[QUOTE=Jookia;33375690]What graphics drivers do you have, and are you loading the textures/sprites appropriately?[/QUOTE] Sorry what I should have said was that SFML wont work with openGL. However the example does work(the one that uses deprecated openGL) Im using the generic ones (I have an intel GMA? so it wont display the option to use propetary drivers) How do you mean appropriately? this is how i use images with openGL [cpp]#include "./3dSprite.hpp" #include <glm/gtc/matrix_transform.hpp> #include <glm/gtx/transform.hpp> #include <math.h> d3Sprite::d3Sprite( glm::vec3 pos) { std::cout << "Building shader" << std::endl; shader = Shader("./vert.vert" ,"./frag.frag"); std::cout << "Building img" << std::endl; sf::Image img; img.LoadFromFile("./pedro.png"); position = pos; mPosition = glm::vec3(0.0f); alphaAmount = 0.0f; rotation = glm::vec3(0.0f); mRotation = glm::vec3(0.0f); rotating = false; //img.FlipVertically(); UVList[0] = 1.0f; UVList[1] = 0.0f; UVList[2] = 0.0f; UVList[3] = 0.0f; UVList[4] = 0.0f; UVList[5] = 1.0f; UVList[6] = 1.0f; UVList[7] = 0.0f; UVList[8] = 0.0f; UVList[9] = 1.0f; UVList[10] = 1.0f; UVList[11] = 1.0f; vertexList[0] = 0.5f; vertexList[1] = 1.0f; vertexList[2] = 0.0f; vertexList[3] = -0.5f; vertexList[4] = 1.0f; vertexList[5] = 0.0f; vertexList[6] = -0.5f; vertexList[7] = 0.0f; vertexList[8] = 0.0f; vertexList[9] = 0.5f; vertexList[10] = 1.0f; vertexList[11] = 0.0f; vertexList[12] = -0.5f; vertexList[13] = 0.0f; vertexList[14] = 0.0f; vertexList[15] = 0.5f; vertexList[16] = 0.0f; vertexList[17] = 0.0f; std::cout << "Building buffers" << std::endl; // Generate 1 buffer, put the resulting identifier in vertexbuffer glGenBuffers(1, &vertexbuffer); // The following commands will talk about our 'vertexbuffer' buffer glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); // Give our vertices to OpenGL. glBufferData(GL_ARRAY_BUFFER, sizeof(vertexList), vertexList, GL_STATIC_DRAW); MatrixID = glGetUniformLocation(shader.shaderID, "MVP"); AlphaID = glGetUniformLocation(shader.shaderID, "Alpha"); positionID = glGetAttribLocation(shader.shaderID, "Position"); TextureID = glGetUniformLocation(shader.shaderID, "myTexture"); UVID = glGetAttribLocation(shader.shaderID, "UV"); glGenBuffers(1, &uvbuffer); glBindBuffer(GL_ARRAY_BUFFER, uvbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(UVList), UVList, GL_STATIC_DRAW); glGenTextures(1, &texturebuffer); // "Bind" the newly created texture : all future texture functions will modify this texture glBindTexture(GL_TEXTURE_2D, texturebuffer); // Give the image to OpenGL glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, img.GetWidth(), img.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,img.GetPixelsPtr() ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } d3Sprite::~d3Sprite() { // Cleanup VBO and shader glDeleteBuffers(1, &vertexbuffer); glDeleteBuffers(1, &uvbuffer); glDeleteTextures(1, &texturebuffer); } void d3Sprite::Initiate(glm::mat4 *persMat, glm::mat4 *camMat) { Drawable::Initiate(persMat, camMat); } void d3Sprite::Update(sf::RenderWindow &App, bool blah ) { if(alphaAmount < 0.0f) alphaAmount = 0.0f; if(alphaAmount > 1.0f) alphaAmount = 1.0f; if(rotation.y > 1.0f) { rotating = true; rotation.y -= 0.5f * App.GetFrameTime(); mRotation.y += 0.5f * App.GetFrameTime(); } else if(rotation.y < -1.0f) { rotating = true; rotation.y += 0.5f * App.GetFrameTime(); mRotation.y -= 0.5f * App.GetFrameTime(); } else { mRotation.y += rotation.y; rotation.y = 0.0f; rotating = false; } if(rotating == false) mPosition = position; else position = mPosition; glm::mat4 modelTranslate = glm::translate( glm::mat4(1.0f), mPosition) ; glm::mat4 modelRotate = glm::rotate( glm::mat4(1.0f), mRotation.y, glm::vec3(0.0f, 1.0f, 0.0f)); modelMatrix = (modelTranslate * modelRotate) * modelRotate; if(blah) { /*glm::mat4 camTranslate = glm::translate( modelTranslate , glm::vec3(0.0f, 3.0f, 5.0f) ); glm::mat4 lookAtCam = glm::lookAt( glm::vec3(0.0f, 3.0f, 5.0f), // Camera is here glm::vec3( 0, 0, 5 ); glm::vec3(0.0f), // and looks here : at the same position, plus "direction" glm::vec3( 0, 1, 0 ) // Head is up (set to 0,-1,0 to look upside-down) ); glm::mat4 camRotate = glm::rotate( glm::mat4(1.0f) , mRotation.y * -1, glm::vec3(0.0f, 1.0f, 0.0f)); engine->cameraMatrix = modelTranslate * lookAtCam * camRotate;// camRotate;// (camTranslate); */ if((((int)(mRotation.y / 90.0f)) % 2) == 0) { *cameraMatrix = glm::lookAt( mPosition + glm::vec3(0.0f, 3.0f, 5.0f), // Camera is here glm::vec3( 0, 0, 5 ); mPosition, // and looks here : at the same position, plus "direction" glm::vec3( 0, 1, 0 ) // Head is up (set to 0,-1,0 to look upside-down) ); } else { *cameraMatrix = glm::lookAt( mPosition + glm::vec3(0.0f, 3.0f, -5.0f), // Camera is here glm::vec3( 0, 0, 5 ); mPosition, // and looks here : at the same position, plus "direction" glm::vec3( 0, 1, 0 ) // Head is up (set to 0,-1,0 to look upside-down) ); } } Drawable::Update(); modelMatrix = glm::mat4(1.0f); } void d3Sprite::Draw() { glUseProgram(shader.shaderID); glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]); glUniform1f(AlphaID , alphaAmount); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texturebuffer); glUniform1i(TextureID, 0); // 1rst attribute buffer : vertices glEnableVertexAttribArray(positionID); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( positionID, // attribute 0. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : UVs glEnableVertexAttribArray(UVID); glBindBuffer(GL_ARRAY_BUFFER, uvbuffer); glVertexAttribPointer( UVID, // attribute. No particular reason for 1, but must match the layout in the shader. 2, // size : U+V => 2 GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Send our transformation to the currently bound shader, // in the "MVP" uniform // For each model you render, since the MVP will be different (at least the M part) // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 6); // Starting from vertex 0; 3 vertices total -> 1 triangle glDisableVertexAttribArray(UVID); glDisableVertexAttribArray(positionID); }[/cpp] btw this is what happens with the app [video=youtube;IC9K70EnOeg]http://www.youtube.com/watch?v=IC9K70EnOeg[/video]
Sorry, you need to Log In to post a reply to this thread.