Results 1 to 9 of 9

Thread: VB6 applied physics, using the chipmunk-engine (simple Demo for Starters)

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,356

    VB6 applied physics, using the chipmunk-engine (simple Demo for Starters)

    This simple "Physics-Engine usage for Starters"-Demo depends on the vbRichClient5.dll,
    downloadable here: http://vbrichclient.com/#/en/Downloads.htm

    So, before you can run it you will have to unpack the 3 Dlls from the above linked vbRC5BaseDlls.zip
    into a Folder (e.g. C:\RC5\)... and then only register (in AdminMode) the vbRichClient5.dll per regsvr32.

    There's no need to copy the Dlls into the same Folder where you unpack the Zip of our small Demo-Project here:
    http://vbRichClient.com/Downloads/ChipmunkCairo.zip
    Meaning you can run all further RC5-based Demos directly from within their Unpack-Target-Folders,
    without having to bother again with the (only once) to install RC5-BaseLibs.

    The chipmunk Physic-Engine is wrapped up behind easy to use VB-Classes - no need to take care about
    handle-freeing or other stuff (when you'd be using the "plain-C" chipmunk-API)...

    For 2D-game-developers this should be quite interesting, since it allows all kinds of physics based games,
    which involve e.g. true Car-Physics, or the whole class of "Rubberband-based games" - or shooting some Objects
    around, which will follow true flight-parables with only a given Impulse... or all kind of simpler games where
    Ball-bouncing-Physics are involved.

    The Collision-Detection is sophisticated (respecting Mass, Elasticity, Friction, Momentum) though still quite performant,
    even with a larger amount of moving Objects or irregularly shaped "fixed-bodies" in your scenes.

    This last part, the construction of complex shapes is a speciality I've included in the Wrapper, since it allows
    the Construction of any shape-form with ease over simple Cairo-Drawing-Calls (Cairo-Paths) - and that includes
    even as complex shapes as rendered Text - the Demo here will already demonstrate, that the Ball-Objects take
    even such complex-formed fixed shapes as rendered Text(Paths) seriously in their collisions...

    One can see that easily witht a good look at the ScreenShot below... (where the Balls ended up finally after
    bouncing around) - they "lean on each other" and rest with their bottoms on the TextChars exactly
    (the left Ball on the "dot of an i" - and the right Ball is "hanging" between the highest points of "k" and "h"):



    The Drawing-Capabilities of Cairo include SubPixel-based Rendering of Png-based Sprites, as well as
    normal Vectordrawn-Shapes ... this (antialiased) SubPixelprecision-output is quite important
    especially with slower moving Objects - and cairos internally used Double-Precision matches exactly with
    the Double-Precision each of the Body-Shape-Objects is internally repositioned by the Physics-Engine
    in each (highres) Timer-Step.

    I'll post some more Demos about this Engine, for the moment this simpler one may be sufficient as a
    Base for your own experiments (with different Shapes or maybe only some Fiddling with the Parameters,
    as e.g. the Gravity - or the Elasticity and Friction of the Balls).

    Have fun with it.

    Olaf

  2. #2
    Registered User
    Join Date
    Oct 2013
    Posts
    2

    Re: VB6 applied physics, using the chipmunk-engine (simple Demo for Starters)

    so amazing! expecting more demos .

  3. #3
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,467

    Re: VB6 applied physics, using the chipmunk-engine (simple Demo for Starters)

    Awakening this thread frooooooommmmm the deeeeaAAAAAdddd.

    Olaf, do you have a pendulum example?
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,356

    Re: VB6 applied physics, using the chipmunk-engine (simple Demo for Starters)

    Quote Originally Posted by yereverluvinuncleber View Post
    ...do you have a pendulum example?
    Here's a Demo-Zip: https://vbRichClient.com/Downloads/ChipmunkPendulum.zip

    And here, what it will produce:



    The RC6-chipmunk-wrapper is quite similar to the one for Python (PyMunk) -
    a python-code-based pendulum-construction is covered e.g. by this youtube-vid:
    https://www.youtube.com/watch?v=OJkcRl05gOk

    HTH

    Olaf

  5. #5
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,467

    Re: VB6 applied physics, using the chipmunk-engine (simple Demo for Starters)

    Well, thank you for that. I will give all that a good read.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  6. #6
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    464

    Re: VB6 applied physics, using the chipmunk-engine (simple Demo for Starters)

    Thank you. I have uploaded the latest version of a Matter-driven tear off calendar here:

    https://icontalk.org/matter/index.html

    As one can see, the calendar rotates around the nail (limited by the hole).

    I would like to do this in VB6 instead. I appreciate the Pendulum demo very much.
    Would it be possible to get a kick start on how to assign an image (Cairo surface / context) to such a Chipmunk pendulum?
    This is what I would have to do to convert my matter html project to VB6 / RC6.

  7. #7
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    464

    Re: VB6 applied physics, using the chipmunk-engine (simple Demo for Starters)

    I would like to ask which type of physics object I should choose to represent a hold as seen in this calendar. The calendar can rotate around the nail, and the "inner movement" (I have no idea what I should call it) is limited by the hole.
    I am looking at the ChipmunkPendulum sample, and I am looking for a way to integrate it in that.
    Note the different positions of the nail in respect to the hole in a various screenshots of possible movements when being rotated / given a push.

    Name:  calendar with hole.jpg
Views: 293
Size:  100.9 KB
    Last edited by tmighty2; Jul 23rd, 2024 at 11:54 AM.

  8. #8
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    464

    Re: VB6 applied physics, using the chipmunk-engine (simple Demo for Starters)

    I am using cpBoxShape for the calendar.

    I believe that at drawing, I have to translate the drawing according to the calendar's current center of the shape.

    In the basketball (Chipmunk Cairo) demo, it is done the following way for the ball (which is cpCircleShape):

    CC.TranslateDrawings Shape.tC_X, Shape.tC_Y 'translate the CC to the current center of of the Shape
    CC.RotateDrawings Cairo.CalcArc(Body.Rot_Y, Body.Rot_X) 'now rotate the Coord-System (according to the current Infos in our Body)

    However, "tC_X" and "tC_Y" do not exists for cpBoxShape.

    I thought that I have to calculate it myself using the vertices, but I did not find out how to access them.

    Can somebody tell me how to do this?

    The project is attached, and also here is my code for the calendar class:

    Code:
    Option Explicit
    
    Public Body As cpBody, Shape As cpBoxShape
    
    Public Sub Construct(ByVal X As Double, ByVal Y As Double, ByVal uWidth As Long, ByVal uHeight As Long, ByVal Mass As Double)
    
      Set Body = PhEngine.CreateBody(Mass, PhEngine.GetMomentForBox(Mass, uWidth, uHeight))
      PhEngine.Space.AddBody Body, X, Y
      
      Set Shape = Body.CreateBoxShape(uWidth, uHeight)
      PhEngine.Space.AddShape Shape, 0.78, 0.98
      
      'now - if it does not exists yet in our global Imagelist - we add a small sprite here from an Alpha-JPG-resource
      If Not Cairo.ImageList.Exists("calendar1") Then Cairo.ImageList.AddImage "calendar1", App.Path & "\calendar1.png", 500, 300
    End Sub
    
    Public Sub Draw(CC As cCairoContext, Optional ByVal SimpleOutlineOnly As Boolean)
    
        Static SrfPat As cCairoPattern
        CC.Save
        
        'todo: CC.TranslateDrawings Shape.tC_X, Shape.tC_Y
        CC.RotateDrawings Cairo.CalcArc(Body.Rot_Y, Body.Rot_X)  'now rotate the Coord-System (according to the current Infos in our Body)
        
        'Cairo.ImageList(SomeKey) delivers a Surface-Object (in our case our stored Sprite)
        'and to be able to shift the center of such a Surface-Object (just before we render it below),
        'we need to wrap it beforehand in some lightweight-container-Object, which allows transforms
        'And such a wrapper-object is the cCairoPattern, which can be derived from any Surface by:
        Set SrfPat = Cairo.ImageList("calendar1").CreateSurfacePattern
        
        'now the just mentioned shift "within the Sprite-Pattern", to finally bring
        'the pattern-wrapped Sprite-center into sync with our current center of the CC
        Set SrfPat.Matrix = SrfPat.Matrix.TranslateCoords(SrfPat.Surface.Width / 2, SrfPat.Surface.Height / 2)
        CC.SetSourcePattern SrfPat
        CC.Paint
        
        CC.Restore
    End Sub
    18 Chipmunk-Physics (simple Balls) extended with cal.zip

  9. #9
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    464

    Re: VB6 applied physics, using the chipmunk-engine (simple Demo for Starters)

    There is no documentation which I have overlooked which describe your implementation, right?

Posting Permissions

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



Click Here to Expand Forum to Full Width