BOS最佳入门_Web应用II

合集下载

HTML5游戏开发-Box2dWeb应用(一)-创建各种各样的刚体

HTML5游戏开发-Box2dWeb应用(一)-创建各种各样的刚体

本篇开始,会介绍lufylegend-1.4.0的新功能,怎样结合box2dweb 创建一个物理世界以及这个物理世界里的各种刚体准备工作首先你需要下载html5开源库件lufylegend-1.4.0/lufy_legend/article/details/7644932box2dweb你可以到这里下载/p/box2dweb/downloads/list准备三张图片,分别用来创建圆形,矩形和三角刚体。

准备结束,现在开始制作。

下面是利用lufylegend.js中的LLoadManage类来读取图片[javascript]view plain copy1.init(10,"mylegend",800,400,main);2.var backLayer,cLayer,wallLayer,bitmap,loadingLayer;3.var imglist = {};4.var imgData = new Array(5. {name:"bird1",path:"./images/bird1.png"},6. {name:"bird2",path:"./images/bird2.png"},7. {name:"stage01",path:"./images/stage01.png"}8. );9.function main(){10. LGlobal.setDebug(true);11. backLayer = new LSprite();12. addChild(backLayer);13.14.15. loadingLayer = new LoadingSample3();16. backLayer.addChild(loadingLayer);17. LLoadManage.load(18. imgData,19.function(progress){20. loadingLayer.setProgress(progress);21. },22.function(result){23. imglist = result;24. backLayer.removeChild(loadingLayer);25. loadingLayer = null;26. gameInit();27. }28. );29.}LGlobal.setDebug(true);是开启debug模式,这样在创建刚体的时候,会将box2dweb所创建的debug刚体也一起显示出来,发布成品的时候,应该关闭debug模式。

WEB_2.0应用及简介

WEB_2.0应用及简介

通过互联网把自己的智慧、知识、能力、 威客:通过互联网把自己的智慧知道、新浪爱问、雅虎知识堂 ) 播客:一种在互联网上发佈并允许用户订阅 以自动接收新文件的方法, 以自动接收新文件的方法,或用此方法来制作的电台 节目。 节目。 土豆、优酷……) (土豆、优酷 ) 微博( 微博(Twitter): 博客的精简版,有较为严格的 ) 博客的精简版, 字数限制。更简单的发布流程和更随意的写作方式, 字数限制。更简单的发布流程和更随意的写作方式, 使得参与到网络内容贡献中的门槛降低, 使得参与到网络内容贡献中的门槛降低,更大程度的 推动了网络内容建设和个体信息贡献。 推动了网络内容建设和个体信息贡献。 新浪、腾讯微博……) (新浪、腾讯微博 )
2.时间问题 时间问题
●WEB 2.0里有价值的东西太多,看不过来 里有价值的东西太多, 里有价值的东西太多
●每天都可以发现新的博客、新的人物、新的链接、新的观 每天都可以发现新的博客、新的人物、新的链接、 接受不过来, 点,接受不过来,也管理不过来
3.个人知识管理问题凸显 个人知识管理问题凸显
●加强对信息和知识的分类
网站交换链接、互惠链接、互换链接、 友情链接:网站交换链接、互惠链接、互换链接、联盟链 接等,是具有一定资源互补优势的网站之间的简单合作形式, 接等,是具有一定资源互补优势的网站之间的简单合作形式, 即分别在自己的网站上放置对方网站的LOGO图片或文字的 即分别在自己的网站上放置对方网站的 图片或文字的 网站名称,并设置对方网站的超链接(点击后 点击后, 网站名称,并设置对方网站的超链接 点击后,切换或弹出 另一个新的页面), 另一个新的页面 ,使得用户可以从合作网站中发现自己的 网站。 网站。
1.网站应该能够让用户把数据在网站系统内 网站应该能够让用户把数据在网站系统内 外倒腾; 外倒腾; 2.用户在网站系统内拥有自己的数据 ; 用户在网站系统内拥有自己的数据 3.完全基于 完全基于Web,所有的功能都能透过浏览 完全基于 , 器完成。 器完成。

box2d 用法

box2d 用法

box2d用法Box2D是一款非常流行的物理引擎,广泛应用于游戏开发、机器人模拟等领域。

它提供了一个简单而强大的API,可以模拟真实的物理世界,让开发者能够轻松地实现各种物理效果。

在本篇文章中,我们将介绍Box2D的基本用法,包括它的安装、基本概念和示例代码。

一、安装Box2D要使用Box2D,首先需要在开发环境中引入它的库。

通常情况下,Box2D提供了动态链接库(DLL)或静态库(.a文件),可以通过拖放或导入的方式将其添加到项目中。

此外,还需要在项目中链接相应的Box2D头文件。

二、基本概念1.物体(Body):Box2D中的物体表示物理世界中的对象,如墙壁、球体、刚体等。

物体由质量、形状和速度等属性描述。

2.关节(Joint):Box2D中的关节用于连接两个物体,以实现它们之间的相互作用。

常见的关节类型包括弹簧关节、固定关节和滑轮关节等。

3.边界(Shape):边界用于定义物体的形状和尺寸,以便在模拟中计算碰撞和受力。

Box2D提供了多种边界类型,如圆形边界、矩形边界和多边形边界等。

4.世界(World):世界是Box2D中的模拟环境,包含多个物体和关节。

开发者可以通过设置重力、模拟时间等参数来控制世界的行为。

