• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=bootv2;43676769]I thought so, but I havent been able to find out what. I'll upload a zip of the full source for now, until I get github to work. [editline]26th January 2014[/editline] [url]https://dl.dropboxusercontent.com/u/30229428/markanoid_2.rar[/url][/QUOTE] Okay, you are handling includes the wrong way throughout the whole project. 1. Only include header files, do not include implementation files 2. Any file should include the header files for whatever declarations it needs 3. Forward-declare any types whose specifics (members, sizeof, nested types, etc.) are not needed For example: - Foo.h declares class Foo inheriting from Bar: Foo.h should include Bar.h - Foo has a pointer-to-Derp member: Foo.h should forward-declare Derp - Foo's implementation calls a method on Derp: Foo.cpp includes Derp.h
[QUOTE=bootv2;43677006]Thanks, works now. Though, I have to ask, why do the implementation files automatically include the header files in visual studio when using the new class wizard? It made me thing I should include the implementation files.[/QUOTE] In general, each class Foo should come with a Foo.h declaring the class (i.e. method signatures only) and a Foo.cpp implementing it (i.e. what the methods should do). A compilation step is triggered for each implementation file, but not for header files. So when Foo.cpp gets compiled and you refer to Foo, you first have to make the declaration of Foo available by including Foo.h within Foo.cpp. Implementations can only occur once, so including those (and thus duplicating them) will often result in linker errors.
Hey guys, busy with some exciting stuff but ran into a little issue making my level editor. I use box2D's settransform to move my physics camera around, but I don't want it to penetrate the ground or other physics objects. I would really like to avoid using forces to move it since that becomes messy. How would I stop body penetration while still retaining smooth mouse control over the camera?
C++ question: Say I have a class called Vector. I have an int variable that I defined in the header file called size. Now let's say I'm inside the class file in a function called Vector::setSize(int size). I want to replace the global variable declared in the header file with the one put in the parameter for the function. Do these two both accomplish that: Vector::size = size; this->size = size;
[QUOTE=Cow Muffins;43682736]C++ question: Say I have a class called Vector. I have an int variable that I defined in the header file called size. Now let's say I'm inside the class file in a function called Vector::setSize(int size). I want to replace the global variable declared in the header file with the one put in the parameter for the function. Do these two both accomplish that: Vector::size = size; this->size = size;[/QUOTE] They do, yes. But if you want to make sure, you should run it through a debugger.
I need some help establishing why I can't access information from my JSONObject. This is my code that isn't working properly: [CODE] protected void onPostExecute(JSONObject json) { // String[] formid = new String[100]; String[] questionsplit = new String[100]; String[] qidsplit = new String[100]; String[] qtypesplit = new String [100]; try { if (json.getString(KEY_SUCCESS) != null) { json_form = json.getJSONObject("form"); // Handle form data String qid; String question; String qtype; // formid[i] = json_form.getString(KEY_FORMID); qid = json_form.getString(KEY_QID); // The line of code which gives me an error question = json_form.getString(KEY_QUESTION); qtype = json_form.getString(KEY_QTYPE);[/CODE] And part of the JSON response: [CODE]01-27 06:12:52.315: E/JSON(12246): {"success":1,"form":{"formid":"3","qid":"13;16;17;18;19;20;21;22;23;24;25","question":[/CODE] [editline]27th January 2014[/editline] And the error code: [CODE]01-27 06:12:52.330: W/System.err(12246): org.json.JSONException: No value for null 01-27 06:12:52.330: W/System.err(12246): at org.json.JSONObject.get(JSONObject.java:354) 01-27 06:12:52.335: W/System.err(12246): at org.json.JSONObject.getString(JSONObject.java:510) [/CODE] [editline]27th January 2014[/editline] Okay so the problem was that I hadn't defined the keys when I declared them..
I'm having problems in C Reallocing for a struct. the structs are something like this. [code] typedef struct{ int numberOfStructs; myStructs **; //array of pointers to structs }StructHolder; typedef struct{ int numberOfProperties Property[] properties; //Variable length array allowed in c99 }MyStruct; typedef struct{ int type; char * attribute1; char * attribute2; char * value; }Property [/code] Sequence of operations: Open a file for parsing. Read it. Take that line, if it needs to be parsed, parse it and put it into the Property. Memory for strings attribute1, attribute 2 and value have POSSIBLY been allocated (AT LEAST ONE IS ALLOCATED). From that property, I need to put it into a "myStruct", and that struct into a struct holder. The problem is not doing it once, it's reallocated and properly accounting for all the space I need in a loop. The line in question where I get a "*** glibc detected *** ./a.out: realloc(): invalid next size: 0x0000000000a6c270 ***" error; [code](*myStruct)=realloc((*myStruct),sizeof((*myStruct))+(sizeof(Property)*((*myStruct)->numberOfProperties))); //im not typecasting anything (*myStruct) is the dereferenced MyStruct ** pointer. [/code] The function's definition where this is from sent, readOneStruct(FILE vcf,MyStruct **const myStruct) The functions main purpose is to be sent a null double pointer which will be changed to point to the allocated memory for the struct. The struct has multiple properties and are filled up in a loop, therefore need to be reallocated each time to account for space while the file is being parsed to fiill the one struct. Mainly I can't find any good explanations on how to reallocate memory for variable length arrays with c99. Again this is C, not C++.
[QUOTE=bull3tmagn3t;43686395]I'm having problems in C Reallocing for a struct. the structs are something like this. [code] typedef struct{ int numberOfStructs; myStructs **; //array of pointers to structs }StructHolder; typedef struct{ int numberOfProperties Property[] properties; //Variable length array allowed in c99 }MyStruct; typedef struct{ int type; char * attribute1; char * attribute2; char * value; }Property [/code] Sequence of operations: Open a file for parsing. Read it. Take that line, if it needs to be parsed, parse it and put it into the Property. Memory for strings attribute1, attribute 2 and value have POSSIBLY been allocated (AT LEAST ONE IS ALLOCATED). From that property, I need to put it into a "myStruct", and that struct into a struct holder. The problem is not doing it once, it's reallocated and properly accounting for all the space I need in a loop. The line in question where I get a "*** glibc detected *** ./a.out: realloc(): invalid next size: 0x0000000000a6c270 ***" error; [code](*myStruct)=realloc((*myStruct),sizeof((*myStruct))+(sizeof(Property)*((*myStruct)->numberOfProperties))); //im not typecasting anything (*myStruct) is the dereferenced MyStruct ** pointer. [/code] The function's definition where this is from sent, readOneStruct(FILE vcf,MyStruct **const myStruct) The functions main purpose is to be sent a null double pointer which will be changed to point to the allocated memory for the struct. The struct has multiple properties and are filled up in a loop, therefore need to be reallocated each time to account for space while the file is being parsed to fiill the one struct. Mainly I can't find any good explanations on how to reallocate memory for variable length arrays with c99. Again this is C, not C++.[/QUOTE] I don't mean to avoid answering the question, but do you really need VLAs here? To me it makes things more complicated, without it you would just do: [code] (*myStruct)->properties = realloc((*myStruct)->properties, sizeof(Property) * (*myStruct)->numberOfProperties); [/code] I understand this may be set-in-stone and out of your control, but I would consider replacing the VLA with a pointer, especially because in C11 the VLA is not even a required part of the standard, so this code will eventually require legacy support to run.
[QUOTE=Rayjingstorm;43688881]I don't mean to avoid answering the question, but do you really need VLAs here? To me it makes things more complicated, without it you would just do: [code] (*myStruct)->properties = realloc((*myStruct)->properties, sizeof(Property) * (*myStruct)->numberOfProperties); [/code] [/QUOTE] Yes I have to use VLA's. Said code gives : error: invalid use of flexible array member
[QUOTE=bull3tmagn3t;43689225]Yes I have to use VLA's. Said code gives : error: invalid use of flexible array member[/QUOTE] Woops, yeah VLAs are on the stack whereas "flexible array members" are in structs, such as [code] typedef struct { int numberOfProperties; Property properties[]; // Flexible array member allowed in c99 } MyStruct; int main(int argc, char *argv[]) { int foo[argc]; // VLA allowed in c99 } [/code] You should still be able to realloc as you did. My code would require you to change the struct definition to something like [code] typedef struct { int numberOfProperties; Property *properties } MyStruct; [/code] but you mention this isn't possible. As for your previous errors I'm not sure what is wrong without actually seeing the full code, or a simplified case where you actually get the error (what you posted is both invalid C and incomplete code).
I have made this skeletal animator: [media]http://youtu.be/ao0Uhra0Cc4[/media] Now I'm using the animations in a game, but I can't figure out how I'd go about flipping it all for the equivalent left-facing animation. Bearing in mind the upper limb angles relative to the axis axis are stored, and the lower limb angles are stored relative to the upper limbs. I assume for the lower limbs I can then just use the negative of the angle, but I have no idea how to calculate the angles for the upper limbs (and then do I need to flip the sprites vertically?) EDIT: Nevermind, put some thought in and worked it out :smile:
Found solution: Using a temporary struct and allocing for it and copying it into the newly allocated memory [code] (*cardp)=realloc((*cardp),sizeof(Vcard)+(sizeof(VcProp)*((*cardp)->nprops)));//allocate itself plus an extra prop memcpy(&(*cardp)->prop[(*cardp)->nprops-1], tempProp, sizeof(VcProp)); [/code]
-snip- Figured out what I was missing
Guys I am not trolling in any way when I say this, but when I start to learn about C++(I have learned about simple stuff like arrays, variables, constants, etc...) immediately when I start reading, I can feel my ass unclench and shit start to turtle head. Why the ass does this happen?
So guys I'm trying to make a trigger system that will work with my building destruction system I'm making for my game. Should I make it so the trigger checks for the wall/support instances inside of it and if it goes below a certain percent it begins to make the building "fall"? Or is there an easier way to do this?
Question: In C# are there tables like in Lua ? [code] Table in Lua tbl = {} tbl.Name = "Awesome" tbl.Price = 5000 [/code] [editline]28th January 2014[/editline] Or in C# you lists ?
[QUOTE=BoowmanTech;43698531]Question: In C# are there tables like in Lua ? [code] Table in Lua tbl = {} tbl.Name = "Awesome" tbl.Price = 5000 [/code] [editline]28th January 2014[/editline] Or in C# you lists ?[/QUOTE] There are lots of different collections to choose from, each have their own benefits. But yeah you will probably use Lists more than anything at least to start with. You should also learn to use arrays for fixed size data. [URL]http://msdn.microsoft.com/en-us/library/ybcx56wz.aspx[/URL] [B]Edit[/B]: I misread but Tamschi covered it.
[QUOTE=BoowmanTech;43698531]Question: In C# are there tables like in Lua ? [code] Table in Lua tbl = {} tbl.Name = "Awesome" tbl.Price = 5000 [/code] [editline]28th January 2014[/editline] Or in C# you lists ?[/QUOTE] Not exactly, you'd use an anonymous type like [code]new { Name = "Awesome", Price = 5000 }[/code] (or similar) for small things and just a normal type if you want to use it outside of a method. [editline]28th January 2014[/editline] You [i]could[/i] use a Dictionary<string, dynamic>, but that way you loose all static type checking. It's maybe useful for runtime content but I'd avoid it if possible.
Huh, well that is a bit embarrassing. I've been programming in C# for years now and I didn't know about anonymous types. Seems like fundamental knowledge too. I'd always just create a new struct or class.
Do you guys know of an efficient way to parse BBCode in Java? I'm trying to get my FP app to work with labpunch, and while it's much faster, posts are now supplied in BBCode instead of HTML. Most BBCode parsers just output HTML code, which would mean I'd have to parse it in HTML afterwards as well. Right now (in HTML) I traverse the children of the XML root (using the JSoup library) and create the approriate views for quotes, media,... BBCode parsers however do not allow you to do the same.
[code]playerBody.AddForce(Mathf.Cos(launch.firingAngle)*launch.forceAmount,0,Mathf.Sin(launch.firingAngle)*launch.forceAmount,ForceMode.Impulse);[/code] I need to use an angle (not normalized in any way, can be positive/negative/any size), and use it to determine a Vector3 force. I rotate an arrow on the Y (up) axis, and the angle that gives me, I need to use to apply a force on a rigidbody on x and z (forward/backwards and sideways). The code above gives really random, strange results, and I'm not sure if it's because I messed up cos/sin, or because the angle isn't normalized, or because the forceAmount changes (sine wave over time).
-snip'd-
Right. So, I am using Java3D for a [b]really[/b] simple 3D application (part of a larger game that is mostly 2D), involving a three-dimensional wireframe cube comprised of a three-dimensional grid (specifically, it's intent is to be a "star map"). Part of this 3D application involves the user being able to rotate the cube along pitch and yaw. The way I want rotation to work is a mapping of [0,width] -> [0,PI] for mouse-X -> cube-yaw [0,height] -> [0,PI] for mouse-Y -> cube-pitch Which is to say, if you grab at one end of the screen and drag to the other end, it rotates the cube 180 degrees. The crux of my problem is I want this to be done [b]additively[/b], meaning it keeps rotating. So if I rotate in 30-degree increments, then if I rotate 12 times, the cube will have rotated a full 360 degrees. Long story short, I don't know how to do this. I would provide an online link to the Java3D API, but I can't find any (and Oracle's link to it 404's). I have an offline copy, but that's no good to anyone. For those not familiar with Java3D, though, the relevant information is as such: My cube is a TransformGroup, which is a collection of transformations (represented as Transform3D's) that the underlying OpenGL performs in order. I can get the resultant Transform3D of the cube (what the final transformation would be) - call this [b]cubeTransform[/b]. From the [b]cubeTransform[/b], I can get the rotation transformation, represented as either a [b]Quaternion4d[/b] or a [b]Matrix4d[/b]. Quaternions can be converted to [b]AxisAngle4d[/b]s, which are basically Euler angles, defining an axis to rotate about and the number of radians to rotate about it. [b]Transform3D[/b] objects, such as [b]cubeTransform[/b], have rotX, rotY, and rotZ methods that set the rotation in each axis. They can also have signatures [b]setRotation(Quaternion4d)[/b] and [b]setRotation(AxisAngle4d)[/b] to set the rotation to any quaternion or Euler angle. However, none of these objects have any way to safely [b]add[/b] rotations together. There is an "add" method, but it doesn't do any sort of bounding checks and is prone to erroring. Long story short, I have no idea how to accomplish what I want.
Alright so I'm gonna need some logic help here, pseudo code is wonderfully appreciated. Basically I'm making a run of the mill 2D platform game, however I want to do a random twist and have some "randomness" involved. One of my theories was to use a fractal algorithm to create the ground beneath the player. However, I'm SOL on trying to figure out how to do this in a C#, Visual Studios, Windows Form. Yes I know, there are literally about a million better ways and things to use to do this project, however being in a technical school, I don't yet have the ability to freely decide what I work with and how I do it. So I'm limited to that. I'd like to use a 'pass' system with some recursive method calling in order to break the lines into smaller lines and draw an ellipse over each endpoint. At the moment I currently have this: Start the program, and load up a line from one edge of the screen to the other Draw an ellipse in the middle of the line, and store the points of the line (both endpoints) into an array However, I cannot for the life of me figure out how to correctly divide the lines/points
I've been trying to use the leds of my keyboard to visualize my sound output, but when I try to get a reference to my default IMMDevice I get an access violation: [code] Unhandled exception at 0x00CC5DD1 in logiledtest1.exe: 0xC0000005: Access violation reading location 0x00000000. [/code] The access violation appears on the last line: [code] IMMDeviceEnumerator *pEnumerator; const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator); const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator); HRESULT hr = CoCreateInstance( CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&pEnumerator); IMMDevice* device; pEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &device); [/code] edit: well that was stupid, I didn't call "CoInitialize(NULL)" first.
[QUOTE=LennyPenny;43713474]I've been trying to use the leds of my keyboard to visualize my sound output, but when I try to get a reference to my default IMMDevice I get an access violation: [code] Unhandled exception at 0x00CC5DD1 in logiledtest1.exe: 0xC0000005: Access violation reading location 0x00000000. [/code] The access violation appears on the last line: [code] IMMDeviceEnumerator *pEnumerator; const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator); const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator); HRESULT hr = CoCreateInstance( CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&pEnumerator); IMMDevice* device; pEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &device); [/code] edit: well that was stupid, I didn't call "CoInitialize(NULL)" first.[/QUOTE] I don't know if you've fixed it yet but pEnumerator is never set
[QUOTE=AtomiCal;43717236]I don't know if you've fixed it yet but pEnumerator is never set[/QUOTE] It is being set by CoCreateIntance() (last arg) Turned out pretty nice too! Now I just need to find a way to get the levels of certain frequencies instead of just the peak. Right now it only looks cool on songs that go from quiet to loud a lot and looks boring on songs that kinda keep a level.
Does anyone have any experience with internship in computer science institutes? I'll have a four month long internship in a year and for some crazy reason I have to choose where I want to go right now. I can choose between programming, network admin and CS. Computer science sounds interesting, but I don't really know anything about CS institutes.
Does anyone have any guides or tutorials for setting up Sublime Text 2 with a C++ compiler on Windows?
[QUOTE=Laserbeams;43723403]Does anyone have any guides or tutorials for setting up Sublime Text 2 with a C++ compiler on Windows?[/QUOTE] I've tried a couple of times and all I managed to gather from it is that all the plugins for C/C++ development in Sublime are abandoned and a bit crap. It's probably easier not to try, but if you're set on it then look into SublimeClang.
Sorry, you need to Log In to post a reply to this thread.