• What do you need help with? V. 3.0
    4,884 replies, posted
I'm testing some stuff in C++: [code] class baseclass { public: virtual void overrideme() = 0 {} }; class inheritedclass : public baseclass { public: inheritedclass() { } void overrideme() { } }; ..... std::vector<baseclass*> tests; tests.push_back(new inheritedclass()); std::cout << (typeid(tests.back()) == typeid(baseclass*) ? "true" : "false") << std::endl; std::cout << (typeid(tests.back()) == typeid(inheritedclass*) ? "true" : "false") << std::endl; [/code] output: [code] true false [/code] Shouldn't the typeid for inheritedclass be inheritedclass? When I inspect the vector in MSVC it lists element 0 as an inheritedclass.
"tests" is just a vector of baseclass pointers, it doesn't matter what you PUT in those pointers, they will always be baseclass pointers. Try this: [code] std::cout << (typeid(*tests.back()) == typeid(baseclass) ? "true" : "false") << std::endl; std::cout << (typeid(*tests.back()) == typeid(inheritedclass) ? "true" : "false") << std::endl; [/code]
Oh cool it works, thanks.
I have some collision detection code that works and to resolve the collisions I'm using this piece of code: [CODE] float distance = Vector2.Distance(zombies[i].pos, zombies[j].pos); Vector2 dir = zombies[i].pos - zombies[j].pos; dir.Normalize(); zombies[i].pos += dir * distance / 2; zombies[j].pos -= dir * distance / 2;[/CODE] The thing is, the zombies are jumping around, the collision resolution works they just jump around a lot... What have I done wrong?
I have a pretty damn large help request; I understand if I get little or no response. Basically, I've been learning how to use OpenGL 3.3 with Java and the LWJGL for a while now, and got to perspective projection and camera space/movement a week or so ago. Skip to a few nights ago when I decided to forgo sleep and introduce a [I]massive[/I] change to the way my project works with a Pipeline class and a Camera class. The Pipeline class handles transformation calculations of all relevant matrices and stores the information for those transformations. The actual transformation of the vertices by OGL is done by multiplying a uniform matrix by the position of the vertices in the vertex shader. Every render loop, the total transformation matrix is calculated by the Pipeline and send down to the shader's uniform variable. The Camera class doesn't do much in itself; it stores the target, up and position vectors and contains getters/setters for them. I also implemented two mathematics classes, "Mat4f" and "Vec3f." These extend Matrix4f and Vector3f respectfully and both include new methods to perform matrix transformations and normalization/crossing of vectors. After implementing all of this change by using the learning I've done over the last few weeks, everything worked fine...for a little while. While I was getting to grips with the way it all worked and finding out as much as I can by fiddling with parameters and messing with the transformation matrices, I noticed a few things that are flat out wrong and since then I've not been able to find out why or make more progress - if it's wrong now and I don't fix it then any further change is going to further abstract the error. I've been through the source too many times now; I am 100% confident that I know what it does and how it works, and moreover that it is correct. I've checked the code against the online tutorial I'm using, value-for-value, and I've researched many matrix and vector operations to be certain that I've gotten them right too. [b]The problem I have[/b] is kind of hard to describe as I don't know what it is. A good example of the problem becoming visible is when I move my camera left and right. This [I]should[/I] produce right and left movements in the shape I'm rendering respectfully, but in most cases it seems that what it actually does is move the scene by some value relative to the shape's position. This is most apparent when I slow down the camera's movement and set the shape's z-axis rotation by a value that increases every render loop. First off, the shape never makes a full circle (tested on all three axes together and individually), and second off the camera's left-right motion inverts whenever the shape appears to turn back on itself. My description is terrible, so I thought I'd include this video I made of the system earlier today: [video=youtube;VE_Tl9X4Mns]http://www.youtube.com/watch?v=VE_Tl9X4Mns[/video] This video is unfortunately not intended to show off the error, but it is apparent through the video. According to the vertices that create the shape, I am confident that it should be a cube. When it rotates on the z or x axes, it stretches and distorts. Given that it's a uniform matrix that causes the transformation, I can't work out even [I]how[/I] it does that. All of this boils down to this: I have [I]no[/I] idea what is going on and can't make any more stabs at fixing it than I already have. I've been through [I]everything[/I] and ensured that I have the theory and calculation correct, fiddled with parameters and generally messed with it to see what I might have wrong. I have a theory that I'm missing something very very small or maybe I've miss-learned or misunderstood something key in my implementation. My biggest suspicion is that there is a logical error of some kind in the perspective projection, one which is caused by Java's syntax or the way it handles values and not the actual values I'm manipulating. I've created a handy .zip containing the full source of the application and a built version for anyone has read this far and is interested in helping me out. [B]Requirements[/B]: - Graphics card supporting OpenGL 3.3+ and GLSL 3.3+ - OS: Hopefully the built version should run on any machine, as I created a fat jar with all relevant natives for Linux, Mac and Windows. [B]Details[/B]: - The built version renders a prism that rotates on the z axis. A prism is the perfect shape to show the discrepancies in my rotation, as the screen-facing end will show major distortion as the shape rotates. - Control the camera with WASD. It's looking down the z axis, so W should be negative z, S should be positive z, A should be negative x and D should be positive x. [b]Download:[/b] [URL="http://dl.dropbox.com/u/38489921/ShapeFactory.zip"]Project Shape Factory[/URL] I appreciate that giving people the source and a loose description of the problem is tantamount to begging for a solution and that it might look like I just can't be bothered, but I am at the end of what I can do to make sense of this problem and if I can't fix it and no one else can/wants to then I will press on with my learning and see if I can find and fix the issue at a later date. As I said, I [I]expect[/I] nothing from people, as this is a big ask, though I'd appreciate any and all help with fixing this issue and letting me get on confidently with new learning. I'm happy to give any extra information or detail anyone wants, thanks for reading and I hope this turns out to be a simple issue.
[QUOTE=jonnopon3000;33511597]I have a pretty damn large help request; I understand if I get little or no response. Basically, I've been learning how to use OpenGL 3.3 with Java and the LWJGL for a while now, and got to perspective projection and camera space/movement a week or so ago. Skip to a few nights ago when I decided to forgo sleep and introduce a [I]massive[/I] change to the way my project works with a Pipeline class and a Camera class. post... [/QUOTE] Did you enable GL_DEPTH_TEST?
[QUOTE=mlbfan560;33512271]Did you enable GL_DEPTH_TEST?[/QUOTE] I've thought of this many times myself, but that's a command the tutorials I'm referencing never mention or use. I've only ever seen its explicit use in older, GL11 tutorials. Despite that, I'll go see if plonking it in the GL initialisation changes anything. EDIT: Checked out glEnable(GL_DEPTH_TEST) and glDepthMask(true), and implementing Enable and depth mask or Enable on its own causes no image to be rendered at all. DepthMask on its own produces an image, with the same issues it has without it.
I would need help making this program work the way I'd like it to work. My code so far: [code] #include <SDL.h> void P_O_I( int *Pos_X, int *Pos_Y, SDL_Surface *Image, SDL_Surface *ImageLoc ); void GameLoop( int *stickX, int *stickY, SDL_Surface *tempGameImage, SDL_Surface *gameImgLoc ); int main( int argc, char *args[] ){ const int width = 800; const int height = 800; const int bitperpixel = 32; int Stick_Pos_X = 0; int Stick_Pos_Y = 0; SDL_Init( SDL_INIT_EVERYTHING ); SDL_Surface *screenHandle = NULL; SDL_Surface *tempImage = NULL; SDL_Surface *optImg = NULL; screenHandle = SDL_SetVideoMode( width, height, bitperpixel, SDL_SWSURFACE ); tempImage = SDL_LoadBMP("cube.bmp"); optImg = SDL_DisplayFormat( tempImage ); SDL_WM_SetCaption( "SDL", NULL ); P_O_I( &Stick_Pos_X, &Stick_Pos_Y, optImg, screenHandle ); SDL_FreeSurface( tempImage ); SDL_Flip( screenHandle ); GameLoop( &Stick_Pos_X, &Stick_Pos_Y, optImg, screenHandle ); SDL_Quit(); return 0; } void P_O_I( int *Pos_X, int *Pos_Y, SDL_Surface *Image, SDL_Surface *ImageLoc ){ SDL_Rect rect; rect.x = *Pos_X; rect.y = *Pos_Y; SDL_BlitSurface( Image, NULL, ImageLoc, &rect ); } void GameLoop( int *stickX, int *stickY, SDL_Surface *tempGameImage, SDL_Surface *gameImgLoc ){ bool GameLoop = true; while(GameLoop == true){ SDL_Event gameEvent; if(SDL_PollEvent( &gameEvent )){ switch( gameEvent.type ){ case SDL_QUIT: GameLoop = false; break; case SDL_KEYDOWN: if(gameEvent.key.keysym.sym == SDLK_a || gameEvent.key.keysym.sym == SDLK_LEFT){ stickY += 1; } else if(gameEvent.key.keysym.sym == SDLK_s || gameEvent.key.keysym.sym == SDLK_DOWN){ stickX += 1; } else if(gameEvent.key.keysym.sym == SDLK_d || gameEvent.key.keysym.sym == SDLK_RIGHT){ stickY -= 1; } else if(gameEvent.key.keysym.sym == SDLK_w || gameEvent.key.keysym.sym == SDLK_UP){ stickX -= 1; } SDL_FillRect( gameImgLoc, NULL, SDL_MapRGB( gameImgLoc->format, 0, 0, 0 ) ); P_O_I( stickX, stickY, tempGameImage, gameImgLoc ); SDL_Flip( gameImgLoc ); } } } } [/code] Basically, the program runs fine. I see my BMP and all. However, when I press the WASD keys or it's alternative, my block randomly disappears even though I've set it to move only to 1.
[QUOTE=jonnopon3000;33512424]I've thought of this many times myself, but that's a command the tutorials I'm referencing never mention or use. I've only ever seen its explicit use in older, GL11 tutorials. Despite that, I'll go see if plonking it in the GL initialisation changes anything. EDIT: Checked out glEnable(GL_DEPTH_TEST) and glDepthMask(true), and implementing Enable and depth mask or Enable on its own causes no image to be rendered at all. DepthMask on its own produces an image, with the same issues it has without it.[/QUOTE] Oh and also make sure that you do glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) instead of only the color buffer.
[QUOTE=mlbfan560;33512598]Oh and also make sure that you do glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) instead of only the color buffer.[/QUOTE] OK, that was a step in the right direction. Now that the shape appears to have opaque edges, I see that it's not so much transforming wrong as it is transforming differently to how I thought it was. It seems that its rotation is about some point behind it, meaning that it rotates in a large circle of sorts. I still have the issue that the shape is distorting when it's transformed. Either that, or I'm not drawing what I think I am. I'm sure it's the former, though, as when the prism rotates on the y axis, the front-facing triangle becomes elongated as the shape reaches the edge of the screen. EDIT: Looking at it, I think I've found my issue; the only thing that seems genuinely wrong with the application any more is the way the camera is moving. It changes speed and direction based on the shape's orientation, even after ensuring that the shape's position in the world is remaining the same. If it's facing to the left, the camera will behave differently to if it's facing to the right. Call me crazy but that seems wrong. Time to find out why.
[QUOTE=Spm09;33512461]I would need help making this program work the way I'd like it to work. Basically, the program runs fine. I see my BMP and all. However, when I press the WASD keys or it's alternative, my block randomly disappears even though I've set it to move only to 1.[/QUOTE] You forgot to dereference stickX and stickY in your events.
Hey, in Visual C# 2010, I can't seem to add references for the csfml DLLs.
[QUOTE=Niteshifter;33513130]You forgot to dereference stickX and stickY in your events.[/QUOTE] Ah, thank you! I also got the stickX/stickY wrong.
I'm following one of Rimers tutorials (Trying to learn 3d in XNA) and I came across a problem. [code]System.NullReferenceException was unhandled Message=Object reference not set to an instance of an object. Source=flightsim StackTrace: at flightsim.Game1.DrawCity() in C:\Users\smartass\Documents\Visual Studio 2010\Projects\flightsim\flightsim\flightsim\Game1.cs:line 144 at flightsim.Game1.Draw(GameTime gameTime) in C:\Users\smartass\Documents\Visual Studio 2010\Projects\flightsim\flightsim\flightsim\Game1.cs:line 151 at Microsoft.Xna.Framework.Game.DrawFrame() at Microsoft.Xna.Framework.Game.Tick() at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e) at Microsoft.Xna.Framework.GameHost.OnIdle() at Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame() at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e) at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at Microsoft.Xna.Framework.WindowsGameHost.Run() at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun) at Microsoft.Xna.Framework.Game.Run() at flightsim.Program.Main(String[] args) in C:\Users\smartass\Documents\Visual Studio 2010\Projects\flightsim\flightsim\flightsim\Program.cs:line 15 InnerException: [/code] Here's the code its-self. [code] using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace flightsim { public class Game1 : Microsoft.Xna.Framework.Game { Matrix projectionMatrix; Matrix viewMatrix; GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D sidewalk; GraphicsDevice device; Effect effect; int[,] floorPlan; VertexBuffer cityVertexBuffer; private void LoadFloorPlan() { floorPlan = new int[,] { {0,0,0}, {0,1,0}, {0,0,0}, }; } private void SetUpCamera() { viewMatrix = Matrix.CreateLookAt(new Vector3(3, 5, 2), new Vector3(2, 0, -1), new Vector3(0, 1, 0)); projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.2f, 500.0f); } private void SetUpVertices() { int cityWidth = floorPlan.GetLength(0); int cityLength = floorPlan.GetLength(1); List<VertexPositionNormalTexture> verticesList = new List<VertexPositionNormalTexture>(); for (int x = 0; x < cityWidth; x++) { for (int z = 0; z < cityLength; z++) { // if floorplan contains a 0 for this particular tile, add 2 tris int imagesInTexture = 11; if (floorPlan[x, z] == 0) { verticesList.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -z), new Vector3(0, 1, 0), new Vector2(0, 1))); verticesList.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -z - 1), new Vector3(0, 1, 0), new Vector2(0, 0))); verticesList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, 0, -z), new Vector3(0, 1, 0), new Vector2(1.0f / imagesInTexture, 1))); verticesList.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -z - 1), new Vector3(0, 1, 0), new Vector2(0, 0))); verticesList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, 0, -z - 1), new Vector3(0, 1, 0), new Vector2(1.0f / imagesInTexture, 0))); verticesList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, 0, -z - 1), new Vector3(0, 1, 0), new Vector2(1.0f / imagesInTexture, 1))); } } cityVertexBuffer = new VertexBuffer(device, VertexPositionNormalTexture.VertexDeclaration, verticesList.Count, BufferUsage.WriteOnly); cityVertexBuffer.SetData<VertexPositionNormalTexture> (verticesList.ToArray()); } } public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { // TODO: Add your initialization logic here LoadFloorPlan(); base.Initialize(); } protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); sidewalk = Content.Load<Texture2D>("concrete"); effect = Content.Load<Effect> ("effects"); } protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update logic here base.Update(gameTime); } private void DrawCity() { effect.CurrentTechnique = effect.Techniques["Textured"]; effect.Parameters["xWorld"].SetValue(Matrix.Identity); effect.Parameters["xView"].SetValue(viewMatrix); effect.Parameters["xProjection"].SetValue(projectionMatrix); effect.Parameters["xTexture"].SetValue(sidewalk); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); device.SetVertexBuffer(cityVertexBuffer); device.DrawPrimitives(PrimitiveType.TriangleList, 0, cityVertexBuffer.VertexCount/3); } } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); DrawCity(); // TODO: Add your drawing code here base.Draw(gameTime); } } } [/code] Anyone have any idea how to fix this?
[QUOTE=Mr. Smartass;33513801]I'm following one of Rimers tutorials (Trying to learn 3d in XNA) and I came across a problem. [code] [/code] Anyone have any idea how to fix this?[/QUOTE] You never set 'device' to anything. Also its repetitive to do that because graphics.GraphicsDevice will get you the device.
[QUOTE=Killowatt;33513257]Hey, in Visual C# 2010, I can't seem to add references for the csfml DLLs.[/QUOTE] You don't add them as references. Add the sfmlnet dlls to the references and copy the csfml dlls to the folder where the executable is running. You can also add them to the solution as normal files and tell visual studio to copy them to the output folder on the properties so you don't need to copy them to the debug and release folders, VS will do that for you.
I still get an error. It says that it can't find one of the csfml files.
[QUOTE=Killowatt;33514278]I still get an error. It says that it can't find one of the csfml files.[/QUOTE] Have copied it to the output (bin/Debug) folder? It should work, if it doesn't you missed a DLL. Each sfmlnet-*.dll has a csfml-*.dll equivalent, there should be a total of 6 dlls (3 .Net binaries and 3 C binaries) if you are using the full SFML framework (audio, graphics, window).
Yep. It's doing all that, but it still gives me the error that says it is missing it
Can you get a screen shot of the exception?
Add me on steam, will make things a lot easier.
Hey, wondering if anyone can figure this out. I think it's Unicode or Unix. 1317409596 1317409680 _ _ _ _ _ _ _ X I just need to fill in the blanks.
Those are Unix timestamps, what are you supposed to be figuring out?
[QUOTE=NovembrDobby;33506027]I'm testing some stuff in C++: [code] class baseclass { public: virtual void overrideme() = 0 {} }; class inheritedclass : public baseclass { public: inheritedclass() { } void overrideme() { } }; ..... std::vector<baseclass*> tests; tests.push_back(new inheritedclass()); std::cout << (typeid(tests.back()) == typeid(baseclass*) ? "true" : "false") << std::endl; std::cout << (typeid(tests.back()) == typeid(inheritedclass*) ? "true" : "false") << std::endl; [/code] output: [code] true false [/code] Shouldn't the typeid for inheritedclass be inheritedclass? When I inspect the vector in MSVC it lists element 0 as an inheritedclass.[/QUOTE] Isn't an abstract method [code] virtual void methodName()=0; //not virtual void methodName()=0{} [/code]
New to programming and C# in general, when I try to call a non-static function from the static main function of a C# console application, it gives an error "An object reference is required for the non-static field, method, or property". Why does it do this and how do I go about fixing it?
[QUOTE=ief014;33478024]You're modifying (in this case, removing) an item in the collection. It makes the foreach corrupt. If I were you, I would use a regular for loop: [code] for(int i = 0; i < particles.Count(); i++) { if(particles[i].ttl <= 0) { particles.RemoveAt(i); i--; //since we removed an item, we move back the for loop so we don't skip the next item } } [/code][/QUOTE] I'd actually go a step further and suggest using a doubly linked list, so deletions aren't O(n)
How would you go about getting the local IP of a computer in C#?
[url]https://www.google.com/search?q=C%23+get+local+address[/url] [editline]1st December 2011[/editline] also 127.0.0.1 is always your computer.
[QUOTE=robmaister12;33519537][url]https://www.google.com/search?q=C%23+get+local+address[/url] [editline]1st December 2011[/editline] also 127.0.0.1 is always your computer.[/QUOTE] I cant believe I never knew that, never done much with networking over simple home network type stuff. Thanks. [editline]1st December 2011[/editline] Anyone used NATUPNPLib? I'm getting an exception for this code. [csharp] NATUPNPLib.UPnPNAT upnpnat = new NATUPNPLib.UPnPNAT(); upnpnat.StaticPortMappingCollection.Add(8888, "TCP", 8888, "127.0.0.1", true, "forIM"); [/csharp] Exception System.Runtime.InteropServices.COMException (0x80040208): A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208) at NATUPNPLib.IStaticPortMappingCollection.Add(Int32 lExternalPort, String bstrProtocol, Int32 lInternalPort, String bstrInternalClient, Boolean bEnabled, String bstrDescription) at ConsoleApplication1.Program.Main(String[] args) in C:\Users..... [editline]2nd December 2011[/editline] Has anyone used UPnP in C# if so how?
[QUOTE=jonnopon3000;33512808]OK, that was a step in the right direction. Now that the shape appears to have opaque edges, I see that it's not so much transforming wrong as it is transforming differently to how I thought it was. It seems that its rotation is about some point behind it, meaning that it rotates in a large circle of sorts. I still have the issue that the shape is distorting when it's transformed. Either that, or I'm not drawing what I think I am. I'm sure it's the former, though, as when the prism rotates on the y axis, the front-facing triangle becomes elongated as the shape reaches the edge of the screen. EDIT: Looking at it, I think I've found my issue; the only thing that seems genuinely wrong with the application any more is the way the camera is moving. It changes speed and direction based on the shape's orientation, even after ensuring that the shape's position in the world is remaining the same. If it's facing to the left, the camera will behave differently to if it's facing to the right. Call me crazy but that seems wrong. Time to find out why.[/QUOTE] Make sure your matrices are setup correctly, and that they're being multiplied in the right order in your shaders.
Sorry, you need to Log In to post a reply to this thread.