三、示例代码下面是一个简单的Box2D示例代码,用于创建一个球体并模拟其运动:```cpp//创建世界b2World*world=newb2World();//创建球体b2BodyDefbodyDef;bodyDef.type=b2_dynamicBody;//动态球体bodyDef.position.Set(0.0f,10.0f);//球体位置b2Body*body=world->CreateBody(&bodyDef);//设置球体形状和摩擦力b2CircleShapecircle;circle.m_radius=0.5f;//球体半径body->CreateFixture(&circle,1.0f);//摩擦力系数为1.0f//模拟移动球体for(inti=0;i<100;i++){//更新世界时间步长world->Step(1.0f/60.0f,10,10);//设置球体的速度和角度变化body->SetLinearVelocity(b2Vec2(body->GetLinearVelocity().x*cos(i*(M_PI/180.0f)),body->GetLinearVelocity().y*sin(i*(M_PI/180.0f)));body->SetAngle(body->GetAngle()+i*(M_PI/180.0f);}```这段代码创建了一个动态球体,并在模拟中移动它。

box2d项目开发实例

box2d项目开发实例

box2d项目开发实例Box2D是一个用于2D物理模拟的开源C++库,可以用于开发游戏和模拟应用程序。

本文将介绍一些使用Box2D进行项目开发的实例。

1. 弹球游戏弹球游戏是一个经典的使用物理引擎的例子。

开发者可以利用Box2D的碰撞检测功能和力的模拟,实现球体的弹跳和碰撞效果。

通过设置不同形状的刚体以及施加力的方向和大小,可以实现球体在不同环境下的运动效果,增加游戏的趣味性。

2. 平衡木游戏平衡木游戏是一种需要平衡技巧的益智游戏。

利用Box2D的刚体和关节系统,开发者可以创建一个平衡木,并在其上放置物体。

通过模拟物体的重力和关节的受力情况,可以实现平衡木上物体的平衡和倾斜效果。

玩家需要通过调整物体的位置和重心来保持平衡,挑战自己的平衡能力。

3. 弹射游戏弹射游戏是一种利用弹簧力和重力的物理模拟游戏。

开发者可以利用Box2D的关节系统和力的模拟,创建弹簧和物体之间的连接,并施加力来模拟弹射效果。

通过调整弹簧的弹性系数和施加力的大小,可以实现不同力度的弹射效果,增加游戏的挑战性。

4. 碰撞仿真碰撞仿真是一种用于模拟物体之间碰撞效果的技术。

利用Box2D的碰撞检测功能和材质属性,开发者可以模拟不同形状和材质的物体之间的碰撞效果。

通过设置物体的质量、形状和摩擦系数,可以实现不同碰撞情况下物体的运动轨迹和反弹效果,用于游戏开发和物理仿真。

5. 车辆模拟车辆模拟是一种用于模拟车辆运动和碰撞效果的技术。

利用Box2D 的车辆关节和碰撞检测功能,开发者可以创建车辆模型,并模拟车辆的运动和转向效果。

通过施加力和转向角度,可以实现车辆在不同地形和碰撞情况下的运动效果,用于游戏开发和驾驶模拟。

总结:以上是一些使用Box2D进行项目开发的实例。

通过利用Box2D的物理引擎功能,开发者可以实现丰富多样的物理效果,增加游戏的趣味性和真实感。

无论是弹球游戏、平衡木游戏还是弹射游戏,都可以通过合理设置刚体、力和关节等参数,实现各种有趣的物理效果。

box2d入门教程

box2d入门教程

