• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=ZeekyHBomb;41208205] That book seemed to have been released just two months ago. I guess not many people have taken a look at it yet. I thought Learn C++ in 21 Days (newer revisions go by a slightly different title) was a good one, some others on this forum have made positive comments about Accelerated C++. Effective C++ by Scott Meyers is a good intermediate book, I definitively recommend to read it after you can write some C++.[/QUOTE] Ahh, I understand, but I need a book that teaches from scratch, however I will look into it, I appreciate it a lot, thank you.
Learn C++ in 21 Days and Accelerated C++ both are books designed for beginning programming. Effective C++ is the only one I mentioned that is meant for intermediate programmers.
This code is giving me the following error: "conversion from 'Coord3D' to non-scalar type 'Vector3D' requested|". It happens at the line "Vector3D c = a + b;". I want to have the functions from Coord3D carry over to Vector3D, and I expected them to do so since Vector3D inherited Coord3D. What am I doing wrong? [code] #include <iostream> using namespace std; class Coord3D { public: float x, y, z; Coord3D (float = 0.0f, float = 0.0f, float = 0.0f); Coord3D operator + (Coord3D); }; Coord3D::Coord3D (float a, float b, float c) { x = a; y = b; z = c; } Coord3D Coord3D::operator+ (Coord3D param) { Coord3D temp; temp.x = x + param.x; temp.y = y + param.y; temp.z = z + param.z; return temp; } class Vector3D: public Coord3D { public: Vector3D (float a, float b, float c) : Coord3D(a, b, c) {}; }; int main () { Vector3D a (3, 4, 5); Vector3D b (6, 7, 8); Vector3D c = a + b; return 0; } [/code]
[QUOTE=ZeekyHBomb;41208205]According to [url=http://www.mono-project.com/Interop_with_Native_Libraries#Invoking_Unmanaged_Code]this page[/url] the default calling convention on Linux is cdecl, and that should be correct. The library could be set to use another calling convention via compiler flag, but I think that's unlikely since interfacing with it in C would also not be straight forward. As a workaround you could reverse the order of parameters in the declaration, but I don't know how you'd fix the actual problem. You could perhaps try to ask in the CritterAI community if anyone has already interfaced with the lib in a .NET language. [editline]27th June 2013[/editline] That book seemed to have been released just two months ago. I guess not many people have taken a look at it yet. I thought Learn C++ in 21 Days (newer revisions go by a slightly different title) was a good one, some others on this forum have made positive comments about Accelerated C++. Effective C++ by Scott Meyers is a good intermediate book, I definitively recommend to read it after you can write some C++.[/QUOTE] The calling convention is further affected by the architecture. I don't use linux myself but on x86-64 I think it passes more args in registers
[QUOTE=elevate;41209078]This code is giving me the following error: "conversion from 'Coord3D' to non-scalar type 'Vector3D' requested|". It happens at the line "Vector3D c = a + b;". I want to have the functions from Coord3D carry over to Vector3D, and I expected them to do so since Vector3D inherited Coord3D. What am I doing wrong? -code-[/QUOTE] If it works the same as in C# then the operands on the + operator (I can't find the definition for binary +?) are cast to Coord3D before the static operator is applied and the result is a Coord3D, not a Vector3D which can't be cast to the derived type.
Is there any "elegant" way to draw a sphere in OpenGL using shaders, or should I just draw a mesh which approximates one?
[QUOTE=thf;41209484]Is there any "elegant" way to draw a sphere in OpenGL using shaders, or should I just draw a mesh which approximates one?[/QUOTE] You can use a billboard, then calculate the fragment depth from the distance from the centre and the projection but it's likely slower than a geometry-based solution.
[QUOTE=Tamschi;41209517]You can use a billboard, then calculate the fragment depth from the distance from the centre and the projection but it's likely slower than a geometry-based solution.[/QUOTE] Oh well. I should probably just do it the ugly way then.
[QUOTE=thf;41209558]Oh well. I should probably just do it the ugly way then.[/QUOTE] If you rotate the mesh towards the camera you can give the edge more detail and only draw a half-sphere. Still not 100% accurate but it should give better results with the same amount of triangles. This should get rid of the edge jitter on rotating spheres, but you may have to manipulate UVs or scroll the texture in the shader.
Noob git question: I'm building my first real Java project (outside university), and I've used an external .jar library. If someone were to clone the repo, they would only get the source files I've written, right? Would I have to link people to download the library themselves, or am I 'gitting' this all wrong?
You'll want a build-system. [url=https://en.wikipedia.org/wiki/Apache_Maven]Maven[/url] is one I know is (at least somewhat) popular in the Java community. You can define the dependency there and when anyone attempts to build your project without having the dependency satisfied they'll get a (hopefully, that is if the build system is good) descriptive message about what's missing and should be installed.
I am getting confused by OpenGL model manipulation. I read that the order of operations would be to scale, rotate, then translate. I scaled an object to be 100 times smaller than it is, then translated it. However, the translation was also scaled by the size of the object, which is not what I want. I tried translating then scaling, which worked correctly. But when should I scale? I am quite confused by this. I read somewhere else that the correct order is opposite, it is translate, rotate, then scale. Can someone explain to me how it should be? And why it's rotate then scale rather than scale then translate or whatever the real order is.
IIRC the correct order is to scale, rotate then translate (in fact I think the order of scale and rotate does not matter). Matrices in opengl are column-major, which means that you need to reverse this order.
[QUOTE=ZeekyHBomb;41208205]According to [url=http://www.mono-project.com/Interop_with_Native_Libraries#Invoking_Unmanaged_Code]this page[/url] the default calling convention on Linux is cdecl, and that should be correct. The library could be set to use another calling convention via compiler flag, but I think that's unlikely since interfacing with it in C would also not be straight forward. As a workaround you could reverse the order of parameters in the declaration, but I don't know how you'd fix the actual problem. You could perhaps try to ask in the CritterAI community if anyone has already interfaced with the lib in a .NET language.[/QUOTE] So I did some more testing and isolated the issue. Structs are being passed incorrectly. The struct parameters are being "skipped" and (with enough parameters) tacked on to the end, it's not actually backwards. [editline]27th June 2013[/editline] At this point I'm convinced it's a runtime bug, so I submitted a bug report: [url]https://bugzilla.xamarin.com/show_bug.cgi?id=12925[/url]
[QUOTE] Error 7 error LNK2019: unresolved external symbol "public: unsigned int __thiscall Bootil::Buffer::GetSize(void)const " (?GetSize@Buffer@Bootil@@QBEIXZ) referenced in function _main c:\Users\formatme\documents\visual studio 2012\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.obj ConsoleApplication2 [/QUOTE] I have a 9 link errors like this i dont understand could someone help me out thanks.
[QUOTE=Tamschi;41209313]If it works the same as in C# then the operands on the + operator (I can't find the definition for binary +?) are cast to Coord3D before the static operator is applied and the result is a Coord3D, not a Vector3D which can't be cast to the derived type.[/QUOTE] So what can I do about it? Do I have to write functions for Vector3D, because that's very verbose and completely defeats the purpose of using OOP in this example at least.
Without adding a += operator this will not be possible (in a clean way anyway), because there's no guarantee that Vector3D (or any other hypothetical class inheriting from Chord3D) will not have additional members. The operator+ for Chord3Ds only allocates and initializes memory for a Chord3D, so it could not account for potential additional members. If you have a += operator, then you can easily implement the operator+ in terms of the operator+=: [cpp]Chord3D operator+(const Chord3D &lhs, const Chord3D &rhs) { Chord3D temp = lhs; temp += rhs; return temp; } //same for Vector3D[/cpp] The reason that works fine via operator+= is that it works on a constructed object, so you only need minimal code for the operator+ to construct the temporary Vector3D and use the operator+= for the actual add-implementation. You might find [url=http://www.boost.org/doc/libs/1_53_0/libs/utility/operators.htm]Boost.Operators[/url] handy for automatically adding a bunch of operators. Also, if you're using C++11 you'll want to std::move that temp.
snipo
Could you potentially strap the razer hydra to your legs and use that to try and simulate walking in a game. Imagine having a character that is controlled by your feet, and giving there upper body physics so they flop around when you walk. That would be funny as fuck
[QUOTE=ZeekyHBomb;41216163]Without adding a += operator this will not be possible (in a clean way anyway), because there's no guarantee that Vector3D (or any other hypothetical class inheriting from Chord3D) will not have additional members. The operator+ for Chord3Ds only allocates and initializes memory for a Chord3D, so it could not account for potential additional members. If you have a += operator, then you can easily implement the operator+ in terms of the operator+=: [cpp]Chord3D operator+(const Chord3D &lhs, const Chord3D &rhs) { Chord3D temp = lhs; temp += rhs; return temp; } //same for Vector3D[/cpp] The reason that works fine via operator+= is that it works on a constructed object, so you only need minimal code for the operator+ to construct the temporary Vector3D and use the operator+= for the actual add-implementation. You might find [url=http://www.boost.org/doc/libs/1_53_0/libs/utility/operators.htm]Boost.Operators[/url] handy for automatically adding a bunch of operators. Also, if you're using C++11 you'll want to std::move that temp.[/QUOTE] Oh, you could also provide a Vector3D(const Chord3D&) constructor, which can then implicitly initialize a Vector3D from a Chord3D.
So, the other day I was thinking about probability, and how to write a function that would return true or false on the basis of some probability: For example, P(0.9) would, if run millions of times, return true ~90% of the time. I think the way to do this would be: Generate a random number in the [0,1] range, and if that number is lesser than or equal to the input probability (ie falls within the [0,probability] range) then the function returns true, otherwise false. Is this a valid way to go about this?
Yes. However note that many random number generators are actually pseudo random number generators. And many languages (at least the popular ones) provide this functionality as part of their standard library; Some even with more precise control over the distribution of the "random" numbers.
[QUOTE=ZeekyHBomb;41226230]However note that many random number generators are actually pseudo random number generators.[/QUOTE] Oh, I'm aware, I was just talking about it in the abstract sense. [QUOTE=ZeekyHBomb;41226230]And many languages (at least the popular ones) provide this functionality as part of their standard library[/QUOTE] Do you mean random number generation or weighted choice?
Sorry, I don't remember what I meant. I've probably had an inconsistency in my thoughts. [editline]28th June 2013[/editline] That they provide RNGs would fit, but you probably knew that.
Holy shit, why is it so impossible to find an algorithm that gets the point of intersection between two lines in three dimensional space? I'm going to fucking rip my hair out if I cannot find an algorithm soon. I have been spending ALL DAY looking for one, but I can't find one.
[QUOTE=elevate;41236630]Holy shit, why is it so impossible to find an algorithm that gets the point of intersection between two lines in three dimensional space? I'm going to fucking rip my hair out if I cannot find an algorithm soon. I have been spending ALL DAY looking for one, but I can't find one.[/QUOTE] There is none because you can't compare floats. You can get the point of least distance though. [editline]edit[/editline] I don't know it off the top of my head, but you can get direction of the distance with the cross product between the line directions.
[QUOTE=elevate;41236630]Holy shit, why is it so impossible to find an algorithm that gets the point of intersection between two lines in three dimensional space? I'm going to fucking rip my hair out if I cannot find an algorithm soon. I have been spending ALL DAY looking for one, but I can't find one.[/QUOTE] Lines don't usually intersect in 3D. If the lines do intersect, the problem is reducible to a 2-dimensional case (as they must lie on the same plane to intersect, meaning that there is a dimension where their coordinates do not matter as they're zero).
Actually, I think I changed my mind. I do want to attempt to render a sphere using the billboarding technique. Is it possible (and practical) to texture it as well?
[QUOTE=thf;41238603]Actually, I think I changed my mind. I do want to attempt to render a sphere using the billboarding technique. Is it possible (and practical) to texture it as well?[/QUOTE] It should be, but I think it adds a bit more computations than the depth and you have to transform them afterwards for the rotation. Make sure you don't just use an orthographic projection, each pixel has to be transformed individually into perspective if you want a perfect result... I think the best option is actually the same method as ray-tracing, you just emit the data from a fragment shader instead of storing it in a texture. You should find plenty of code samples if you search for it that way.
[QUOTE=Matthew0505;41249525]What is the scope of an anonymous array passed into a function parameter in C? For example, does the last instruction (*glob = 2) have defined or undefined behaviour? [code] int *glob; void dosomething(int *n) { glob = n; } void main() { dosomething((int[]){0}); *glob = 2; } [/code][/QUOTE] Its storage duration extends to the surrounding block, so the behaviour is defined. And it's static if it's outside of a function body.
Sorry, you need to Log In to post a reply to this thread.