• What do you need help with? V. 3.0
    4,884 replies, posted
[QUOTE=mechanarchy;32857001] How can I do what I want? I'm kinda loathe to put the StandardRandom and MersenneRandom classes into the header instead of the source file, there's no real point having access to them specifically later when all I want is access to the general base they share.[/QUOTE] Const pointers have to defined and initialized at the same time, so I think this is the only way: [cpp] // Header class Random { public: static Random* const Standard; static Random* const MersenneTwister; // ... }; // Implementation // These two are constructed sometime before main, in undefined order. StandardRandom __standard; MersenneTwisterRandom __mersenneTwister; Random* const Random::Standard = &__standard; Random* const Random::MersenneTwister = &__mersenneTwister; // Illustrative example #include <iostream> int main() { std::cout << Random::Standard << " " << Random::MersenneTwister << std::endl; } [/cpp] If the two pointers were not const, you could have made a "global constructor" class with arbitrary initialization in its constructor, then declared a dummy instance of the class (to run the constructor once).
[QUOTE=jA_cOp;32857518]Const pointers have to defined and initialized at the same time, so I think this is the only way: [cpp] // Header class Random { public: static Random* const Standard; static Random* const MersenneTwister; // ... }; // Implementation // These two are constructed sometime before main, in undefined order. StandardRandom __standard; MersenneTwisterRandom __mersenneTwister; Random* const Random::Standard = &__standard; Random* const Random::MersenneTwister = &__mersenneTwister; // Illustrative example #include <iostream> int main() { std::cout << Random::Standard << " " << Random::MersenneTwister << std::endl; } [/cpp] If the two pointers were not const, you could have made a "global constructor" class with arbitrary initialization in its constructor, then declared a dummy instance of the class (to run the constructor once).[/QUOTE] yay masterpiece :DD I adapted your solution and change my code I posted above from using constant pointers to using a reference. That makes things a lot easier now. Thank you for your help! :smile:
[QUOTE=Map in a box;32853583]Again, I'm 99% sure Slick2D has a a* implementation.[/QUOTE] It does, but I figured it's something I should learn to do myself.
Trying to get a camera to work for my 2D xna game. I'm setting the cameras position to 0,0 but when i run the code the camera position is no where near 0,0. The image below will hopefully example my problem. [img]http://i967.photobucket.com/albums/ae154/chrismelling/XDE2011-10-1915-04-51-62.jpg[/img] The text is being drawn at 0,0 and as you can see the camera position is no where near them, its almost like the camera's centre is at 0,0 instead of the top left corner. Here is the code for the camera. [code] namespace GameStates { class Camera2d { static public Matrix transform; // Matrix Transform static public Vector2 pos; // Camera Position public static void Init(GraphicsDeviceManager graphics) { pos = new Vector2(0, 0); } public static Matrix get_transformation(GraphicsDeviceManager graphics) { transform = // Thanks to o KB o for this solution Matrix.CreateTranslation(new Vector3(pos.X, pos.Y, 0)) * Matrix.CreateTranslation(new Vector3(graphics.PreferredBackBufferWidth * 0.5f, graphics.PreferredBackBufferHeight * 0.5f, 0)); return transform; } } } [/code]
When compiling a program in microsoft visual studio C#, you should be able to run the program in the "debug" folder no matter what computer it's on, correct?
[QUOTE=Mr. Smartass;32858913]When compiling a program in microsoft visual studio C#, you should be able to run the program in the "debug" folder no matter what computer it's on, correct?[/QUOTE] The program compiled in "release" mode will work on any machine that supports the .NET framework you target. "debug" mode will only work on computers with visual studio and C# installed (afaik).
[del] C# Is there a way I can sort of 'parent' one form to another? So that whereever I move my first form, the second acts like it's attached and moves with it. [/del] Scratch that. I found out that you can use the LocationChanged event.
[QUOTE=thomasfn;32859177]The program compiled in "release" mode will work on any machine that supports the .NET framework you target. "debug" mode will only work on computers with visual studio and C# installed (afaik).[/QUOTE] Isn't the only difference that the Debug build isn't optimized and has debug information and whatnot?
Any good place to start learning JavaScript? Atm I know only xhtml, css, and a bit of java. Looking for website or videos where it would start completely from scratch teching javascript. Thanks.
[QUOTE=vexx21322;32859362]C# Is there a way I can sort of 'parent' one form to another? So that whereever I move my first form, the second acts like it's attached and moves with it.[/QUOTE] Set form2's position relative to the form1's position in form1's Move event.
[QUOTE=thomasfn;32859177]The program compiled in "release" mode will work on any machine that supports the .NET framework you target. "debug" mode will only work on computers with visual studio and C# installed (afaik).[/QUOTE] That's wrong, both release and debug builds will run on any computer with .Net, the difference is that the release build is optimized and contains no debug information at all, the debug build is not optimized (to make debugging easier) and contains debugging information.
[QUOTE=Fox-Face;32859773]That's wrong, both release and debug builds will run on any computer with .Net, the difference is that the release build is optimized and contains no debug information at all, the debug build is not optimized (to make debugging easier) and contains debugging information.[/QUOTE] I stand corrected.
[cpp] gl.viewport(0, 0, local.m_width, local.m_heigth); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); // somwhere later var DDraw2dQuad = []; this.Draw2dQuad = function(x, y, width, hight, color) { /*m_gl.useProgram(DDraw2dQuad.program);*/ m_gl.bindBuffer(gl.ARRAY_BUFFER, DDraw2dQuad.buffer_vertex); m_gl.vertexAttribPointer(DDraw2dQuad.attrib_vertexposition, 2, m_gl.FLOAT, false, 0, 0); m_gl.drawArrays(m_gl.TRIANGLE_STRIP, 0, 4); } this.Draw2dQuad.Init = function() { DDraw2dQuad.program = m_sm.GetProgram("2DCOLOR"); m_gl.useProgram(DDraw2dQuad.program); DDraw2dQuad.attrib_vertexposition = m_gl.getAttribLocation(DDraw2dQuad.program, "aVertexPosition"); m_gl.enableVertexAttribArray(DDraw2dQuad.attrib_vertexposition); DDraw2dQuad.buffer_vertex = m_gl.createBuffer(); m_gl.bindBuffer(m_gl.ARRAY_BUFFER, DDraw2dQuad.buffer_vertex); vertices = [ 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0 ]; // Testing. m_gl.bufferData(m_gl.ARRAY_BUFFER, new Float32Array(vertices), m_gl.STATIC_DRAW); console.log(m_gl.getError()); } [/cpp] Shaders: vertex [cpp] attribute vec2 aVertexPosition; void main(void) { gl_Position = vec4(aVertexPosition, 1.0, 1.0); } [/cpp] fragment [cpp] #ifdef GL_ES precision highp float; #endif void main(void) { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); } [/cpp] Not drawing anything not giving any opengl or javascript errors only clearcolor background. In my smaller testing project it seemed to work fine i have looked over my code a few times now and found nothing. Complete version: [url]http://cold.netburst.co.uk/webgl/[/url]
Alright, can anybody help me out with a two concepts i'm fumbling around with at the moment? [u]1| Proper class heirarchy in C++[/u] Let's say I have a super class called [b]Block[/b]. A [b]Block[/b] is essentially a 3D model in the game, and another Class called [b]BlockFactory[/b] will have an array of [b]Blocks[/b] and create types of blocks on demand. And I also have a few subclasses of [b]Block[/b], one of which is called [b]SpecialBlock[/b], and they all do a few things differently in their implementation. Although some of them do things differently, they all need the basic methods from Block. What's the best way to set this up? How can I determine when something is a subclass, and not the super class? Should I watch out for something in particular? Here's some example header files of what I basically have: [url=http://pastebin.com/UH4rRunc]Block.h[/url] -- A model [url=http://pastebin.com/BVgCPTg7]SpecialBlock.h[/url] -- Inherits block [url=http://pastebin.com/kT87fMdV]BlockFactory.h[/url] -- Controls creation and deletion of blocks, as well as manipulation I have those implemented and working at the moment, but if anything is glaringly unsafe or could be set up better I would really like to know. For example, this all works but not even a single pointer has been used yet, which seems [i]odd[/i] to me. [u]2| How would I properly separate logic from the drawing code?[/u] I'm looking for references and theories on different ways to go about doing this, I don't need an exact answer as there most likely isn't one. Should I made a thread for the display, and tell it to update from the logic thread? Should I tell the logic thread to standby until a call is sent to it by an entity? I assume I would have to make sure they don't both try to grab the same data at the same time, like every normal thread if I did it that way. I'm pretty much doing that currently, but it doesn't seem like it would be a good way to go about it.
[QUOTE=Fox-Face;32859773]That's wrong, both release and debug builds will run on any computer with .Net, the difference is that the release build is optimized and contains no debug information at all, the debug build is not optimized (to make debugging easier) and contains debugging information.[/QUOTE] How do I compile it in release mode?
[QUOTE=HeroicPillow;32866599]I have those implemented and working at the moment, but if anything is glaringly unsafe or could be set up better I would really like to know. For example, this all works but not even a single pointer has been used yet, which seems [i]odd[/i] to me.[/QUOTE] If anything it'd be your implementation being unsafe.
[QUOTE=Mr. Smartass;32866900]How do I compile it in release mode?[/QUOTE] [IMG]http://i52.tinypic.com/2gxhijm.png[/IMG] or [IMG]http://i51.tinypic.com/11brfk2.png[/IMG] Just flip the switch from debug to release, the first one will apply to the entire solution and the second one will open a more complete window, where you can choose how to compile for each project(projects inside the solution, that is). I don't know how to do it in other IDE's, but I assume it is something similar to this.
[QUOTE=Fox-Face;32867761][IMG]http://i52.tinypic.com/2gxhijm.png[/IMG] or [IMG]http://i51.tinypic.com/11brfk2.png[/IMG] Just flip the switch from debug to release, the first one will apply to the entire solution and the second one will open a more complete window, where you can choose how to compile for each project(projects inside the solution, that is). I don't know how to do it in other IDE's, but I assume it is something similar to this.[/QUOTE] I have neither of those options: [img]http://dl.dropbox.com/u/12024286/damnit.PNG[/img]
Are you by any chance using the express edition? If so microsoft hides it somewhere [editline]20th October 2011[/editline] [url]http://stackoverflow.com/questions/2812423/how-to-switch-between-debug-release-in-visual-c-sharp-2010-express[/url]
[QUOTE=Richy19;32867899]Are you by any chance using the express edition? If so microsoft hides it somewhere[/QUOTE] Indeed I am. Does anyone know where it's hidden?
[QUOTE=Mr. Smartass;32867916]Indeed I am. Does anyone know where it's hidden?[/QUOTE] [url]http://stackoverflow.com/questions/2812423/how-to-switch-between-debug-release-in-visual-c-sharp-2010-express[/url]
I have been struggling to get SFML to work properly on Ubuntu with Code::Blocks, can anyone give me a tutorial or something? I'm pretty sure I linked the libraries properly but I'm still getting this error. Here's my example code: [code] #include <SFML/Graphics.hpp> int main() { sf::VideoMode VMode(800, 600, 32); sf::RenderWindow Window(VMode, "SFMLCoder Tutorial - Empty Window"); while (Window.IsOpened()) { sf::Event Event; while (Window.PollEvent(Event)) { switch (Event.Type) { case sf::Event::Closed: Window.Close(); break; default: break; } } Window.Clear(sf::Color(0, 255, 255)); Window.Display(); } return 0; } [/code] And here's the error: [code] /home/justin/Desktop/MyPrograms/SFML/main.cpp|11|error: &#8216;class sf::RenderWindow&#8217; has no member named &#8216;PollEvent&#8217;| [/code]
[QUOTE=Jookia;32867179]If anything it'd be your implementation being unsafe.[/QUOTE] Heh. Anything specific I should change? Or is [i]everything[/i] wrong with it?
I dunno, can you post it?
Terrible newbie question here- I have a sprite in XNA. I've managed to apply movement and rotation to it, but how would I do movement relative to local coordinates, rather than global ones?
Hey everyone, this is a noobish kind of question but only recently have I started doing some coding and also sadly I only have access to Visual Basic 6.0. I have been tasked with creating a program that converts decimal numbers to both binary and hex. Getting the conversion to binary was pretty damn easy, but I have no ideas on how to then convert the binary (which is printed into a single label) into hex. Does anyone have any ideas on how to do this? Also, I'd prefer if the output hex was printed into only a single label. Here is the code I've done on the decimal to binary, in case anyone wants to look at that: [CPP] Option Explicit Dim I As Long, X As Integer Private Sub cmdProcess_Click() lblOutput.Caption = "" // Clears the output label incase an operation has already been performed I = txtInput.Text // Input decimal of course X = 64 // How many times the program will execute the following loop, also acts as the powers of 2 tested against Do Until X = -1 If I >= 2 ^ X Then lblOutput.Caption = lblOutput.Caption + "1" I = I - 2 ^ X Else lblOutput.Caption = lblOutput.Caption + "0" End If X = X - 1 Loop lblOutput.Caption = lblOutput.Caption * 1 // This removes all 0s before the first 1 End Sub [/CPP] I've already done the conversion to hex, but with some different code and an entirely different layout. That was that the input number (of to a maximum of 255) had the binary output split into 8 different labels, and that was very easy to get the nibbles and convert 10-15 to A-F. This code is different of course, and because I've been focussing on efficiency it might have limited me a bit.
[QUOTE=Mr. Smartass;32869523]Terrible newbie question here- I have a sprite in XNA. I've managed to apply movement and rotation to it, but how would I do movement relative to local coordinates, rather than global ones?[/QUOTE] Just offset it by the camera position, iirc: [code] x=sprite.x-cam.x; y=sprite.y-cam.y; [/code]
[cpp] gl.viewport(0, 0, local.m_width, local.m_heigth); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); // somwhere later var DDraw2dQuad = []; this.Draw2dQuad = function(x, y, width, hight, color) { /*m_gl.useProgram(DDraw2dQuad.program);*/ m_gl.bindBuffer(gl.ARRAY_BUFFER, DDraw2dQuad.buffer_vertex); m_gl.vertexAttribPointer(DDraw2dQuad.attrib_vertexposition, 2, m_gl.FLOAT, false, 0, 0); m_gl.drawArrays(m_gl.TRIANGLE_STRIP, 0, 4); } this.Draw2dQuad.Init = function() { DDraw2dQuad.program = m_sm.GetProgram("2DCOLOR"); m_gl.useProgram(DDraw2dQuad.program); DDraw2dQuad.attrib_vertexposition = m_gl.getAttribLocation(DDraw2dQuad.program, "aVertexPosition"); m_gl.enableVertexAttribArray(DDraw2dQuad.attrib_vertexposition); DDraw2dQuad.buffer_vertex = m_gl.createBuffer(); m_gl.bindBuffer(m_gl.ARRAY_BUFFER, DDraw2dQuad.buffer_vertex); vertices = [ 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0 ]; // Testing. m_gl.bufferData(m_gl.ARRAY_BUFFER, new Float32Array(vertices), m_gl.STATIC_DRAW); console.log(m_gl.getError()); } [/cpp] Shaders: vertex [cpp] attribute vec2 aVertexPosition; void main(void) { gl_Position = vec4(aVertexPosition, 1.0, 1.0); } [/cpp] fragment [cpp] #ifdef GL_ES precision highp float; #endif void main(void) { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); } [/cpp] Not drawing anything not giving any opengl or javascript errors only clearcolor background. In my smaller testing project it seemed to work fine i have looked over my code a few times now and found nothing. Complete version: [url]http://cold.netburst.co.uk/webgl/[/url]
snip [editline]20th October 2011[/editline] What is it supposed to draw?
I've always wondered how to do something like a planet renderer. I'm talking simply in terms of precision, not anything about planets because that's not what interests me as such. Obviously you can't just do floats and hope for the best. I've heard about keeping the absolute position as a 64 bit integer and then using relative positions with floats. Obviously by this terrible description you can see i'm way too stupid and don't understand how this would actually work. I've tried googling but I guess i'm searching all the wrong things and I haven't found anything decent on it. I'm pretty much asking for anything that can help.
Sorry, you need to Log In to post a reply to this thread.