Giter Club home page Giter Club logo

cs_174a_f18_team-project-group-30's Introduction

CS 174A Term Project - Ball Simulator

Jiayu Hu
Qingpeng Li
Yifei Fu

Description

In this project, we implemented a physics engine in which there are balls generated to interact with other balls, the environment including gravity, and the boundary of a virtualized 3D box. Each ball is modeled as a spring with damping, and its shape will be deformed according to the force that applies to it. Because the balls have damping coefficient, all the balls will be still at the end. The balls have different textures to implement fake bump mapping. Also, the balls’ model can be replaced with a golf ball .obj model to implement an interesting surface.

In addition, we designed a space gravity simulation based on the physics engine that visualizes the interactions between stars and planets in a solar system. The user can interact with the system by adding planets and observe the behavior of a n-body system.

Advanced Topics:

  • Collision detection
  • Newtonian physics simulation
  • Fake Bump Mapping
  • Imported OBJ files

Contributions

Jiayu Hu: Designed the code structure, and set up the physics engine, which includes designing the spring model of the balls, enabling the function of forces such as gravitational force, checking collisions for each ball with other balls and the boundary of the box, and simulating each frame of the physics engine.

Qingpeng Li: Created texture materials for fake bump mapping, implemented a function that generates a random texture material from the texture materials storage. Imported a .obj file to shape and use it correctly.

Yifei Fu: Created the gravity simulation by implementing the Newton's law of universal gravitation. Designed the collision behaviors between planets.

Details

Main Scene

The main scene initially is empty, buttons need to be used to generate new balls.

Buttons

"Generate a ball", ["G"]: generate a new ball from a random position.
"addTop", ["T"]: generate a new ball from a fixed position on the top.
"addLeft", ["L"]: generate a new ball from a fixed position on the left.
"addRight", ["R"]: generate a new ball from a fixed position on the right.
"addFront", ["F"]: generate a new ball from a fixed position on the front.
"switchGravity", ["S"]: switch the gravity in the scene, the default is on.
"diffTexture", ["D"]: switch the fake bump mapping on all balls, the default is off.
"switchObj", ["O"]: switch the .obj model file on all balls, default is off.

All the balls have random colors when they are generated. When "diffTexture" is on, all the balls will have random textures for fake bump mapping. The .obj model is a golf ball model.

Space Scene

The space scene initially consists of a binary star system. The user can add more planets with the “Add Planet” button and change the gravitational constant with the “Increase/Decrease G” buttons.

Future Improvements

In our physics engine, use a new way to update velocity and position given an acceleration a = F / m. Assuming that the velocity and position of a particle of the current frame are V0 and X0 respectively, we let the velocity of the next frame be V1 = V0 + a Δt, and make the position of the next frame be X1 = V0 Δt + 1 / 2 a Δt^2. In this way, we can decrease the error in X1 caused by the velocity when a force is very large. For even better precision, we can solve the motion differential equations directly instead of using the Euler Method to approximate the solution.

For the gravity simulation, add a skybox with stars and realistic models of celestial bodies in the solar system. We can also add explosion visual effects for collisions between planets with a particle system.

Reference

  • Demo code of Fake Bump Mapping and OBJ Model Loader from piazza @331

cs_174a_f18_team-project-group-30's People

Contributors

hujiayu9696 avatar qingpeng9802 avatar yifei-fu avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.