chipmunk

Pymunk/Chipmunk2d - dynamic bodies colliding with static bodies generating collsion impulses

∥☆過路亽.° 提交于 2021-02-11 12:40:26
问题 simple question, but couldn't find an answer: Can static bodies apply collision impulses to dynamic bodies? here's a little recording of what my code does As you can see, the two dynamic triangles collide with each other, and are stopped by the static line. however, the behavior is not what I want. If I had only one triangle, it would be skidding down the ledge on just one vertex --> the static body does not inflict any sort of torque or counter forces (I'm no physicist) on the triangles.

Pymunk/Chipmunk2d - dynamic bodies colliding with static bodies generating collsion impulses

北城余情 提交于 2021-02-11 12:39:19
问题 simple question, but couldn't find an answer: Can static bodies apply collision impulses to dynamic bodies? here's a little recording of what my code does As you can see, the two dynamic triangles collide with each other, and are stopped by the static line. however, the behavior is not what I want. If I had only one triangle, it would be skidding down the ledge on just one vertex --> the static body does not inflict any sort of torque or counter forces (I'm no physicist) on the triangles.

cocos2d-js Chipmunk刚体:cp.Body 笔记

♀尐吖头ヾ 提交于 2020-04-07 00:53:17
1 游离和静态刚体 一般当我们创建一个刚体并将它添加到空间上后,空间就开始对之进行模拟,包括了对刚体位置、速度、受力以及重力影响等的模拟。没被添加到空间(没有被模拟)的刚体我们把它称之为 游离刚体 。游离刚体最重要的用途就是用来当作静态刚体,但是你仍然可以使用它们来实现直接控制物体,如移动平台。 静态刚体是游离刚体,但被设置了一个特殊的标志以便让Chipmunk知道它们从不移动除非你要求这么做。静态刚体有两个目的。最初,它们被加入用 来实现休眠功能。因为静态刚体不移动,Chipmunk知道让那些与静态刚体接触或者连接的物体安全的进入休眠。接触或连接常规游离刚体的物体从不允许休 眠。静态刚体的第二个目的就是让Chipmunk知道,关联到静态刚体的碰撞形状是不需要更新碰撞检测数据的。Chipmunk也不需要操心静态物体之间 的碰撞检测。通常所有的关卡几何图形都会被关联到一个静态刚体上除了那些能够移动的东西,例如平台或门等。 每一个空间都有一个专用的静态刚体(staticBody),你可以使用它来添加静态形状。Chipmunk也会自动将形状作为静态形状添加到静态刚体上。 2.属性 Chipmunk为刚体的多个属性提供了getter/setter函数。如果刚体在休眠状态,设置大多数属性会自动唤醒它们。如果你想,你也可以直接在 cp.Body 结构体内设置字段。它们都在头文件中有记录。

How to make a dynamic body static in Cocos2d v3.0 with Chipmunk

左心房为你撑大大i 提交于 2020-01-02 00:18:13
问题 I’m using Cocos2d v3 and want to change a body from dynamic to static after colliding with another body. At the moment I’ve got: -(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair static:(CCNode *)nodeA wildcard:(CCNode *)nodeB { _player.physicsBody.type = CCPhysicsBodyTypeStatic; } or -(BOOL)ccPhysicsCollisionPreSolve:(CCPhysicsCollisionPair *)pair static:(CCNode *)nodeA wildcard:(CCNode *)nodeB { _player.physicsBody.type = CCPhysicsBodyTypeStatic; return YES; } but neither

物理模拟(基于定时器的动画 11.2)

烈酒焚心 提交于 2019-12-29 22:25:27
物理模拟 即使使用了基于定时器的动画来复制第10章中关键帧的行为,但还是会有一些本质上的区别:在关键帧的实现中,我们提前计算了所有帧,但是在新的解决方案中,我们实际上实在按需要在计算。意义在于我们可以根据用户输入实时修改动画的逻辑,或者和别的实时动画系统例如物理引擎进行整合。 Chipmunk 我们来基于物理学创建一个真实的重力模拟效果来取代当前基于缓冲的弹性动画,但即使模拟2D的物理效果就已近极其复杂了,所以就不要尝试去实现它了,直接用开源的物理引擎库好了。 我们将要使用的物理引擎叫做Chipmunk。另外的2D物理引擎也同样可以(例如Box2D),但是Chipmunk使用纯C写的,而不是C++,好处在于更容易和Objective-C项目整合。Chipmunk有很多版本,包括一个和Objective-C绑定的“indie”版本。C语言的版本是免费的,所以我们就用它好了。在本书写作的时候6.1.4是最新的版本;你可以从 http://chipmunk-physics.net下载它。 Chipmunk完整的物理引擎相当巨大复杂,但是我们只会使用如下几个类: cpSpace - 这是所有的物理结构体的容器。它有一个大小和一个可选的重力矢量 cpBody - 它是一个固态无弹力的刚体。它有一个坐标,以及其他物理属性,例如质量,运动和摩擦系数等等。 cpShape -

[iOS Animation]-CALayer 定时器动画

雨燕双飞 提交于 2019-12-29 22:25:10
定时器的动画 我可以指导你,但是你必须按照我说的做。 -- 骇客帝国 在第10章“缓冲”中,我们研究了 CAMediaTimingFunction ,它是一个通过控制动画缓冲来模拟物理效果例如加速或者减速来增强现实感的东西,那么如果想更加真实地模拟物理交互或者实时根据用户输入修改动画改怎么办呢?在这一章中,我们将继续探索一种能够允许我们精确地控制一帧一帧展示的基于定时器的动画。 定时帧 动画看起来是用来显示一段连续的运动过程,但实际上当在固定位置上展示像素的时候并不能做到这一点。一般来说这种显示都无法做到连续的移动,能做的仅仅是足够快地展示一系列静态图片,只是看起来像是做了运动。 我们之前提到过iOS按照每秒60次刷新屏幕,然后 CAAnimation 计算出需要展示的新的帧,然后在每次屏幕更新的时候同步绘制上去, CAAnimation 最机智的地方在于每次刷新需要展示的时候去计算插值和缓冲。 在第10章中,我们解决了如何自定义缓冲函数,然后根据需要展示的帧的数组来告诉 CAKeyframeAnimation 的实例如何去绘制。所有的Core Animation实际上都是按照一定的序列来显示这些帧,那么我们可以自己做到这些么? NSTimer 实际上,我们在第三章“图层几何学”中已经做过类似的东西,就是时钟那个例子,我们用了 NSTimer 来对钟表的指针做定时动画

Cocos2d 3.0 + Chipmunk + CCAnimation: moving physics body with animated object. How?

江枫思渺然 提交于 2019-12-25 02:22:11
问题 I have a boat with attached physics body. This boat is static physics body. Boat moving with CCAnimateMoveTo from left to right. When I tap on screen my character fall down. I detect collisions well. But I want that after collision my character just fall on boat and keep moving with it. Character is dynamic body. Link to sample video: Sample video Here I create a boat: - (void)createBoat { currentBoat = [CCSprite spriteWithImageNamed:@"Boat.png"]; currentBoat.position = ccp(0 - currentBoat

How velocity impacts on CCSprite in Cocos2d Chipmunk?

浪子不回头ぞ 提交于 2019-12-24 14:05:04
问题 I am in need of the basic understanding of how velocity changing works? i.e. how CCSprite is able to jump at particular height when some velocity is set? Let me give you an example on which I am working currently. I am preparing a demo like flappy bird, in which I wanted my bird to land on vertical pipes. So, it is like, my birdy jumps from the pipe to another pipe :smile:. Check the gif I place here: https://www.dropbox.com/s/n46vak6qy5wu4x4/jumpyBall_15_jul_152.gif?dl=0 I am using Sprite

Common lisp, CFFI, and instantiating c structs

巧了我就是萌 提交于 2019-12-23 18:29:09
问题 I've been on google for about, oh, 3 hours looking for a solution to this "problem." I'm trying to figure out how to instantiate a C structure in lisp using CFFI. I have a struct in c: struct cpVect{cpFloat x,y;} Simple right? I have auto-generated CFFI bindings (swig, I think) to this struct: (cffi:defcstruct #.(chipmunk-lispify "cpVect" 'classname) (#.(chipmunk-lispify "x" 'slotname) :double) (#.(chipmunk-lispify "y" 'slotname) :double)) This generates a struct "VECT" with slots :X and :Y,

How do you make a sprite rotate in cocos2D while using SpaceManager

拜拜、爱过 提交于 2019-12-23 03:22:38
问题 I just have a simple sprite - how can I get it to rotate? A good answer would show how to rotate both a dynamic sprite and a static_mass sprite 回答1: If the sprite is dynamic / non-static, just do like so: cpBodySetAngVel(ObjSmSprite.shape->body,0.25); For a static body, you can do something like this: [ObjSmStaticSprite.shape runAction:[CCRepeatForever actionWithAction: [CCSequence actions: [CCRotateTo actionWithDuration:2 angle:180], [CCRotateTo actionWithDuration:2 angle:360], nil] ]]; smgr