Box2DFlash v2.0.2User manualLargely cribbed unauthorized from the Box2D manual,copyright2007-2009Erin Catto. AboutBox2DFlash is a2D rigid body simulation library for games.Programmers can use it in their games to make objects move in believable ways and make the world seem more interactive.From the game's point of view a physics engine is just a system for procedural animation.Rather than paying(or begging)an animator to move your actors around,you can let Sir Isaac Newton do the directing.Box2DFlash is written in AS3,and resides in the Box2d namespace.Most of the types defined in the engine begin with the b2prefix,to match the C++version.PrerequisitesIn this manual I'll assume you are familiar with basic physics concepts,such as mass, force,torque(扭转力),and impulses(推力).If not,please first consult(翻阅)the many tutorials provided by Chris Hecker and David Baraff(google these names).You do not need to understand their tutorials in great detail,but they do a good job of laying out the basic concepts that will help you use Box2D.Wikipedia is also an excellent source of physics and mathematics knowledge.In some ways it is more useful than Google,because it has carefully crafted content.This is not a prerequisite,but if you are curious about the inner workings of Box2D,you can look at these articles.Since Box2DAS3is written in Actionscript3,you are expected to be experienced in this.If you come from an AS2background,you may find it easier to start on an easier project before using Box2D,but it is not impossible.Core ConceptsBox2D works with several fundamental objects.We briefly define these objects here and more details are given later in this document.rigid body(刚体)A chunk of matter(物质)that is so strong that the distance between any two bits ofmatter on the chunk is completely constant.They are hard like a diamond.In the following discussion we use body interchangably with rigid body.shapeA2D piece of collision geometry that is rigidly attached to a body.Shapes have material properties of friction and restitution.(依附于body的2d碰撞几何结构,具有摩擦和恢复特性)Constraint(约束)A constraint is a physical connection that removes degrees of freedom from bodies.In2D a body has3degrees of freedom.If we take a body and pin it to the wall(like a pendulum)we have constrained the body to the wall.At this point the body can only rotate about the pin,so the constraint has removed2degrees of freedom.contact constraint(接触约束)A special constraint designed to prevent penetration(穿透)of rigid bodies and tosimulate(模仿)friction and restitution.You will never create a contact constraint,they are created automatically by Box2D.jointThis is a constraint used to hold two or more bodies together.Box2D supports these joint types:revolute,prismatic,distance,and more.Joints may support limits and motors.joint limitA joint limit restricts the range of motion of a joint.For example,the human elbow onlyallows a certain range of angles.joint motorA joint motor drives the motion of the connected bodies according to the joint'sdegrees of freedom.For example,you can use a motor to drive the rotation of an elbow.worldA physics world is a collection of bodies,shapes,and constraints that interact together.Box2D supports the creation of multiple worlds,but this is usually not necessary or desirable.Hello Box2DThis is a small example program that creates a large ground box and a small dynamic box. This code does not contain any graphics,so prepare to be underwelmed.:).The matching documents for this example have yet to be created.Creating a WorldEvery Box2D program begins with the creation of a world object.This is the physics hub that manages objects,and simulation.To create a world object,first we need to define a bounding box for the world.Box2D uses the bounding box to accelerate collision detection.The size isn't critical,but a better fit will improve performance.It is better to make the box too big than to make it too small.view sourceprint?1varworldAABB:b2AABB=newb2AABB();2worldAABB.lowerBound.Set(-100.0,-100.0);3worldAABB.upperBound.Set(100.0,100.0);CautionThe world AABB should always be bigger then the region where your bodies are located. It is better to make the world AABB too big than too small.If a body reaches the boundary of the world AABB it will be frozen and will stop simulating.Next we define the gravity vector.Yes,you can make gravity go sideways(or you could just rotate your monitor).Also we tell the world to allow bodies to sleep when they come to rest.A sleeping body doesn't require any simulation.view sourceprint?1vargravity:b2Vec2=newb2Vec2(0.0,-10.0);2vardoSleep:Boolean=true;Now we create the world object.view sourceprint?1varworld:b2World=newb2World(worldAABB,gravity,doSleep);So now we have our physics world,let's start adding some stuff to it.Creating a Ground BoxBodies are built using the following steps:1Define a body with a position,damping,etc.2Use the world object to create the body.3Define shapes with geometry,friction,density,etc.4Create shapes on the body.5Optionally adjust the body's mass to match the attached shapes.For step1we create the ground body.For this we need a body definition.With the body definition we specify the initial position of the ground body.view sourceprint?1vargroundBodyDef:b2BodyDef=newb2BodyDef();2groundBodyDef.position.Set(0.0,-10.0);For step2the body definition is passed to the world object to create the ground body. The world object does not keep a reference to the body definition.The ground body is created as a static body.Static bodies don't collide with other static bodies and are immovable.Box2D determines that a body is static when it has zero mass.Bodies have zero mass by default,therefore they are static by default.view sourceprint?1vargroundBody:b2Body=world.CreateBody(groundBodyDef);For step3we create a ground polygon definition.We use the SetAsBox shortcut to formthe ground polygon into a box shape,with the box centered on the origin of the parent body.view sourceprint?1vargroundShapeDef:b2PolygonDef=newb2PolygonDef();2groundShapeDef.SetAsBox(50.0,10.0);The SetAsBox function takes the half-width and half-height.So in this case the ground box is100units wide(x-axis)and20units tall(y-axis).Box2D is tuned for meters, kilograms,and seconds.So you can consider the extents to be in meters.However,it is possible to change unit systems,as discussed later in this document.We finish the ground body in step4by creating the ground polygon shape on the ground body.view sourceprint?1groundBody.CreateShape(groundShapeDef);Again,Box2D does not keep a reference to the shape or body definitions.It copies the data into the b2Body structure.Note that every shape must have a parent body,even shapes that are static.However, you can attach all static shapes to a single static body.This need for static bodies is done to make the Box2D code more uniform internally,reducing the number of potential bugs.You might notice a pattern here.Most Box2D types are prefixed with b2.This is done to reduce the chance for naming conflicts with your code.Creating a Dynamic BodySo now we have a ground body.We can use the same technique to create a dynamic body.The main difference,besides dimensions,is that we must establish the dynamic body's mass properties.First we create the body using CreateBody.view sourceprint?1varbodyDef:b2BodyDef=newb2BodyDef();2bodyDef.position.Set(0.0,4.0);34varbody:b2Body=world.CreateBody(bodyDef);Next we create and attach a polygon shape.Notice that we set density to1.The default density is zero.Also,the friction on the shape is set to0.3.Once the shape is attached, we instruct the body to compute it's mass properties from the attached shapes using the method SetMassFromShapes.This gives you a hint that you can attach more than one shape per body.If the computed mass is zero,then the body becomes truly static.Bodies have a mass of zero by default,that's why we didn't need to call SetMassFromShapes for the ground body.view sourceprint?1varshapeDef:b2PolygonDef=newb2PolygonDef();2shapeDef.SetAsBox(1.0,1.0);3shapeDef.density=1.0;4shapeDef.friction=0.3;5body.CreateShape(shapeDef);6body.SetMassFromShapes();That's it for initialization.We are now ready to begin simulating.Simulating the World(of Box2D)So we have initialized the ground box and a dynamic box.Now we are ready to set Newton loose to do his thing.We just have a couple more issues to consider.Box2D uses a bit of numerical code called an integrator.Integrators simulate the physics equations at discrete points of time.This goes along with the traditional game loop where we essentially have a flip book of movement on the screen.So we need to pick a time step for Box2D.Generally physics engines for games like a time step at least as fast as60Hz or1/60seconds.You can get away with larger time steps,but you will have to be more careful about setting up the definitions for your world.We also don't like the time step to change much.So don't tie the time step to your frame rate(unless you really,really have to).Without further ado,here is the time step.view sourceprint?1vartimeStep:Number=1.0/60.0;In addition to the integrator,Box2D also uses a larger bit of code called a constraint solver.The constraint solver solves all the constraints in the simulation,one at a time.A single constraint can be solved perfectly.However,when we solve one constraint,we slightly disrupt other constraints.To get a good solution,we need to iterate over all constraints a number of times.The suggested iteration count for Box2D is10.You can tune this number to your liking,just keep in mind that this has a trade-off between speed and ing fewer iterations increases performance but accuracy suffers. Likewise,using more iterations decreases performance but improves the quality of your simulation.Here is our chosen iteration count.view sourceprint?1variterations:Number=10;Note that the time step and the iteration count are completely unrelated.An iteration is not a sub-step.One iteration is a single pass over all the constraints withing a time step. You can have multiple passes over the constraints within a single time step.We are now ready to begin the simulation loop.In your game the simulation loop can be merged with your game loop.In each pass through your game loop you call b2World.Step.Just one call is usually enough,depending on your frame rate and your physics time step.The Hello World program was designed to be dead simple,so it has no graphical output. Rather that being utterly boring by producing no output,the code prints out the position and rotation of the dynamic body.Yay!Here is the simulation loop that simulates60time steps for a total of1second of simulated time.view sourceprint?1for(vari:Number=0;i<60;++i)23{4world.Step(timeStep,iterations);5varposition:b2Vec2=body.GetPosition();6varangle:Number=body.GetAngle();7trace(position.x+','+position.y+','+angle);89}The TestbedOnce you have conquered the HelloWorld example,you should start looking at Box2DAS3's testbed.The testbed is a unit-testing framework and demo environment. Here are some of the features:•Mouse picking of shapes attached to dynamic bodies.•Extensible set of tests.The testbed has many examples of Box2D usage in the test cases and the framework itself.I encourage you to explore and tinker with the testbed as you learn Box2D.API DesignMemory ManagementBox2dFlash is a straight port of Box2D,a C++library.Hence in many places,memory is managed precisely,rather than relying on the garbage collector.This helps reduce stutter. Objects are recycled,hence the many Create/Destroy methods.Factories and DefinitionsAs mentioned above,memory management plays a central role in the design of the Box2D API.So when you create a b2Body or a b2Joint,you need to call the factoryfunctions on b2World.There are creation functions:view sourceprint?1b2World.CreateBody(def:b2BodyDef):b2Body2b2World.CreateJoint(def:b2JointDef):b2JointAnd there are corresponding destruction functions:view sourceprint?1b2World.DestroyBody(body:b2Body):void23b2World.DestroyJoint(joint:b2Joint):voidWhen you create a body or joint,you need to provide a definition or def for short. These definitions contain all the information needed to build the body or joint.By using this approach we can prevent construction errors,keep the number of function parameters small,provide sensible defaults,and reduce the number of accessors.Since shapes must be parented to a body,they are created and destroyed using a factory method on b2Body:view sourceprint?1b2Body.CreateShape(def:b2ShapeDef):b2Shape2b2Body.DestroyShape(shape:b2Shape):voidFactories do not retain references to the definitions.So you can create definitions on the stack and keep them in temporary resources.UnitsBox2D works with floating point numbers,so some tolerances have to be used to make Box2D perform well.These tolerance have been tuned to work well with meters-kilogram-second(MKS)units.In particular,Box2D has been tuned to work well with moving objects between0.1and10meters.So this means objects between soup cans and buses in size should work well.Being a2D physics engine it is tempting to use pixels as your units.Unfortunately this will lead to a poor simulation and possibly weird behavior.An object of length200pixels would be seen by Box2D as the size of a45story building.Imagine trying to simulate the movement of a high-rise building with an engine that is tuned to simulate ragdolls and barrels.It isn't pretty.***Caution***Box2D is tuned for MKS units.Keep the size of moving objects roughly between0.1and10meters.You'll need to use some scaling system when you render your environment and actors.The built in DebugDraw already features a scaling factor.User DataThe b2Shape,b2Body,and b2Joint classes allow you to attach any object as user data. This is handy when you are examining Box2D data structures and you want to determine how they relate to the data structures in your game engine.For example,it is typical to attach an actor to the rigid body on that actor.This sets up a circular reference.If you have the actor,you can get the body.If you have the body,you can get the actor.view sourceprint?1actor:GameActor=newGameCreateActor();2bodyDef:b2BodyDef=newb2BodyDef();erData=actor;4actor.body=box2Dworld.CreateBody(bodyDef);Here are some examples of cases where you would need the user data:•Applying damage to an actor using a collision result.•Playing a scripted event if the player is inside an axis-aligned box.•Accessing a game structure when Box2D notifies you that a joint is going to be destroyed.Keep in mind that user data is optional and you can put anything in it.However,you should be consistent.For example,if you want to store an actor on one body,you should probably keep an actor on all bodies.StrawmanIf you don't like this API design,that's ok!You have the source code!Seriously,if you have feedback about anything related to Box2D,please leave a comment in the forum.The WorldAboutThe b2World class contains the bodies and joints.It manages all aspects of the simulation and allows for asynchronous queries(like AABB queries).Much of your interactions with Box2D will be with a b2World object.Creating and Destroying a WorldCreating a world is fairly simple.You need to provide a bounding box and a gravity vector.The axis-aligned bounding box should encapsulate the world.You can improve performance by making the bounding box a bit bigger than your world,say2x just to be safe.If you have lots of bodies that fall into the abyss,your application should detect this and remove the bodies.This will improve performance and prevent floating point overflow.view sourceprint?1varmyWorld:b2World=newb2World(aabb,gravity,doSleep)When myWorld goes out of use,it will automatically be deleted by the garbage collector.CautionRecall that the world AABB should always be bigger then the region where your bodies are located.If bodies leave the world AABB,then they will be frozen.This is not a bug.Using a WorldThe world class contains factories for creating and destroying bodies and joints.These factories are discussed later in the sections on bodies and joints.There are some other interactions with b2World that I will cover now.SimulationThe world class is used to drive the simulation.You specify a time step and an iteration count.For example:view sourceprint?1vartimeStep:Number=1.0/60.;2variterationCount:Number=10;3myWorld.Step(timeStep,iterationCount);After the time step you can examine your bodies and joints for information.Most likely you will grab the position off the bodies so that you can update your actors and render them.You can perform the time step anywhere in your game loop,but you should be aware of the order of things.For example,you must create bodies before the time step if you want to get collision results for the new bodies in that frame.As I discussed above in the HelloWorld tutorial,you should use a fixed time step.By using a larger time step you can improve performance in low frame rate scenarios.But generally you should use a time step no larger than1/30seconds.A time step of1/60 seconds will usually deliver a high quality simulation.The iteration count controls how many times the constraint solver sweeps over all the contacts and joints in the world.More iterations always yields a better simulation.But don't trade a small time step for a large iteration count.60Hz and10iterations is far better than30Hz and20iterations.Exploring the WorldAs mentioned before,the world is a container for bodies and joints.You can grab the body and joint lists off the world and iterate over them.For example,this code wakes up all the bodies in the world.view sourceprint?1for(varb:b2Body=myWorld.GetBodyList();b;b=b.GetNext())23{4 b.WakeUp();5}Unfortunately life can be more complicated.For example,the following code is broken:view sourceprint?01for(varb:b2Body=myWorld.GetBodyList();b;b=b.GetNext())0203{04varmyActor:GameActor=b->GetUserData()asGameActor;05if(myActor.IsDead())06{07myWorld.DestroyBody(b);//ERROR:now GetNext returns garbage. 0809}10}Everything goes ok until a body is destroyed.Once a body is destroyed,its next pointer becomes invalid.So the call to b2Body.GetNext()will return garbage.The solution to this is to copy the next body before destroying the body.view sourceprint?01varnode:b2Body=myWorld.GetBodyList();02while(node)0304{05varb:b2Body=node;06node=node.GetNext();0708varmyActor:GameActor=b->GetUserData()asGameActor;09if(myActor.IsDead())1011{12myWorld.DestroyBody(b);13}14}This safely destroys the current body.However,you may want to call a game function that may destroy multiple bodies.In this case you need to be very careful.The solution is application specific,but for convenience I'll show one method of solving the problem.view sourceprint?01varnode:b2Body=myWorld.GetBodyList();02while(node)0304{05varb:b2Body=node;06node=node.GetNext();0708varmyActor:GameActor=b.GetUserData()asGameActor;09if(myActor.IsDead())1011{12varotherBodiesDestroyed:Boolean=GameCrazyBodyDestroyer(b); 13if(otherBodiesDestroyed)14{1516node=myWorld.GetBodyList();17}18}19}Obviously to make this work,GameCrazyBodyDestroyer must be honest about what it has destroyed.AABB QueriesSometimes you want to determine all the shapes in a region.The b2World class has a fast log(N)method for this using the broad-phase data structure.You provide an AABB in world coordinates and b2World returns an array of all the shapes that potentially intersect the AABB.This is not exact because what the function actually does is return all the shapes whose AABBs intersect the specified AABB.For example,the following code finds all the shapes that potentially intersect a specified AABB and wakes up all of the associated bodies.view sourceprint?01varaabb:b2AABB=newb2AABB();02aabb.lowerBound.Set(-1.0,-1.0);03aabb.upperBound.Set(1.0,1.0);0405vark_bufferSize:Number=10;06varbuffer:Array=[];07varcount:Number=myWorld.Query(aabb,buffer,k_bufferSize);0809for(vari:Number=0;i<count;++i)10{11buffer[i].GetBody().WakeUp();1213}Note:This calling syntax is rather obscure for typical AS3use.This is due to Box2DAS3's C++heritage,which does not handle variable sized arrays so easily.BodiesAboutBodies have position and velocity.You can apply forces,torques,and impulses to bodies. Bodies can be static or dynamic.Static bodies never move and don't collide with other static bodies.Bodies are the backbone for shapes.Bodies carry shapes and move them around in the world.Bodies are always rigid bodies in Box2D.That means that two shapes attached to the same rigid body never move relative to each other.You usually keep pointers to all the bodies you create.This way you can query the body positions to update the positions of your graphical entities.You should also keep body pointers so you can destroy them when you are done with them.Body DefinitionBefore a body is created you must create a body definition(b2BodyDef).You can create a body definition on the stack or build it into your game's data structures.The choice is up to you.Box2D copies the data out of the body definition,it does not keep a pointer to the body definition.This means you can recycle a body definition to create multiple bodies.Lets go over some of the key members of the body definition.Mass PropertiesThere are a few ways to establish the mass properties for a body.6Set the mass properties explicitly in the body definition.7Set the mass properties explicitly on the body(after it has been created).8Set the mass properties based on the density of the attaced shapes.In many game scenarios it makes sense to compute mass based on shape densities.This helps to ensure that bodies have reasonable and consistent mass values.However,other game scenarios may require specific mass values.For example,you may have a mechanism,like a scale that needs precise mass values.You can explicitly set the mass properties in the body definition as follows:view sourceprint?1bodyDef.massData.mass=2.0;//the body's mass in kg23bodyDef.massData.center.SetZero();//the center of mass in local coordinates4bodyDef.massData.I=3.0;//the rotational inertia in kg*m^2.The other methods of setting the mass properties are covered elsewhere in this document.Position and AngleThe body definition gives you the chance to initialize the position of the body on creation. This has better performance than creating the body at the world origin and then moving the body.A body has two main points of interest.The first point is the body's origin.Shapes and joints are attached relative to the body's origin.The second point of interest is the center of mass.The center of mass is determined from mass distribution of the attached shapes or is explicitly set with b2MassData.Much of Box2D's internal computations use the center of mass position.For example b2Body stores the linear velocity for the center of mass.When you are building the body definition,you may not know where the center of mass is located.Therefore you specify the position of the body's origin.You may also specify the body's angle in radians,which is not affected by the position of the center of mass.If you later change the mass properties of the body,then the center of mass may move on the body,but the origin position does not change and the attached shapes and joints do not move.view sourceprint?1bodyDef.position.Set(0.0,2.0);//the body's origin position.2bodyDef.angle=0.25*b2Settings.b2_pi;//the body's angle in radians.DampingDamping is used to reduce the world velocity of bodies.Damping differs from friction in that friction only occurs when two surfaces are in contact.Damping is also much cheaper to simulate than friction.Note,however,that damping is not a replacement for friction; the two effects should be used together.Damping parameters should be between0and infinity,with0meaning no damping,and infinity meaning full damping.Normally you will use a damping value between0and1.0.I generally do not use linear damping because it makes bodies look floaty.view sourceprint?1bodyDef.linearDamping=0.0;2bodyDef.angularDamping=0.1;Damping is approximated for stability and performance.At small damping values the damping effect is mostly independent of the time step.At larger damping values,the damping effect will vary with the time step.This is not an issue if you use a fixed time step(recommended).Sleep ParametersWhat does sleep mean?Well it is expensive to simulate bodies,so the less we have to simulate the better.When a body comes to rest we would like to stop simulating it.When Box2D determines that a body(or group of bodies)has come to rest,the body enters a sleep state which has very little CPU overhead.If an awake body collides with a sleeping body,then the sleeping body wakes up.Bodies will also wake up if a joint or contact attached to them is destroyed.You can also wake a body manually.The body definition lets you specify whether a body can sleep and whether a body is created sleeping.view sourceprint?1bodyDef.allowSleep=true;2bodyDef.isSleeping=false;BulletsGame simulation usually generates a sequence of images that are played at some frame rate.In this setting rigid bodies can move by a large amount in one time step.If a physics engine doesn't account for the large motion,you may see some objects incorrectly pass through each other.This effect is called tunneling.By default,Box2D uses continuous collision detection(CCD)to prevent dynamic bodies from tunneling through static bodies.This is done by sweeping shapes from their old position to their new positions.The engine looks for new collisions during the sweep andcomputes the time of impact(TOI)for these collisions.Bodies are moved to their first TOI and then simulated to the end of the original time step.This process is repeated as necessary.Normally CCD is not used between dynamic bodies.This is done to keep performance reasonable.In some game scenarios you need dynamic bodies to use CCD.For example, you may want to shoot a high speed bullet at a thin wall.Without CCD,the bullet my tunnel through the wall.Fast moving objects in Box2D are called bullets.You should decide what bodies should be bullets based on your game design.If you decide a body should be treated as a bullet, use the following setting.view sourceprint?1bodyDef.isBullet=true;The bullet flag only affects dynamic bodies.CCD is expensive so you probably don't want all moving bodies to be bullets.So by default Box2D only uses CCD between moving bodies and static bodies.This is an effective approach to prevent bodies from escaping your game world.However,you may have some fast moving bodies that that require CCD all the time.Body FactoryBodies are created and destroyed using a body factory provided by the world class.This lets the world create the body with an efficient allocator and add the body to the world data structure.Bodies can be dynamic or static depending on the mass properties.Both body types use the same creation and destruction methods.view sourceprint?1vardynamicBody:b2Body=myWorld.CreateBody(bodyDef);23//...do stuff...4myWorld.DestroyBody(dynamicBody);5dynamicBody=null;Static bodies do not move under the influence of other bodies.You may manually move static bodies,but you should be careful so that you don't squash dynamic bodies between two or more static bodies.Friction will not work correctly if you move a static body.Static bodies never simulate on their own and they never collide with other static bodies.It is faster to attach several shapes to a static body than to create several static bodies with a single shape on each one.Internally,Box2D sets the mass and inverse mass of static bodies to zero.This makes the math work out so that most algorithms。

