Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Slice Sprites and COM (Center of mass)

Author
Message
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 12th Nov 2014 23:47 Edited at: 12th Nov 2014 23:53
Hi there,

I made a Slice through Sprites Demo and got a problem with the center of mass.
Now when i cut through a sprite I get two images each with Alpha=0 on the other side of the line.
The Image With and Height don't change.
Then I apply polygoncollision via SetSpriteShape(SpriteID,3) and SetSpritePhysicsOn(SpriteID,2)
So it can happen that the center of mass is not there where it should be.

What can I do?
I dont realy want to write an algorithm for that...
But ... if there is no way ..maybe someone did it already ???

Picture of my problem:


Attachments

Login to view attachments
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 12th Nov 2014 23:49 Edited at: 12th Nov 2014 23:50
Picture of what i have:


Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 13th Nov 2014 09:21 Edited at: 13th Nov 2014 09:22
Have you tried: CalculateSpritePhysicsCOM( iSpriteIndex ) ?

Edit: looking forward to seeing that demo. Very useful code
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 13th Nov 2014 13:10
Thank you baxlash,

didn't saw that command.
But it does not solve my problem.
Quote: "
If the COM is very different from the offset point the sprite may seem unstable as it will behave like an unbalanced spinning top."

That's the case.

Does the COM calculation work better if the atached images boundingbox fits the shape?

Aww.. don't want to calculate a fitting bounding box

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 13th Nov 2014 13:46
Ok, try using SetSpritePhysicsDelete( iSpriteIndex ) and then set the sprite up for physics as if it was a new sprite?
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 13th Nov 2014 14:49 Edited at: 13th Nov 2014 15:06
What I tried without success:

SetSpritePhysicsDelete(SliceSpriteID)
ClearSpriteShapes(SliceSpriteID)
SetSpriteShape(SliceSpriteID,3)
SetSpritePhysicsOn(SliceSpriteID,2)
CalculateSpritePhysicsCOM(SecondSpriteID)

Not only that bundle, but also a combination of them.

Damn.. do u see the underlined SpriteID? that was the mistake...
I realized it after i typed that post.
It is the ID for the other half of the cutted Sprite.. so only one sprite behaved corect.
Now it works ..and the manny thanks goes toooo baxslash


Ill put everything in a function, maybe functions if i want to make 2D portals possible.

Another problem is that I use GetImage() for the modyfied image.
Actually im using a shader to cut the image, but it does't change the image itself so I must get the image data after rendering.
Then I just get the image from the buffer and update the sprite.
But it can happen that there is another sprite in the background.
I tried render to image but the sprite was streched.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 13th Nov 2014 16:53
Sometimes if you look at something too much it becomes invisible... normal programming mistake

Can't wait for the code although I would love to attempt it myself as an interesting challenge
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 13th Nov 2014 17:13 Edited at: 13th Nov 2014 17:32
Now everything works like a charm.
Clearscreen solved my last problem.
And i have 4 functions:


I'll send the code to you.
It was much of work and I made several atempts to get the right math.

Login to post a reply

Server time is: 2024-11-25 11:38:50
Your offset time is: 2024-11-25 11:38:50