• Advertisement

cowcow

Member
  • Content count

    46
  • Joined

  • Last visited

Community Reputation

3 Neutral

About cowcow

  • Rank
    Member

Personal Information

  • Interests
    Art
    Programming
  1. Thanks for the help!
  2. I'm trying to get void** pointers working with Python's ctypes. Has anyone ever had this kind of experience? I'm trying to print out the value 123.456f; in the Python code. My code is: #define DLLEXPORT extern "C" __declspec(dllexport) DLLEXPORT int func(void **ptr) { float *p = new float; p[0] = 123.456f; ptr = reinterpret_cast<void**>(&p); return 0; } and import ctypes as ct """ DLLEXPORT int func(void **ptr) """ lib = ct.CDLL("void_dll.dll") x = ct.pointer(ct.c_vo) lib.func(ct.byref(x)) print(x)
  3. C++ FreeGLUT - Making Planets Orbit

    Maybe share your code on GitHub to see what went wrong. I think the idea of rotation is good, but it would only handle orbits that are circular (no eccentricity).
  4. C++ FreeGLUT - Making Planets Orbit

    Just in case it's not clear... The gravitation constant G is 6.673e-11. The sun's mass M is 1.989e30. For the planet Mercury: The aphelion distance is 69817079000. The perihelion distance is 46001200000. The semi major axis A is the (perihelion distance + the aphelion distance) / 2 is 57909100000. The eccentricity e is 0.20563069. The orbit speed at aphelion is v = sqrt((G*M/A) * (1 - e)/(1 + e)) = 38860.5.
  5. C++ FreeGLUT - Making Planets Orbit

    Yes, every time the idle function is called, one will do these things to calculate the position and velocity: https://gist.github.com/sjhalayka/a499a7f0429884bf3fd6ef38151ecd58 There is also this Mercury fact sheet, from which you can obtain the speed of mercury at perihelion (closest approach) and aphelion (furthest approach): https://nssdc.gsfc.nasa.gov/planetary/factsheet/mercuryfact.html That is, the speed (the length of the velocity vector) of Mercury at aphelion is 38860 metres per second, like in the code I posted. I'm not super experienced with scene graphs, sorry. In my code I don't use a scene graph -- I just alter the planet object's position and velocity, and then pass the position directly into glVertex3f(). That's right, I use OpenGL 1.x for the demo. All I know is that scene graphs become very important when it comes to solving for inverse kinematics? There's a hierarchy going on there? I checked out Mario Kart for Switch, and they got some serious physics + inverse kinematics to model the idle animations of the contestants. LOL
  6. C++ FreeGLUT - Making Planets Orbit

    I also put up a C++/OpenGL 1.x/GLUT application that draws Mercury's path as it orbits the Sun. To start the simulation, the planet is placed at the aphelion (0, 69817079000, 0), with an initial velocity (-38860, 0, 0), and everything is taken care of from there. https://github.com/sjhalayka/mercury_orbit_glut Check out idle_func() in main.cpp. That's where the integration occurs.
  7. C++ FreeGLUT - Making Planets Orbit

    You alter the position and velocity of each planet by integrating (adding). Your position is updated by the velocity, and the velocity is updated by the acceleration. Here is some math related to calculating a position and velocity for the orbiting body:
  8. Marching Cubes and Dual Contouring Tutorial

    I put up the C++ code for a DLL for Windows on GitHub. The DLL exports a function that takes in all of the quaternion Julia set parameters, as well as parameters related to the 3D grid extent, resolution, etc. I also included a .py file to show how to call the function from the DLL using Python (the function returns the surface normal gotten by the Marching Cubes algorithm). https://github.com/sjhalayka/marching_cubes_dll The relevant C++ file is mc_dll.cpp and the relevant Python file is mc_dll.py It still suffers from a jittery surface. Can't say that I didn't try.
  9. Hell yes, that's exactly what I wanted to do! Thanks again.
  10. I got it all working. Thank you for the information. I am now able to call from Python a function that I wrote which generates the surface normal of a quaternion Julia set using Marching Cubes. My final code is... #define DLLEXPORT extern "C" __declspec(dllexport) DLLEXPORT void get_normal(float x_grid_min, float x_grid_max, float y_grid_min, float y_grid_max, float z_grid_min, float z_grid_max, unsigned int x_res, unsigned int y_res, unsigned int z_res, float *output) { // ... stuff } and... def get_normal_from_mc(src_x_grid_min, src_x_grid_max, src_y_grid_min, src_y_grid_max, src_z_grid_min, src_z_grid_max, src_x_res, src_y_res, src_z_res): float3 = ct.c_float * 3 int1 = ct.c_uint float1 = ct.c_float x_grid_min = float1(src_x_grid_min) x_grid_max = float1(src_x_grid_max) y_grid_min = float1(src_y_grid_min) y_grid_max = float1(src_y_grid_max) z_grid_min = float1(src_z_grid_min) z_grid_max = float1(src_z_grid_max) x_res = int1(src_x_res) y_res = int1(src_y_res) z_res = int1(src_z_res) output_arr = float3() lib = ct.CDLL("mc_dll.dll") lib.get_normal(x_grid_min, x_grid_max, y_grid_min, y_grid_max, z_grid_min, z_grid_max, x_res, y_res, z_res, output_arr) ret = V3(output_arr[0], output_arr[1], output_arr[2]) return ret
  11. OK thank you very much; that seemed to have helped. How would I set up for and call the function from Python: DLLEXPORT int print_normal_to_file(float x_grid_min, float x_grid_max, float y_grid_min, float y_grid_max, float z_grid_min, float z_grid_max, size_t x_res, size_t y_res, size_t z_res, char *filename)
  12. I'm having trouble getting an array filled from a DLL. Here's my DLL code: DLLEXPORT void get_triangles(int *p) { vector<int> ints; ints.push_back(123); ints.push_back(456); p = &ints[0]; } .... and here's the Python code: from ctypes import cdll mydll = cdll.LoadLibrary('mc_dll.dll') arr = [] mydll.get_triangles(arr)
  13. Marching Cubes and Dual Contouring Tutorial

    Anything has got to be better than Marching Cubes by itself. Any chance that you can rewrite the Marching Cubes code to have a function like bool get_fractal_surface_triangles(vector<triangle> &triangles, float x_grid_min, float x_grid_max, float y_grid_min, float y_grid_max, float z_grid_min, float z_grid_max, size_t x_res, size_t y_res, size_t z_res)? I tried to write such a function, but I can't figure out how to alter the marching_cubes_3d_single_cell(f, x, y, z): function. def marching_cubes_3d_2(f, x_grid_min = -1.5, x_grid_max = 1.5, y_grid_min = -1.5, y_grid_max = 1.5, z_grid_min = -1.5, z_grid_max = 1.5, x_res = 100, y_res = 100, z_res = 100): """Iterates over a cells of size one between the specified range, and evaluates f to produce a boundary by Marching Cubes. Returns a Mesh object.""" # For each cube, evaluate independently. # If this wasn't demonstration code, you might actually evaluate them together for efficiency x_step_size = (x_grid_max - x_grid_min) / (x_res - 1) y_step_size = (y_grid_max - y_grid_min) / (y_res - 1) z_step_size = (z_grid_max - z_grid_min) / (z_res - 1) x_loc = x_grid_min y_loc = y_grid_min z_loc = z_grid_min mesh = Mesh() for x in range(0, x_res): y_loc = y_grid_min for y in range(0, y_res): z_loc = z_grid_min for z in range(0, z_res): cell_mesh = marching_cubes_3d_single_cell(f, x_loc, y_loc, z_loc) mesh.extend(cell_mesh) z_loc += z_step_size y_loc += y_step_size x_loc += x_step_size return mesh
  14. Marching Cubes and Dual Contouring Tutorial

    It was worth trying, anyway. Thanks again for the code! I wonder if there's a way to use the Marching Cubes surface normals to bootstrap the Dual Contouring algorithm. Yes, there is... I can generate a portion of the surface near the vertex in question, using Marching Cubes, and then average the triangle normals to get a single normal. I'll let you know when it's done.
  15. Marching Cubes and Dual Contouring Tutorial

    I found the curvature once, marked in dark gray. I'm not sure if this is related?
  • Advertisement