什么是Web2.0?

什么是Web2.0?

什么是Web2.0?Web2.0 是相对于Web1.0 的新的时代。

指的是一个利用Web的平台,由用户主导而生成的内容互联网产品模式,为了区别传统由网站雇员主导生成的内容而定义为第二代互联网,即web2.0,是一个新的时代。

Web2.0模式下的互联网应用具有以下显著特点:1.用户分享。

在Web2.0模式下,可以不受时间和地域的限制分享各种观点。

用户可以得到自己需要的信息也可以发布自己的观点。

2.信息聚合。

信息在网络上不断积累,不会丢失。

3.以兴趣为聚合点的社群。

在Web2.0模式下,聚集的是对某个或者某些问题感兴趣的群体,可以说,在无形中已经产生了细分市场。

4.开放的平台,活跃的用户。

平台对于用户来说是开放的,而且用户因为兴趣而保持比较高的忠诚度,他们会积极的参与其中。

Web2.0概念的说明,通常采用典型Web2.0网站案例介绍,加上对部分Web2.0相关技术的解释,这些Web2.0技术主要包括:博客(BLOG)、RSS、百科全书(Wiki)、网摘、社会网络(SNS)、P2P、即时信息(IM)等。

下面是对Web2.0相关技术的简单介绍Blog——博客/网志,Blog的全名应该是Web log,后来缩写为Blog。

