Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

295 Neutral

About daniel_i_l

  • Rank
    Advanced Member
  1. daniel_i_l

    Using python as a configuration file

    Thanks for the suggestions. I'll take a look at boost and lua.
  2. Hi, I'm writing a program in C++ and want initialize it with a configuration file. I usually use libconfig but in this case I have many similar configuration settings and in many cases it'd be easier to write the configuration file using basic programming constructs like loops. So I thought about using python scripts for the configuration files. The file would contain simple dictionaries and lists which may be constructed either by hand or using basic python scripting. My question is, assuming I have a file called, what's the easiest way to read all of the top level variables (integers, lists, dictionaries) from inside a C++ program? I know that by using the Python C-API I can access dir(config) and then use PyDict_GetItemString to get different variables. But what if I have something like: list1[{'a':1}, {'a':2}] in the file? Is there an easy way to get the value of list1[0]['a'] without having to use multiple specialized C-API calls? I was thinking of something like this: //these line are run once PyRun_SimpleString("import config"); PyObject* module = PyImport_AddModule("__main__"); //these three lines can be used for any amount of nesting PyRun_SimpleString("exec('cVar = config.list1[0][\\'a\\'])"); PyObject* dict = PyModule_GetDict(module); PyObject* result = PyDict_GetItemString(dict, "cVar"); The problem with this is that it's just a hack. Is there any better way to approach this problem?
  3. daniel_i_l

    Lego turing machine

    Hi, A while ago I posted here about making a lego turing machine. In the end lego was too expensive so I used carboplast, popsicle sticks, plastic bottles, rubber bands and a glue gun. Here's the result: The turing machine in the movie can run down the track and flip bits according to a program determined by the wiring. Currently it can only execute simple programs because it doesn't have external memory. But that's theoretically simple to add because I'd just have to build another identical unit that operates on one bit only for each bit of memory.
  4. daniel_i_l

    calculating RGB from intensity

    Ok,I'll look up tone mapping. Thanks for the help.
  5. I writing a basic ray-tracer and have a question about calculating the RGB values for each pixel. To calculate the color of each pixel we send a ray from the camera to the pixel, use the scene to find all the light sources that contribute to the color of the ray, and add up all the contributions. Like the physical world, there's no limit to the intensity of the ray so we can add as many sources as we want. Now my question is, what's the correct way to get the RGB color (with a range of 0-255) from the sum I mentioned above? Because it's possible that the sum of all the colors will give RGB values greater than 255. I could simply clamp the values so they fit but that would remove some detail. Would it be better to find the highest value and then linearly scale so that this highest value goes to 255? Thanks
  6. Quote:Original post by Antheus Which is what std::vector is used for. But what if I want to apply various operators to my vectors? Don't I have to write a new class to do that?
  7. Quote:Original post by Zahlman Why do you need more than one kind of Vector at all? Or at worst, more than a few small sizes? Are you writing some kind of quantum-mechanics simulator or something? Nearly all practical applications don't have to worry about more than 3 dimensions of space, i.e. 3-element vectors or 4x4 matrices (due to homogeneous coordinates). Maybe you'd want a 4-element vector to represent a row or column of a 4x4 matrix, but that's about it. I'm writing a rigid body simulator which solves large systems of equations. In these equations, the system state and forces are represented by one long column vector. They have to be calculated together since they all influence each-other. In addition, my integrator also takes one column vector containing the states of all the bodies and one containing all of the derivatives.
  8. Thanks for all the helpful replies. It seems like I shouldn't be using polymorphism for basic types. Maybe it'd be better to use templates? I could make a class with a signature like: template<class Storage, class Math> Vector; and then to create a vector you'd pass a "Storage" class that has getter and setter functions, and a "Math" class that uses the storage class to do the math. Is that a good idea? Is there a better way to use templates? Thanks
  9. Quote:Original post by imi How do the different implementations of your BasicVec differ? Are they different dimensions of a vector? Then you most probably want a compile time error anyway if you use two different vectors in an equation. IVec* v2d = new My2DVector(5,5); IVec* v3d = new My3DVector(2,2,2); IVec* v = (*v2d) + (*v3d); // I bet you would like to get this caught by the compiler If that's your design, you should go for templates (or better, have a closer look into the STL to reuse code). The different implementations would differ mainly in the way the vector is stored, and in the way the operators are implemented. How would I use templates to create the vectors? Would I have one templated vector class which is initialized with storage and operator options? Thanks
  10. Quote:Original post by jwezorek ... I think it would be easier to help if we knew a little more about what you want to do. What kind of vectors do want to have besides BasicVec? What kind of polymorphic behavior do you want? I want to experiment with both different ways to store the vector and with different ways to implement the various operators. For example, I'd like to try both the standard (basic) way of doing matrix algebra, and also more advanced techniques like meta-programming. Thanks
  11. I'm sorry, I don't understand. How can STL and <algorithm> help with a mathematical vector class? (I now see that I wasn't clear before, I'm trying to implement a mathematical vector, not a container class) Can you explain what you mean when you say that STL and <algorithm> are compile time polymorphism? Thanks.
  12. How can I use concrete types if I want to be able to easily change the implementation? How to typed iterators help? Thanks
  13. I have a Vector class that represents a vector which can have any number of elements. It overloads the obvious operators like + and -. I'd like to try different implementations of the operators so I was thinking of making an abstract vector interface called IVec and deriving all of the vectors from that. But the problem is that if I'm working with pointers to the IVec class, then in order to use the operators I'll have to dereference all the pointers. For example, if BasicVec derives from IVec then I'd have to do something like this: IVec* v1 = new BasicVec(); IVec *v2 = new BasicVec(); //initialize vectors IVec* v3 = (*v1) + (*v2); It doesn't look good to have to dereference the pointers just to use the + operator. This could be phrased as a more general question: How can operators be implemented in a polymorphic base class without having to dereference the pointers to the base class whenever the operators are used? Thanks
  14. Let's say I have the following function: void addOne(double& x) { x+=1; } And I want to expose it to python using boost like this: BOOST_PYTHON_MODULE(add) { using namespace boost::python; def("addOne", addOne); } Now after compiling, when I run: >>>import add it works, but when I do: >>>x = 10.0 >>>add.addOne(x) I get the error: Boost.Python.ArgumentError: Python argument types in add.addOne(float) did not match C++ signature: addOne(double {lvalue}) How can I expose the addOne function so that it works and increments x? Thanks
  15. daniel_i_l

    Numerical Analysis Libraries

    Are there any good open source numerical analysis libraries. Most importantly, I'm looking for one that can solve linear equations, solve ordinary differential equations, and efficiently handle various vector and matrix operations. What do you recommend? Thanks
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!