dcsimg
Results 1 to 4 of 4
  1. #1

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,194

    C3D Player using DX9

    Version 1.1 released in post #4. But please read this post #1 for details.

    Hi All,

    Okay, I've been pulling together a "player" to play mocap (motion capture) C3D files. These are a binary type file with 3D coordinate (i.e., the C3D) data in them. They can get large, depending on how long a mocap session is, and how many infra-red markers are on a person. There's no executable code in these C3D files. Mostly, they're just IEEE Singles within them.

    Here's a link to a website that completely explains them: https://www.c3d.org/

    I've provided links to a few of them below. I'm hoping the forum moderators won't object to this.

    TestWalk.c3d (this is the one I made into a C3X for early testing)
    Dance.c3d
    March.c3d
    PunchKick.c3d
    Run.c3d

    I'm about at a point in programming my "player" that I'm going to start incorporating it into a larger project. I'll probably use an ActiveX DLL approach. However, after that, it'll be more difficult to share. So, I'd like to share this stand-alone version.

    Also, I want it to be well known that this "player" is heavily based on the SimpleScene demo from The Trick's DX9 work. And a huge thanks goes out to him for his assistance.

    Attached is what I'm thinking/hoping is a fairly well-developed stand-alone version to show the captured 3D points/markers in one of these C3D files. You will need one of the above C3D files to use it. Or you can find your own C3D files. They're all over the web. Just as a caveat, it's possible to capture multiple-people into a single C3D file. However, my C3D reader software doesn't accommodate this situation. Just for those who may try to find their own C3D files. Beyond that limitation, it should "play" a C3D file captured by most of the mocap systems out there (with Vicon and Motion Analysis Corp being the two "big boys").

    Also, the code in the C3dReaderTerse.bas module is VERY old. It works flawlessly and is without-a-doubt some of the most well exercised code I've got, but it could use some "clean up" work. It's just one of those, "if it ain't broke, don't fix it" things.

    As another note, there's a single registry setting in this code. I do that so the common dialog will start in the same folder as the last folder you explored to. It's just a convenience, and I only mention it because some people don't like programs that mess with the registry. You could comment those lines out with no harm done.

    If you have any interest in mocap, C3D files, and/or programming with DirectX9, this may be of interest to you.

    Also, the TimerEx.cls Class is self-instantiating. You can just throw it into any project, and have the equivalent of a Timer function like the VB6 Timer function, but it's named TimerEx and much higher precision. No need to instantiate nor create a variable for it ... just use it (after putting TimerEx.cls into your project).

    Respectful critiques and suggestions are encouraged.

    The Trick's dx9vb.tlb is necessary for this project. You can certainly get it from his CodeBank post to which I linked above. However, I'll go ahead and attach it here as well. I zipped it. I included both the TLB and the IDL file. I'll assume you know how to reference and/or register this TypeLib for use with a VBP project. The easiest way is to put it in System32 (or SysWOW64 for Windows-64-bit systems) and then register it with the RegTLib command-line utility.

    Enjoy,
    Elroy
    Attached Files Attached Files
    Last edited by Elroy; May 17th, 2018 at 08:00 AM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  2. #2
    Fanatic Member
    Join Date
    Feb 2015
    Posts
    1,007

    Re: C3D Player using DX9

    Great work! I'm glad my library was helpful.
    BTW, you can accelerate picking. You can cache the mesh bounds and check at first if a ray intersects bounds (rough checking and more cheap) if so you can test it more accurate with triangles. Also because you use only the spheres, you don't need to find intersection between the screen ray and all triangles in the sphere mesh, you can find the intersection between the screen ray and the sphere. It ensures no camera freezing while you select a point.

  3. #3

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,194

    Re: C3D Player using DX9

    Hi Trick,

    Thanks for the vote of confidence. This was/is truly a fun project.

    I'll definitely look into speeding up the mesh-selection code. The caching of bounds sounds like a good idea, as I'll never be dynamically resizing anything. And always, at least 50% of what I'll be rendering will be spheres, so I'll definitely read your link.

    However, it won't always be this simple. For instance, there are certain (calculated) markers that represent knee-center, ankle-center, etcetera. My next step is to have an option to render "connecting rods" between these joint-centers, and we will need to select those also.

    I just released this spheres-only version for the sake of "calling something done". I can see how one could get lost in this stuff, never to be seen again.

    Also, I figured out how to keep a stand-alone version of this thing. I just created two VBP files, one for the ActiveX DLL (with a controlling class module), and then other for the stand-alone EXE (without the controlling class). It seems to work perfectly. Therefore, I'll probably be releasing more versions in this thread, in the future.

    All The Best,
    Elroy

    EDIT1: By the way, I've already incorporated it into my primary project. It only took me about an hour:

    Name:  Player.jpg
Views: 39
Size:  43.5 KB
    Last edited by Elroy; May 16th, 2018 at 09:18 AM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  4. #4

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,194

    Re: C3D Player using DX9

    Okay, here's Version 1.1 (attached).

    Off the top of my head, here are the changes/enhancements that have been made:
    • Reworked mesh HitTest so that it works much faster if only spheres are being searched.
    • Added a "Render First Frame" button.
    • The selected mesh/sphere now shows its coordinates as the "movie" plays.
    • The selected mesh is shown in a different color.
    • There's a bit of subclassing so the mousewheel will work as another way to zoom.
    • It can be compiled as either an ActiveX DLL or a stand-alone, but this is the stand-alone version.


    Don't forget that it'll still need Trick's DX9 TypeLib which is in the first post. Also, you'll need some C3D files (from somewhere) to see what it actually does.

    Enjoy,
    Elroy

    EDIT1 @Trick: Here's the code I developed to get the HitTest going for spheres. I actually also did some timing tests, and it turned out the slowdown was about evenly split between fetching the vector buffer and looping through the triangles for hit tests. I guess the fetch of the vector buffer was slow because of some kind of wait-state being imposed by the video card. I don't really know, but it was slow.

    However, using the circle's radius for the HitTest obviated the need for the vector buffer and the triangle loop. It's much faster now. In fact, I've deleted the CheckBox to turn selection on/off. It's just on all the time now.

    This code is organized the way I like things, but you're welcome to put it into your DX9 math library, and rework it into your style.

    Code:
    
    Public Function DxVecIntersectsSphere(fRadius As Single, uFrom As D3DVECTOR, uDir As D3DVECTOR) As Boolean
        ' The uFrom and uDir vectors have already been centered for the sphere's position.
        ' This is all worked out from here: https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection
        '                          or here: https://en.wikipedia.org/wiki/Line-sphere_intersection
        Dim fDot As Single
        '
        fDot = DxVecDot(uDir, uFrom)
        DxVecIntersectsSphere = fDot * fDot - DxVecLengthSq(uFrom) + fRadius * fRadius >= 0!
    End Function
    
    
    Attached Files Attached Files
    Last edited by Elroy; May 16th, 2018 at 05:46 PM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.