Blog是一个易于使用的网站,您可以在其中迅速发布想法、与他人交流以及从事其他活动。

所有这一切都是免费的。

RSS ,RSS是站点用来和其他站点之间共享内容的一种简易方式(也叫聚合内容)的技术。

最初源自浏览器“新闻频道”的技术,通常被用于新闻和其他按顺序排列的网站,例如Blog。

WIKI——百科全书,Wiki--一种多人协作的写作工具。

Wiki站点可以有多人(甚至任何访问者)维护,每个人都可以发表自己的意见,或者对共同的主题进行扩展或者探讨。

Wiki指一种超文本系统。

这种超文本系统支持面向社群的协作式写作,同时也包括一组支持这种写作的辅助工具。

有人认为,Wiki系统属于一种人类知识网格系统,我们可以在Web的基础上对Wiki文本进行浏览、创建、更改,而且创建、更改、发布的代价远比HTML 文本小;同时Wiki系统还支持面向社群的协作式写作,为协作式写作提供必要帮助;最后,Wiki的写作者自然构成了一个社群,Wiki系统为这个社群提供简单的交流工具。

WEB2.0标准教程(循序渐进12天的基础学习)

WEB2.0标准教程(循序渐进12天的基础学习)

WEB标准是什么?WEB标准WEB标准不是某一个标准,而是一系列标准的集合。

