|
-
Jul 26th, 2024, 12:49 PM
#8
Fanatic Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|