• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=Gmod4ever;35844421]Well, I decided to take your suggestion and do that. I modified the [b]SoundManager_Object[/b] to look as such (.h, then .cpp): [code]class ManagerObject_Sound { public: string filepath; sf::SoundBuffer buffer; sf::Sound SoundInstance; ManagerObject_Sound(string); sf::SoundBuffer &GetBuffer(); bool IsCorrectBuffer(string); };[/code] [code]ManagerObject_Sound::ManagerObject_Sound(string fpath) { filepath = fpath; buffer.LoadFromFile(fpath); sf::Sound SoundInstance(buffer); SoundInstance.SetBuffer(buffer); SoundInstance.SetVolume(100); SoundInstance.SetPitch(1); SoundInstance.SetLoop(true); SoundInstance.SetPosition(0,0,0); SoundInstance.SetRelativeToListener(false); SoundInstance.SetMinDistance(1); SoundInstance.SetAttenuation(1); SoundInstance.Play(); cout << "MO_Sound created and sound played from buffer loaded from path (" << fpath << "). Status: " << SoundInstance.GetStatus() << ", Duration: " << buffer.GetDuration() << std::endl; };[/code] And it compiles fine, but as soon as it starts to play a sound, well... [t]http://dl.dropbox.com/u/8416055/WellThen.png[/t] And this is after an error window comes up saying something about an access violation reading location :v: And about the way I manage sprites... Yeah... I haven't gotten to making a sprite manager yet. I wanted to do sounds first, because there's less involved in testing those. :v:[/QUOTE] I'm not sure why it crashes, but you forgot to remove the "sf::Sound SoundInstance(buffer);" line from the constructor, so you're still not using the one that is stored in the class. Remove that line and it should work.
[QUOTE=Funley;35834432]I have a 3D "dungeon" in XNA. The walls have individual BoundingBoxes around them. I also have a player, that is moved with velocityX and velocityZ. How can i make realistic collisions with having only one BoundingBox/Sphere around the player? This is how i move the player: [code]int velocityX = 0; int velocityZ = 0; if (ks.IsKeyDown(Keys.W)) { velocityZ = 1; } if (ks.IsKeyDown(Keys.S)) { velocityZ = -1; } if (ks.IsKeyDown(Keys.A)) { velocityX = 1; } if (ks.IsKeyDown(Keys.D)) { velocityX = -1; } cameraPos += (cameraRotation.Forward * currentSpeed * elapsedTime) * velocityZ; cameraPos += (cameraRotation.Left * currentSpeed * elapsedTime) * velocityX; velocityZ = 0; velocityX = 0;[/code] I am already generating the BoundingBoxes around the walls and i can access them very easily. I also have a function to test if a BoundingBox is colliding with another.[/QUOTE] Not sure if you've already figured this out yet, but the general idea is to move the player forwards, test if the bounding boxes are intersecting, and if so move him back. That's how I do it at least. So long as it's all done before the frame is rendered, so you don't visually see the player moving inside the wall and bouncing back.
[QUOTE=Z_guy;35844474]I'm not sure why it crashes, but you forgot to remove the "sf::Sound SoundInstance(buffer);" line from the constructor, so you're still not using the one that is stored in the class. Remove that line and it should work.[/QUOTE] Fair enough. Commented out that line from the constructor. It doesn't crash any more, but now it's right back to where we had begun. Also fun fact, when it was crashing, if I pressed "continue" fast enough through the horde of error popups that came up, I could actually hear my sound play - it only played a fraction of a second at a time, in the time it took for one message box to close and another to open, but it [b]was[/b] playing. :v:
[QUOTE=Gmod4ever;35844533]Fair enough. Commented out that line from the constructor. It doesn't crash any more, but now it's right back to where we had begun. Also fun fact, when it was crashing, if I pressed "continue" fast enough through the horde of error popups that came up, I could actually hear my sound play - it only played a fraction of a second at a time, in the time it took for one message box to close and another to open, but it [b]was[/b] playing. :v:[/QUOTE] Can you show the code where you're creating your ManagerObject_Sound instance?
Yeah, no problem. It's being made in the [b]Manager_Sound[/b], shown below. As always, .h then .cpp. [code]class Manager_Sound { public: int CachedBufferIndex; std::vector<ManagerObject_Sound> ObjectVector; Manager_Sound(); void ResetCachedBuffer(); void CacheBufferIndex(string); bool HasBuffer(string); bool PlaySoundInternal(string,bool,float,float,float,float,float,bool,float,float); // Holy overload (will have lots of overloads when everything is wroking) bool PlaySound(string); };[/code] [code]bool Manager_Sound::PlaySoundInternal(string fpath,bool loop,float pitch, float volume,float x, float y, float z,bool disable_spatialization, float mindist, float atten) { bool NewBuffer = false; CacheBufferIndex(fpath); if (!HasBuffer(fpath)) // We don't have a buffer for this? We better make one! { // First create the object and push it ManagerObject_Sound bufferObj(fpath); ObjectVector.push_back(bufferObj); // Then use it to play a sound sf::Sound SoundInstance(bufferObj.GetBuffer()); SoundInstance.SetBuffer(bufferObj.GetBuffer()); SoundInstance.SetVolume(volume); SoundInstance.SetPitch(pitch); SoundInstance.SetLoop(loop); SoundInstance.SetPosition(x,y,z); SoundInstance.SetRelativeToListener(disable_spatialization); SoundInstance.SetMinDistance(mindist); SoundInstance.SetAttenuation(atten); SoundInstance.Play(); NewBuffer = true; } else { // We already have a buffer for this; just use that buffer ManagerObject_Sound bufferObj = ObjectVector[CachedBufferIndex]; // Then use it to play a sound sf::Sound SoundInstance(bufferObj.GetBuffer()); SoundInstance.SetVolume(volume); SoundInstance.SetPitch(pitch); SoundInstance.SetLoop(loop); SoundInstance.SetPosition(x,y,z); SoundInstance.SetRelativeToListener(disable_spatialization); SoundInstance.SetMinDistance(mindist); SoundInstance.SetAttenuation(atten); SoundInstance.Play(); NewBuffer = false; } // At the end of the day, return whether or not we had to make a new buffer. return NewBuffer; } bool Manager_Sound::PlaySound(string fpath) { return PlaySoundInternal(fpath,false,1.f,100.f,0.f,0.f,0.f,true,1,1); }[/code]
[QUOTE=Gmod4ever;35844746]Yeah, no problem. It's being made in the [B]Manager_Sound[/B], shown below. As always, .h then .cpp. [code]-snip-[/code][/QUOTE] Okay, I think I've figured it out. Look at these two lines: [code]ManagerObject_Sound bufferObj(fpath); ObjectVector.push_back(bufferObj);[/code] In the first line you are creating an instance of ManagerObject_Sound and the constructor is called. In the second line you are calling push_back(), which is creating a copy of bufferObj (calling the copy constructor, which doesn't play the sound). Then after the function ends, the original bufferObj is destroyed, thus destroying the sf::Sound that is playing. What you should do is moving the code in the constructor to a separate method (let's say Init()) and call that like this: [code]ObjectVector.push_back(ManagerObject_Sound()); ManagerObject_Sound &bufferObj = ObjectVector.back(); bufferObj.Init();[/code]
Okay, I understood most of that. I'm not quite sure what you mean by "the code in the constructor," though. Here's what I did, though. Firstly, I removed the debug code from [b]ManagerObject_Sound[/b], so it looks like this now (.h and .cpp): [code]class ManagerObject_Sound { public: string filepath; sf::SoundBuffer buffer; ManagerObject_Sound(string); sf::SoundBuffer &GetBuffer(); bool IsCorrectBuffer(string); };[/code] [code]ManagerObject_Sound::ManagerObject_Sound(string fpath) { filepath = fpath; buffer.LoadFromFile(fpath); };[/code] So, now it's back to what it was originally and what I want to look like (roughly; I'll change it as needed to get it working :v:). Then, in my [b]Manager_Sound[/b], I changed it from this: [code] // First create the object and push it ManagerObject_Sound bufferObj(fpath); ObjectVector.push_back(bufferObj);[/code] To this: [code]// First create the object and push it ObjectVector.push_back(ManagerObject_Sound(fpath)); ManagerObject_Sound &bufferObj = ObjectVector.back();[/code] Which looks more or less like what you suggested. I'm just not exactly sure what all code you want me to scoop out of the constructor and put into its own method. Just for clarification, [b]Sound_Manager.cpp[/b]'s relevant code is now as thus: [code]bool Manager_Sound::PlaySoundInternal(string fpath,bool loop,float pitch, float volume,float x, float y, float z,bool disable_spatialization, float mindist, float atten) { bool NewBuffer = false; CacheBufferIndex(fpath); if (!HasBuffer(fpath)) // We don't have a buffer for this? We better make one! { // First create the object and push it //ManagerObject_Sound bufferObj(fpath); //ObjectVector.push_back(bufferObj); ObjectVector.push_back(ManagerObject_Sound(fpath)); ManagerObject_Sound &bufferObj = ObjectVector.back(); // Then use it to play a sound sf::Sound SoundInstance(bufferObj.GetBuffer()); SoundInstance.SetBuffer(bufferObj.GetBuffer()); SoundInstance.SetVolume(volume); SoundInstance.SetPitch(pitch); SoundInstance.SetLoop(loop); SoundInstance.SetPosition(x,y,z); SoundInstance.SetRelativeToListener(disable_spatialization); SoundInstance.SetMinDistance(mindist); SoundInstance.SetAttenuation(atten); SoundInstance.Play(); NewBuffer = true; } else { // We already have a buffer for this; just use that buffer ManagerObject_Sound bufferObj = ObjectVector[CachedBufferIndex]; // Then use it to play a sound sf::Sound SoundInstance(bufferObj.GetBuffer()); SoundInstance.SetVolume(volume); SoundInstance.SetPitch(pitch); SoundInstance.SetLoop(loop); SoundInstance.SetPosition(x,y,z); SoundInstance.SetRelativeToListener(disable_spatialization); SoundInstance.SetMinDistance(mindist); SoundInstance.SetAttenuation(atten); SoundInstance.Play(); NewBuffer = false; } // At the end of the day, return whether or not we had to make a new buffer. return NewBuffer; }[/code] However, there [b]still[/b] is no sound. Thanks a lot for all the help, by the way. You guys have no idea how much this means to me. Now I just wish we can get it working soon. [editline]fish[/editline] [b][highlight]HOT[/highlight][/b] I also made it so the "SoundInstance" is created and stored in the class declaration (to "keep it alive"), and now the sound plays when the buffer is made. Yay. Also set up the "buffer already exists" to work similarly, but unfortunately, it's not yet working. Progress, though! [editline]6th May 2012[/editline] Now that I got that working, and I am onto getting the cached buffer method to work, here's what I got. [b]Manager_Sound (.h then .cpp)[/b] (There's new, relevant code now! Honest!) [code]class Manager_Sound { public: int CachedBufferIndex; std::vector<ManagerObject_Sound> ObjectVector; sf::Sound SoundInstance; Manager_Sound(); void ResetCachedBuffer(); void CacheBufferIndex(string); bool HasBuffer(string); bool PlaySoundInternal(string,bool,float,float,float,float,float,bool,float,float); // Holy overload bool PlaySound(string); };[/code] [code]void Manager_Sound::CacheBufferIndex(string fpath) { int i; for (i=0; ObjectVector.size(); i++) { if (ObjectVector[i].IsCorrectBuffer(fpath)) { CachedBufferIndex = i; break; } } } bool Manager_Sound::HasBuffer(string fpath) { return !(CachedBufferIndex==MANAGER_NULL_INDEX); } bool Manager_Sound::PlaySoundInternal(string fpath,bool loop,float pitch, float volume,float x, float y, float z,bool disable_spatialization, float mindist, float atten) { bool NewBuffer = false; CacheBufferIndex(fpath); if (!HasBuffer(fpath)) // We don't have a buffer for this? We better make one! { // You know what's here... This part is working. I won't post it AGAIN and clutter this page even more than I already have. } else { // We already have a buffer for this; just use that buffer ManagerObject_Sound bufferObj = ObjectVector[CachedBufferIndex]; // Then use it to play a sound //sf::Sound SoundInstance(bufferObj.GetBuffer()); SoundInstance.SetBuffer(bufferObj.GetBuffer()); SoundInstance.SetVolume(volume); SoundInstance.SetPitch(pitch); SoundInstance.SetLoop(loop); SoundInstance.SetPosition(x,y,z); SoundInstance.SetRelativeToListener(disable_spatialization); SoundInstance.SetMinDistance(mindist); SoundInstance.SetAttenuation(atten); SoundInstance.Play(); NewBuffer = false; } // At the end of the day, return whether or not we had to make a new buffer. return NewBuffer; }[/code] [b]ManagerObject_Sound.cpp[/b] [code]bool ManagerObject_Sound::IsCorrectBuffer(string fpath) { return (filepath==fpath); };[/code] As far as I know, the ObjectVector.back(); method and this method should be returning the same thing.
[QUOTE=Gmod4ever;35844944]Now that I got that working, and I am onto getting the cached buffer method to work, here's what I got. -snip- As far as I know, the ObjectVector.back(); method and this method should be returning the same thing.[/QUOTE] This line: [code]ManagerObject_Sound bufferObj = ObjectVector[CachedBufferIndex];[/code] You are creating a copy of the ManagerObject_Sound (which gets destroyed when the function ends). Create a reference instead: [code]ManagerObject_Sound &bufferObj = ObjectVector[CachedBufferIndex];[/code]
Oh wow I feel stupid. Could have sworn I made sure I did that... [img]http://dl.dropbox.com/u/8416055/FacepunchEmots/Saddowns.gif[/img] Thanks again, guys. It works beautifully. Now I'm off to continue my endeavors, since this challenge has finally been overcome. The lesson of the day is pointers are my friend, and I should use them.
[QUOTE=dvondrake;35844507]Not sure if you've already figured this out yet, but the general idea is to move the player forwards, test if the bounding boxes are intersecting, and if so move him back. That's how I do it at least. So long as it's all done before the frame is rendered, so you don't visually see the player moving inside the wall and bouncing back.[/QUOTE] Do you mean to move the player back to the point where he was before collision or just move it backwards one time?
I'm trying (and failing) to create a 2D array of Java.awt rectangles, no clue what's going on... [lua]/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package lab4_2; import javax.swing.*; import java.awt.*; /** * * @author Kyle */ public class Lab4_2 { /** * @param args the command line arguments */ public static void main(String[] args) { GameBoard game = new GameBoard(); final int XSIZE = 195, YSIZE = 215; //frame size JFrame win = new JFrame("Tic Tac Toe"); win.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); win.setBounds(0, 0, XSIZE, YSIZE); Rectangle panels[][] = new Rectangle[2][2]; //Array int count1 = 0, count2, colourCount = 0; //colourCount is to determine which rectangle will be red or black while(count1 <= 2) { count2 = 0; while(count2 <= 2) { //Colour choice if(colourCount % 2 == 0) { panels[count1][count2].setColor(Color.BLACK); } else { panels[count1][count2].setColor(Color.RED); } //Create rectangle panels[count1][count2].fillRect(count1*(XSIZE/3), count2*(YSIZE/3), XSIZE/3, YSIZE/3); colourCount++; count2++; } } //Add to window count1 = 0; while (count1 <=2) { count2 = 0; while (count2 <= 2) { win.getContentPane().add(panels[count1][count2]); count2++; } count1++; } win.pack(); win.setVisible(true); } } [/lua] Any clue what's wrong?
In Java for arrays I believe its typename[][] variablename rather than typename variablename[][] when initializing an array.
[QUOTE=darkrei9n;35845927]In Java for arrays I believe its typename[][] variablename rather than typename variablename[][] when initializing an array.[/QUOTE] I don't think so, I've used arrays in the past and have always done it like this, only difference is that they were String arrays rather than Rectangle Arrays
[QUOTE=download;35846017]I don't think so, I've used arrays in the past and have always done it like this, only difference is that they were String arrays rather than Rectangle Arrays[/QUOTE] Check the documentation. Just looked at it, it should be rectangle[][]
[QUOTE=Richy19;35835192]Does anyone have by any chance a sample premake4 script file for creating dynamic libraries?[/QUOTE] [code] solution "SOLUTION" project "PROJ" kind "SharedLib" -- Dynamic Library --kind "StaticLib" -- Static Library --kind "WindowedApp" -- No console window --kind "ConsoleApp" -- Console Window [/code] I assume you know the rest?
[QUOTE=darkrei9n;35846060]Check the documentation. Just looked at it, it should be rectangle[][][/QUOTE] If that was the problem I'll be so fucked off :v: [editline]6th May 2012[/editline] Nope, not working [editline]6th May 2012[/editline] Netbeans won't recognise "rectangle", but it will "Rectangle"
[code] for(int i = 0; i <= window.getSize().x; i++) { int a = window.getSize().y; int b = window.getSize().x; sf::Vertex vertices[] = { sf::Vertex(sf::Vector2f( i, 0), sf::Color::Green, sf::Vector2f( 0, 0)), sf::Vertex(sf::Vector2f( i, a - ((a>b)?b:a / (a<b)?b:a) * i), sf::Color(255 / a * ((a>b)?b:a / (a<b)?b:a), 128, 128), sf::Vector2f( 1, 1)) }; window.draw(vertices, 4, sf::Lines); } window.display(); [/code] For some reason, this only draws 1 line at x=0. When I didn't make it safe for resized windows yet, so 600 instead of a and 800 instead of b it worked for some reason. The point is to make a sort of triangle filling half the screen Don't tell me I can just use 1 triangle, I am planning to be able to control the individual sizes of each line Using SFML if it wasn't obvious enough already
[QUOTE=darkrei9n;35845927]In Java for arrays I believe its typename[][] variablename rather than typename variablename[][] when initializing an array.[/QUOTE] Both work in Java. The Java tutorials on the Oracle website only briefly mention this at the beginning, then they use "Type[] variable" for the rest of the tutorials. I've never seen another tutorial even mention it.
If I have an abstract class and another one publicly inheriting from it, what will the derived class inherit? Public and protected datamembers? Also do I have to implement a constructor for the abstract class?
[QUOTE=Number-41;35853867]If I have an abstract class and another one publicly inheriting from it, what will the derived class inherit? Public and protected datamembers? [/QUOTE] I think public inheriting just means the child class inherits everything as-is. Other sorts of inheritance [url=http://www.parashift.com/c++-faq-lite/private-inheritance.html]are fucking complex[/url].
For some reason if I have a static class inside the class that defines it, its fine [cpp] namespace SOGLF { class WindowSettingsClass { WindowSettingsClass(); public: std::string Title; int Height, Width; short OGLMajor, OGLMinor; short rBits, gBits, bBits, aBits; short depthBufferBits, stencilBufferBits; bool FullScreen; int AntiAliasing; int FramesPerSecond; bool HideMouse; static WindowSettingsClass Settings; }; } [/cpp] but if I have the static class in the namespace directly, it doesnt work. [cpp] namespace SOGLF { class WindowSettingsClass { public: WindowSettingsClass(); std::string Title; int Height, Width; short OGLMajor, OGLMinor; short rBits, gBits, bBits, aBits; short depthBufferBits, stencilBufferBits; bool FullScreen; int AntiAliasing; int FramesPerSecond; bool HideMouse; }; static WindowSettingsClass Settings; } [/cpp] By this I mean for example I change the title but it doesnt take effect, and the title set in the constructor gets used.
I'm trying to use OpenCL -> OpenGL interop, however i have pretty much 0 knowledge of OpenGL. Currently, i'm using SFML to set up the window (there doesn't appear to be anything special needed to make it work with opengl) Unfortunately opencl is telling me that i've allocated my buffer wrong. I don't know what's wrong with it, anyone fancy taking a look? The code goes: [cpp] glGenTextures(1 ,&gltscreen_id); glBindTexture(GL_TEXTURE_2D, gltscreen_id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2048, 2048, 0, GL_RGB, GL_FLOAT, NULL); gscreen_rgb=clCreateFromGLTexture2D(cl::context, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, gltscreen_id, &cl::error); [/cpp] Edit: Might be this bug: [url]http://www.opengl.org/wiki/Common_Mistakes#Render_To_Texture[/url] Though i honestly have no idea what texture completeness is Edit 2: Turns out it was the issue of 'texture completeness' (seems rather arbitrary but there you go). Changed the code to: [cpp] glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0 , GL_RGBA, 2048,2048,0, GL_RGBA,GL_FLOAT,NULL);[/cpp] Edit 3: I've been trying to work out how on earth i draw a 2d texture to the screen using non immediate mode. Does anyone have any idea how I can do this? Currently I'm trying to see how you might store a quad and then draw that quad textured, but the OpenGL API is obtuse and completely unclear as to how you might do this Edit 4: Going down the FBO route. Turns out the functions don't really exist by default, so you have to import them manually with: [cpp] PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)wglGetProcAddress("glGenFramebuffersEXT"); PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)wglGetProcAddress("glBindFramebufferEXT"); PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC)wglGetProcAddress("glGenRenderbuffersEXT"); PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC)wglGetProcAddress("glBindRenderbufferEXT"); PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC)wglGetProcAddress("glRenderbufferStorageEXT");[/cpp]
[QUOTE=Richy19;35854489]For some reason if I have a static class inside the class that defines it, its fine <code> By this I mean for example I change the title but it doesnt take effect, and the title set in the constructor gets used.[/QUOTE] You need to create a function to access the static variable. For example: SOGLF.h: [cpp]namespace SOGLF { static WindowSettingsClass Settings; WindowSettingsClass* GetWindowSettings(); }[/cpp] SOGLF.cpp [cpp]WindowSettingsClass* SOGLF::GetWindowSettings(){ return &Settings; }[/cpp] And then use GetWindowSettings() whenever you want to use your Settings variable.
snip
[QUOTE=Naelstrom;35864891]You need to create a function to access the static variable. For example: SOGLF.h: [cpp]namespace SOGLF { static WindowSettingsClass Settings; WindowSettingsClass* GetWindowSettings(); }[/cpp] SOGLF.cpp [cpp]WindowSettingsClass* SOGLF::GetWindowSettings(){ return &Settings; }[/cpp] And then use GetWindowSettings() whenever you want to use your Settings variable.[/QUOTE] Ohh, that gives me the same inconvenence as just having the static variable in the class. I will just keep it as it is
I'm trying to get the angle between 2 lines. So usually I'd go result = secondAngle - firstAngle; However if the second angle is negative, and the first is positive, I get the wrong answer. Eg. -3-5 = -8. In my program it should be 2. [URL]http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign[/URL] This link didn't help :/ My code [CODE]//the horizontal float difference = (angles2.z - angles.z); z = RAD2DEG(difference); weaponAngleOffset.z = z;[/CODE]
[QUOTE=JLea;35869068]I'm trying to get the angle between 2 lines. So usually I'd go result = secondAngle - firstAngle; However if the second angle is negative, and the first is positive, I get the wrong answer. Eg. -3-5 = -8. In my program it should be 2. [URL]http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign[/URL] This link didn't help :/ My code [CODE]//the horizontal float difference = (angles2.z - angles.z); z = RAD2DEG(difference); weaponAngleOffset.z = z;[/CODE][/QUOTE] From your link: [quote] if you only want to know the absolute difference then you can use [code] DEL = PI - ABS(PI - ABS(A - B)) in radians. DEL = 180 - ABS(180- ABS(A - B)) in degrees. [/code] [/quote] I believe that's what you're asking for, no?
Well no, because the final angle offset should range from - (on the left) to positive (on the right). Unless I need to use a dot product? [editline]8th May 2012[/editline] Oh yeah, I just needed to use a dot product to see where I was facing and then multiply the final result based on what I got. Thanks
Well, I have some dumb question. How do I create a vector of Sprites using SFML and vector header? i started the vector like vector<sf::Sprite> test; and Im trying to do a push_back(), but i dont know what i need to put inside the "()". Anyway, my vector will be 41x31, so there is a way t do something like vector<vector<sf::Sprite> > test (41,vector<sf::Sprite>(31,??)) ?
[QUOTE=Mete;35872718]Well, I have some dumb question. How do I create a vector of Sprites using SFML and vector header? i started the vector like vector<sf::Sprite> test; and Im trying to do a push_back(), but i dont know what i need to put inside the "()". Anyway, my vector will be 41x31, so there is a way t do something like vector<vector<sf::Sprite> > test (41,vector<sf::Sprite>(31,??)) ?[/QUOTE] [cpp] vector<sf::Sprite> test; sf::Texture t; t.loadFromFile("foo.png"); sf::Sprite s(t); test.push_back(s); [/cpp] [editline]8th May 2012[/editline] If the size is always going to be 41x31 you are probably better of just using an array. Also if this is just for background have a look at sf::VertexArray [editline]8th May 2012[/editline] If in OpenGL(2.1) I have a scene like the left, therefore the user views the right. Does the cube actually get rendered? [IMG]http://i.imgur.com/T6FK8.png[/IMG] The reason im asking is because in a voxel game(like minecraft for example) would it be necesairy to actually call or not call the draw for sides of cubes that are connected to other cubes?
Sorry, you need to Log In to post a reply to this thread.