网页主要由三部分组成:结构(Structure)、表现(Presentation)和行为(Behavior)。

对应的标准也分三方面:结构化标准语言主要包括XHTML和XML,表现标准语言主要包括CSS,行为标准主要包括对象模型(如W3C DOM)、ECMAScript等。

这些标准大部分由W3C起草和发布,也有一些是其他标准组织制订的标准,比如ECMA(European Computer Manufacturers Association)的ECMAScript标准。

我们来简单了解一下这些标准:1.结构标准语言(1)XMLXML是The Extensible Markup Language(可扩展标识语言)的简写。

目前推荐遵循的是W3C 于2000年10月6日发布的XML1.0,参考(/TR/2000/REC-XML-20001006)。

和HTML一样,XML同样来源于SGML,但XML是一种能定义其他语言的语。

XML最初设计的目的是弥补HTML的不足,以强大的扩展性满足网络信息发布的需要,后来逐渐用于网络数据的转换和描述。

关于XML的好处和技术规范细节这里就不多说了,网上有很多资料,也有很多书籍可以参考。

(2)XHTMLXHTML是The Extensible HyperText Markup Language可扩展标识语言的缩写。

目前推荐遵循的是W3C于2000年1月26日推荐XML1.0(参考/TR/xhtml1)。

XML 虽然数据转换能力强大,完全可以替代HTML,但面对成千上万已有的站点,直接采用XML 还为时过早。

