首页 > 其他分享 >6-springs_and_springlike_things

6-springs_and_springlike_things

时间:2024-03-13 14:55:44浏览次数:18  
标签:real will force particle spring springlike things springs

One of the most useful forces we can create for our engine is a spring force. Although springs have an obvious use in driving games (for simulating the suspension of a car), they come into their own in representing soft or deformable objects of many kinds. Springs and particles alone can produce a whole range of impressive effects such as ropes, flags, cloth garments, and water ripples. Along with the hard constraints we’ll cover in the next chapter, they can represent almost any kind of object.

HOOK’S LAW

Hook discovered that the force exerted by a string depends only on the distance the spring is extended or compressed from its rest position. A spring extended twice as far will exert twice the force. The formula is therefore

\[f = -k\Delta l \]

where \(\Delta l\) is the distance the spring is extended or compressed, and \(k\) is the “spring constant,” a value that gives the stiffness of the spring. When it comes to three dimensions.The corresponding formula for the force is

\[f = -k(\lvert d \rvert - l_{0}) \widehat{d} \qquad \qquad [6.1] \]

where \(d\) is the vector from the end of the spring attached to the object we’re generating a force for, to the other end of the spring.

THE LIMIT OF ELASTICITY

Real springs only behave this way within a range of lengths: this range is called their “limit of elasticity.” If you continue to extend a metal spring, eventually you will exceed its elasticity and it will deform. Similarly, if you compress a spring too much, its coils will touch and further compression is impossible.

SPRINGLIKE THINGS

Hook’s law applies to a huge range of natural phenomena. Anything that has an elastic property will usually have some limit of elasticity in which Hook’s law applies.We could simulate the buoyancy of water in the same way, connecting the submerged object to the nearest point on the surface with an invisible spring.

SPRINGLIKE FORCE GENERATORS

A BASIC SPRING GENERATOR

两个particle之间有个弹簧

class ParticleSpring : public ParticleForceGenerator
{
    /** The particle at the other end of the spring. */
    Particle *other;
    /** Holds the spring constant. */
    real springConstant;
    /** Holds the rest length of the spring. */
    real restLength;
    public:
    /** Creates a new spring with the given parameters. */
    ParticleSpring(Particle *other,
    real springConstant, real restLength);
    /** Applies the spring force to the given particle. */
    virtual void updateForce(Particle *particle, real duration);
};

AN ANCHORED SPRING GENERATOR

一点固定,另一点连接着一个particle.

class ParticleAnchoredSpring : public ParticleForceGenerator
{
    /** The location of the anchored end of the spring. */
    Vector3 *anchor;
    /** Holds the spring constant. */
    real springConstant;
    /** Holds the rest length of the spring. */
    real restLength;
    public:
    /** Creates a new spring with the given parameters. */
    ParticleAnchoredSpring(Vector3 *anchor,
    real springConstant, real restLength);
    /** Applies the spring force to the given particle. */
    virtual void updateForce(Particle *particle, real duration);
};

AN ELASTIC BUNGEE GENERATOR (松紧绳)

An elastic bungee only produces pulling forces. You can scrunch it into a tight ball and it will not push back out, but it behaves like any other spring when extended.

STIFF SPRINGS

In real life almost everything acts as a spring. If a rock falls onto the ground, the ground gives a little, like a very stiff spring.With a model of spring behavior we could simulate anything. Collisions between objects could be modeled in a similar way to the buoyancy force. With the correct spring parameters for each object, this method would give us perfect collisions. It is called the “penalty” method and has been used inmany physics simulators, including several used in games.

缺点:(不同spring constant引起问题)
In fact, to avoid having everything in a game look really spongy as things bounce around on soggy springs, we have to increase the spring constant so that it is very high. If you try to do that, and run the engine, you will see everything go haywire: objects will almost instantly disappear off to infinity, and your program may even crash with numerical errors. This is the problem of stiff springs, and it makes penalty methods almost useless for our needs.

标签:real,will,force,particle,spring,springlike,things,springs
From: https://www.cnblogs.com/ultramanX/p/18070648

相关文章

  • DRY things up是什么意思?
    "DRYthingsup"这个短语在计算机编程领域中,是一个源自“Don'tRepeatYourself”(简称DRY)原则的概念。这个原则强调在编写软件代码时应尽量避免重复劳动和复制粘贴代码,提倡将常用或重复的功能抽象成可复用的模块、函数或类。所以,当说"DRYthingsup"时,意味着要对现有的代码进......
  • 使用SpringSecurity相关说明
    原理探析思路实现密码加密存储......
  • SpringSecurity与JWT如何实现项目端分离认证与授权
    ✅SpringSecurity+JWT实现项目前端分离认证授权✅1.简介SpringSecurity是Spring家族中的一个安全管理框架。相比与另外一个安全框架Shiro,它提供了更丰富的功能,杜区资源也比Shiro丰富。一般来说中大型的项目都是使用SpringSecurity来做安全框架。小项目有Shiro的比较多,因......
  • SpringSecurity
    1、项目依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId><version>2.7.14</version></dependency><dependency><groupId>......
  • Java21 + SpringBoot3整合springdoc-openapi,自动生成在线接口文档,支持SpringSecurity
    目录前言相关技术简介OpenAPISwaggerSpringfoxspringdocswagger2与swagger3常用注解对比实现步骤引入maven依赖修改配置文件设置api-docs和swagger-ui访问权限定义springdoc配置类修改Controller类和实体类查看效果总结前言近日心血来潮想做一个开源项目,目标是做一款可以适配多......
  • SpringSecurity-手机号+短信验证码登陆
    与验证码登录逻辑是不一样的,所以不能使用SpringSecurity默认提供的那套逻辑;需要自个去写一个自定义身份认证逻辑短信验证码生成生成验证码短信验证码类ValidateCode是父类,ImageCode子类publicclassValidateCode{privateStringcode;/***过期时间......
  • springboot整合springSecurity入门案例(实现登录,记住我等常用标签使用)
    一,整合进依赖每个依赖都标了注释,大家可以按照自己需要的来添加,置于配置问件啥的,大家可以参考springboot+mybatisplus+redis整合(附上脚手架完整代码)<!--主要就是加了这个依赖--><dependency><groupId>org.springframework.security</groupId><artifact......
  • SpringSecurity-记得我
    原理在用户发送认证请求之后,或调用我们之前说过的usernamePasswordAuthenticationFilter这个过滤器,认证成功之后会调用一个RemeberMeService服务;负责针对每一用户生成一个Token,然后将token写入到浏览器的Cookie里面,同时会使用:TokenRepository将这个token写入数据库中。将Toke......
  • SpringSecurity-图片验证码
    图片验证码生成Core模块封装验证码类publicclassImageCode{    privateBufferedImageimage;    /**     *code是一个随机数,图片是根据随机数生成的,     *存放到session里面,后面用户提交登录请求时候要去验证的     */    private......
  • SpringSecurity-认证流程源码级详解
    自定义用户认证逻辑处理用户信息获取逻辑:UserDetailsService处理用户校验逻辑:UserDetails处理密码加密解密:PasswordEncoder认证处理流程以表单认证为例:从发起认证请求到认证过滤器,接着认证成功后,响应从认证过滤器返回的整个过程。SpringSecurity做了什么,设计到了哪些类?他......