因此,我们在HTML4.0的基础上,用XML的规则对其进行扩展,得到了XHTML。

简单的说,建立XHTML的目的就是实现HTML向XML的过渡。

2. 表现标准语言CSS是Cascading Style Sheets层叠样式表的缩写。

2bixbox快速入门教程

2bixbox快速入门教程

快速入门教程目录下载、安装以及运行2BizBox下载、安装2BizBox运行服务器程序运行客户端程序登录2BizBox退出以及注销2BizBox预备知识创建零件创建物料清单创建销售单添加客户地址簿添加销售单审批销售单计划—制造或外购创建工单审批工单工单排产运行物料需求计划创建采购单审批采购单采购单收料创建应付账款付款工单发料工单收料销售单发货创建应收账款收款欢迎光临2BizBox快速入门教程!您可在阅读本教程同时,先观看配套操作视频,以便更直观了解2BizBox工作原理:快速上手操作视频2BizBox是功能全面、易于使用的免费ERP软件,此教程可帮助您快速完成2BizBox基础设置,并初步了解2BizBox的主要流程。

本教程的内容可在30分钟内完成,在您完成本教程并熟悉了2BizBox之后,您可进入在线用户手册,详细了解2BizBox各种有趣而强大的功能。

本教程只需要一台装有任意版本Windows操作系统的电脑来安装2BizBox,Microsoft Excel和Adobe Reader软件来阅读系统打印的PDF文件,无需数据库、Java或者其他软件的安装部署。

从官网下载2BizBox安装程序。

如果您下载的是“All In One”安装程序,可在下载完成后,根据“安装向导”的提示进行安装,确保“全部”选项(此选项包含2BizBox ERP的服务器和客户端)在安装过程中被选中。

如果您下载的是ZIP压缩文件, 直接解压缩安装包,找到相应的“run.bat”运行服务器,以及“client.exe”运行客户端即可。

双击“2BizBox服务器”即可运行2BizBox服务器程序。

请确保计算机上的80端口未被其他程序占用,以便2BizBox服务器能够正确启动。

服务器程序启动后,会有两个命令提示窗口运行,“run_database.bat”运行MySQL数据库服务,使用端口3307;“run.bat”是2BizBox 运行的后台程序JBoss服务。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/13
返回
BOS 进阶培训流程
JavaScript基础 JavaScript基础
Ext.js(Ajax)框架 Ext.js(Ajax)框架
Jsf框架原理 Jsf框架原理
AOM框架基础 AOM框架基础
Waf应用(Web设计器) Waf应用(Web设计器) 应用 设计器
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/12
返回
BOS Web开发概述 开发概述
BOS Web开发属于BOS 6.3起主推的一种开发模式,能够快速的满足 企业Web2.0应用、企业云开发平台等模式的需求,而且同时具有BOS GUI开发的工具、模式、效率,能够快速的满足任何一个企业Web应 用开发需求 目前的BOS Web开发已经满足EAS 协同、供应链、HR、BOS云平台 、北研电子政务、上研文档知识管理等多个领域的需求,并且在不断 的突破新领域。
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/30
返回
部署和测试
如下图,在左边选择“测试设置”,然后右切换到“WEB UI相关设置”页签,进行设 置,其他设置请参考BOS业务建模工具相应文档。
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/31
返回
部署和测试
部署Web应用首先需要启动BIM服务器,启动方法请参考BOS业务建模工具相应文档。 (如果只是部署到本地测试,可以不用启动)。 BIM服务器就绪后,在“业务单元管理”视图中选中解决方案,在主菜单中选择〖工具 〗 〖部署〗进入部署向导。如下图
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/28
返回
发布Web UI代码 发布 代码
Web代码发布支持两种代码结构 Xhtml模式:组件声明在页面上 Mbean模式:组件声明在mbean中
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/29
返回
部署和测试
切换到“金蝶BOS业务建模工具”透视图,在“业务单元管理”视图中选中解决方案。 在主菜单上选择〖工具〗 〖设置解决方案〗。如下图。
在周期4结束后,执行该周期,一般为调用组件绑定的action,action Listener【执行业务逻辑更新模型数据到持久层,以及执行导航跳转】
6:Render Response
最后一个阶段,将更新数据返回客户端显示。
Байду номын сангаас
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/9
返回
JSF-生命周期 生命周期
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/20
返回
Web建模设计工具 --集成各种基础服务
集成功能定义、工具栏、权限、日志、 集成功能定义、工具栏、权限、日志、主菜单等功能
设计期设置主菜单
运行时设置WEB主菜单
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/21
返回
Web建模设计工具 --GUI/WEB界面同步建模
第二部分
BOS Web应用-Web建模设计工具 Web应用-Web建模设计工具
第三部分
BOS Web应用-开发样例说明
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/35
返回
开发样例说明--快速开发Web单据
使用模板快速生成单据界面 Step 1:新建业务单元 Step 2:选择业务类型 Step 3:选择模板
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/36
返回
开发样例说明--快速开发Web单据
增删修改字段的几种方式 Step Step Step Step 1:选择右侧的控件 2:拖曳到需要放的UI位置中 3:点击鼠标右键,单击“字段管理” 4:进入“字段管理”中增删修改字段
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/3
返回
整体介绍--定位与组成(二)
组成
-Web应用框架(WAF,Web Aplication Framework)
A、BOS Web应用的应用框架核心功能 B、无缝粘合业务层与技术框架层 C、提供统一的框架服务与集成
–BOS Web设计器
A、提供快速简单的Web设计器 B、与BOS BIM无缝结合,重用已有BOS建模功能 C、Web企业服务组件开发
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/32
返回
部署和测试
选择部署形式为“部署到远程解决方案服务器”,选择发布的内容为“部署 WEB应用”。 如果部署形式为“部署到本地解决方案目录”,则后续将选择本地路径,下面 只以部署到远程解决方案服务器为例。
版权所有 ©1993-2009 金蝶软件(中国)有限公司
3:Process Validation
在周期2执行后,执行该周期,用来对表单中提交到组件中的数据进行转 化、校验;如果该部分出错,将直接跳转到6执行输出错误。
4:Upadate Model
在周期3完成后,执行该周期,将组件的值更新到Bean的模型中。
5:Invoke Application Method
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/4
返回
整体介绍--主要功能
基于定位BOS Web应用能做什么 应用能做什么? 基于定位BOS Web应用能做什么?
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/5
返回
Web应用平台技术架构——整体架构图
版权所有 ©1993-2009 金蝶软件(中国)有限公司
GUI/WEB界面同步建模 GUI/WEB界面同步建模
WEB界面自动增加“金额字段 GUI上增加“金额”字段
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/22
返回
GUI生成 生成WEB UI 生成
有多数老系统都是使用GUI元数据进行界面开发,因此Web设计器提 供了GUI转WEB UI的功能,能将原有GUI的界面定义转成相应的WEB UI定义,并实现数据绑定,但界面的业务逻辑不能转换。
支持热替换,发布元数据和修改代码不需要重启服务器 提供部署功能,轻松把Web开发内容部署到正式服务器
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/27
返回
发布Web UI代码 发布 代码
在“包分类”视图中,选择需要发布代码的Web UI元数据(可以多选),弹出右键菜单, 选择〖发布〗进入代码发布向导。如下图
每个阶段的作用?
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/8
返回
JSF生命周期作用分析 生命周期作用分析
1:Restore view
在页面首次Get请求时,执行该周期,执行后直接转入第6周期执行
2:Apply request Values
在页面发起Post请求后,执行该周期,将页面录入的数据提交到JSF的组 件中
入门
中级开发
高级开发
Web基础 Web基础
Web进阶 Web进阶
BOS服务组装 BOS服务组装
Java基础 Java基础
JS/Ajax框架 JS/Ajax框架
JSF/AOM
BOS云服务开发 BOS云服务开发
BIM基础 BIM基础 Web设计器 Web设计器 Waf框架 Waf框架
企业云整合
Web业务开发 Web业务开发
A、一个面向Web开发的应用框架,封装技术框架复杂度 B、一个可视化、一体化的集成式开发环境,为业务开发过程与 开发模型提供全生命周期的支持 C、专注于企业应用级服务,提供大量可复用应用框架服务
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/11
返回
整体介绍--BOS Web开发路线图 开发路线图
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/14
返回
Web应用平台技术架构——分层架构视图
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/15
返回
Web应用物理架构——运行期组件图
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/16
返回
目录
第一部分
BOS Web应用-整体介绍
P/33
返回
部署和测试
BIM本身也提供了测试支持,可以直接启动BIM中内置的EAS服务器进行快速测试。如 下图,启动服务器,启动完毕后选择对应的业务单元右键’WEB页面测试’即会弹出浏 览器并定向导测试单据页面。
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/34
返回
目录
第一部分
BOS Web应用-整体介绍
JSF具有6个生命周期
恢复视图(Restore View) 应用请求值(Apply Request Value) 处理验证(Process Validations) 更新模型值(Update Model Value) 调用应用程序(Invoke Application) 渲染响应(Render Response)
P/6
返回
整体介绍--与AOM的关系(一)
AOM Apusic OperaMasks,金蝶中间公司的开源J2EE Web开发解决方案,包 含了运行期平台OperaMasks SDK与集成开发环境OperaMasks Studio。
版权所有 ©1993-2009 金蝶软件(中国)有限公司
P/7
返回
JSF-生命周期 生命周期
版权所有 ©1993-2009 金蝶软件(中国)有限公司
相关文档
最新文档