Next week will be great!

Similar documents
Level Editor. Should be stable (as of Sunday) Will be updating the source code if you want to make tweaks to it for your final

LECTURE 7. Announcements

LECTURE 6. Announcements

LECTURE 5. Announcements

Tac4 Feedback. TAs need to be able to beat your game to grade it. Add an easy mode Let us cheat

LECTURE 5. Announcements

Minecraft Due: March. 6, 2018

The class Object. Lecture CS1122 Summer 2008

C12a: The Object Superclass and Selected Methods

LECTURE 4. Announcements

CS/ENGRD 2110 SPRING Lecture 7: Interfaces and Abstract Classes

Viewing and Ray Tracing

Equality for Abstract Data Types

Minecraft Due: Mar. 1, 2015

Viewing and Ray Tracing. CS 4620 Lecture 4

Collisions/Reflection

Hash tables. hashing -- idea collision resolution. hash function Java hashcode() for HashMap and HashSet big-o time bounds applications

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017

The Java Type System (continued)

Virtual Environments

Unit 1, Lesson 1: Moving in the Plane

Fall 2017 Mentoring 9: October 23, Min-Heapify This. Level order, bubbling up. Level order, bubbling down. Reverse level order, bubbling up

Java: advanced object-oriented features

Super-Classes and sub-classes

CSE 331 Spring 2018 Midterm

This is the last lecture!

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March

Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017

Chapter 11: Collections and Maps

COS226 - Spring 2018 Class Meeting # 13 March 26, 2018 Inheritance & Polymorphism

No more engine requirements! From now on everything you work on is designed by you. Congrats!

MITOCW MIT6_172_F10_lec18_300k-mp4

Ray Tracing Basics I. Computer Graphics as Virtual Photography. camera (captures light) real scene. photo. Photographic print. Photography: processing

Domain-Driven Design Activity

CS/ENGRD 2110 FALL Lecture 6: Consequence of type, casting; function equals

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

Use the Move tool to drag A around and see how the automatically constructed objects (like G or the perpendicular and parallel lines) are updated.

Programming Languages and Techniques (CIS120)

Today. Reading. Homework. Lecture Notes CPSC 224 (Spring 2012) hashcode() method. Collections class. Ch 9: hw 7 out (due in a week)

Lecture 16: HashTables 10:00 AM, Mar 2, 2018

PSE Game Physics. Session (3) Springs, Ropes, Linear Momentum and Rotations. Oliver Meister, Roland Wittmann

Basics of Computational Geometry

Lecture 5: Implementing Lists, Version 1

Photorealism: Ray Tracing

Movie: Geri s Game. Announcements. Ray Casting 2. Programming 2 Recap. Programming 3 Info Test data for part 1 (Lines) is available

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

Collision handling: detection and response

Solutions to Quiz 1 (March 14, 2016)

Lecture 25 of 41. Spatial Sorting: Binary Space Partitioning Quadtrees & Octrees

Note that ALL of these points are Intercepts(along an axis), something you should see often in later work.

Movie: For The Birds. Announcements. Ray Tracing 1. Programming 2 Recap. Programming 3 Info Test data for part 1 (Lines) is available

CS/ENGRD 2110 FALL Lecture 7: Interfaces and Abstract Classes

Simulation in Computer Graphics. Deformable Objects. Matthias Teschner. Computer Science Department University of Freiburg

Pong in Unity a basic Intro

CSE 331 Software Design & Implementation

Particle systems, collision detection, and ray tracing. Computer Graphics CSE 167 Lecture 17

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam

Expected properties of equality

Quiz 1 (March 14, 2016)

INHERITANCE. Spring 2019

Today. Book-keeping. Inheritance. Subscribe to sipb-iap-java-students. Slides and code at Interfaces.

Number- Algebra. Problem solving Statistics Investigations

Chapter 5. Projections and Rendering

Graphical Analysis. Figure 1. Copyright c 1997 by Awi Federgruen. All rights reserved.

COMP200 INHERITANCE. OOP using Java, from slides by Shayan Javed

Basic Triangle Congruence Lesson Plan

CSE 331 Software Design & Implementation

Mathematics 308 Geometry. Chapter 9. Drawing three dimensional objects

Abstract Classes and Interfaces

Building Java Programs. Inheritance and Polymorphism

Ray Tracing Part 1. CSC418/2504 Introduction to Computer Graphics. TA: Muhammed Anwar & Kevin Gibson

Damaging, Attacking and Interaction

MAT 3670: Lab 3 Bits, Data Types, and Operations

Programming Project 1

Ray Tracing I. Internet Raytracing Competition

The Object Class. java.lang.object. Important Methods In Object. Mark Allen Weiss Copyright 2000

1 EquationsofLinesandPlanesin 3-D

Review. CSE 143 Java. A Magical Strategy. Hash Function Example. Want to implement Sets of objects Want fast contains( ), add( )

ASSIGNMENT 2. COMP-202A, Fall 2011, All Sections. Due: Monday, October 17th, 2011 (23:30)

CS112 Lecture: Making Choices

Problem Solving for Intro to Computer Science

Homework 3: Shading, Raytracing, and Image Processing

Making New instances of Classes

Table of Contents. Questions or problems?

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

Agenda. Introduction Curve implementation. Particle System. - Requirements -What are all those vectors? -Where should I put things?

Prime Time (Factors and Multiples)

Glossary Common Core Curriculum Maps Math/Grade 6 Grade 8

CS/ENGRD 2110 FALL Lecture 6: Consequence of type, casting; function equals

A triangle that has three acute angles Example:

(Refer Slide Time: 00:02:24 min)

Section 05: Solutions

Boolean Component. Chapter 1. Boolean Operations

Introduction Ray tracing basics Advanced topics (shading) Advanced topics (geometry) Graphics 2010/2011, 4th quarter. Lecture 11: Ray tracing

2. Getting Started When you start GeoGebra, you will see a version of the following window. 1

Tutorial: Using the UUCS Crowd Simulation Plug-in for Unity

User Guide. for. JewelCAD Professional Version 2.0

CEng 477 Introduction to Computer Graphics Fall 2007

Transcription:

Next week will be great! Three major things are happening next week: Zynga guest lecture Your game pitches (more details later) Christina Paxson

Feedback for M 1 Some of you had stacking shapes The stack probably exploded eventually Don t worry, stacking boxes is hard to do properly This week s lecture will help but not alleviate the problem

Feedback for M 1 Sometimes shapes would settle overlapping other shapes Two possible causes: Not translating enough Doing collision response before integration, hence drawing before translating

Announcements QUESTIONS?

M1 Collision Response You obtained MTV in M1, how did you use it? Move things out of collision Apply some impulse along MTV It probably worked most of the time, or only if you modeled specific behavior Other times the response is weird

Controlling Impulse Want more realistic collisions Two things to do: Support a range of collision behavior Determine the physically correct collision result Also need to be able to code it void oncollide(collision col) { Shape o1 = col.shape1; Shape o2 = col.shape2; Vec2f mtv = col.mtv; o1.move(mtv.smult(0.5f)); o2.move(mtv.smult(-0.5f)); } //code to calculate impulse o1.applyimpulse(imp1); o2.applyimpulse(imp2);

Property of physical entities Value between 0 and 1 0 is perfectly inelastic, 1 is perfectly elastic, etc. The coefficient of restitution (COR) between two entities is the geometric mean of their restitutions: COR = r 1 r 2 Restitution

Correct Collisions How do we find the physically correct collision response? i.e. given u a and u a, what are v a and v b? Use physical definition of the COR: COR = v a v b u a u b u a v a u b v b

Translation to Code Once we determine what the final velocities of the objects should, how do we apply this? Impulse or velocity setting? Setting velocity affects other collision response calculations v r = 1 r = 1 r = 1

Translation to Code We determined what the final velocities of the objects should, how do we apply this? Impulse > velocity setting Setting velocity affects other collision response calculations v

Translation to Code We determined what the final velocities of the objects should, how do we apply this? Impulse > velocity setting Setting velocity affects other collision response calculations v

Translation to Code We determined the final velocities of objects, what do we do with it? Impulse > velocity setting Setting velocity affects other collision response calculations Recall the definition of the impulse: mδv We really want the difference of final and initial velocity v

Final Velocities Conservation of momentum: m a u a + m b u b = m a v a + m b v b The COR equation can be rewritten as COR u a u b = v a v b So conservation of momentum becomes m a u a + m b u b = m a v a + m b (v a COR u a u b )

Solving for v a : Final Velocities v a = m au a +m b u b +m b COR(u b u a ) m a +m b Similarly for v b (reverse a and b basically): v b = m au a +m b u b +m a COR(u a u b ) m a +m b

Velocity Difference The velocity differences are: v a u a = m b(1+cor)(u b u a ) m a +m b v b u b = m a 1+COR m a +m b u a u b

Final Impulse So the impulse you want to apply is: I a = m(v a u a ) = m am b 1+COR m a +m b (u b u a ) I b = m(v b u b ) = m am b 1+COR m a +m b (u a u b ) You can see that they are equal and opposite, as we would expect

Static Shapes If object a is static, you can show that the equations in the last slide reduces to I a = m b (1 + COR) (u b u a ) I b = m b (1 + COR) (u a u b ) Vice-versa if object b is static You should special case this

Note about Velocity Note that all velocities in these equations are for the one-dimensional case But your 2D engine is 2D! Velocity only changes in the direction of the MTV So the v s and u s in the equations are the projection of velocity onto the MTV u b u a u a u b

Putting it all together Physically correct collision response: 1. Calculate COR with the restitutions of the shapes 2. Project velocities onto MTV 3. Apply impulse formula to calculate impulses 4. Apply corresponding impulse to each shape

Physics II QUESTIONS?

What is raycasting? Determine the first object that a ray hits A ray is like a ray of light, has a source and direction and goes on forever It s like a camera (or eye)

Raycasting Uses When would we need to raycast? Hitscan weapons Line of sight for AI Area of effect Rendering

The Ray A ray is a point (source) and a direction Point on ray given by: r = p + td p is the source point d is the direction This must be normalized! t is a scalar value (length) p d td

Raycasting boils down to finding the intersection of a ray and shapes Kind of like collision detection all over again You want the point of collision as well Basics

If the point is outside Project center onto ray Check if the projection is positive and the point is within the circle Point of intersection: p + (L Ray-Circle r 2 x 2 )d

Ray-Circle If the point is outside Project center onto ray Check if the projection is positive and the point is within the circle Point of intersection? p + (L r 2 x 2 )d p L

Ray-Circle If the point is outside Project center onto ray Check if the projection is positive and the point is within the circle Point of intersection? L r 2 x 2 p r 2 x 2 r x p + (L r 2 x 2 )d

Ray-Circle If the source point is inside the circle Do the same thing as if outside, but: p r 2 x 2 x r p + (L + r 2 x 2 )d Now L is allowed to be negative

Ray-Polygon/AAB A polygon/aab is composed of edges We can check for intersection of ray by checking for intersection of all edges There is no shortcut for AABs this time

Ray-Edge Edge is defined by two end points, a and b We need some other vectors: m is direction of the segment (normalized) n is the perpendicular to the segment (normalized) p d a m n b

Ray-Edge Firstly, determine if the segment straddles the ray Use cross products a p d and (b p) d must be of opposite sign Therefore no intersection if a p d b p d > 0 a p p d a m n b p b

Ray-Edge Secondly, determine if the two lines intersect Point of intersection a m n q = p + td q Solve for t t must be nonnegative! p b d

Ray-Edge Because q b lies on the segment m n q b n = 0 So plugging in: p + td b n = 0 a q td n = (b p) n t = (b p) n d n p d b

Intersect the ray with all the edges of the polygon Ray intersects polygon if it intersects at least 1 edge Keep track of the point that is closest to the source (the lowest value of t) Ray-Polygon

Raycasting: Putting it all together 1. Intersect ray with every shape in the world 1. For circles, use the circle-ray algorithm in the slides 2. For polygons, intersect each edge and use the closest 2. Keep track of closest intersection point from the source as well as the corresponding shape

Raycasting QUESTIONS?

Overview Can be any 2D game and engine You can work in groups if you want Each person is responsible for 10 points worth of new engine features More members in a group means more engine features More details in the final project handout

4 main parts: Week 1: Idea Week 2: Form groups and get approved Week 3: Design Weeks 4-8: Code, playtest, polish, present Timeline

A ½ to 1 page document Week 1: Idea Describe basic gameplay idea How is your game fun? Describe engine feature(s) you plan on implementing Give a 60-second elevator pitch of your game in class

Week 2: Groups Form a group (or decide to work alone) Finalize game and engine features Each group must meet with a TA to present the following: A more polished idea of the game Breakdown of member responsibilities for engine

Week 3: Design Research new engine features Design the engine and game Exact breakdown of member responsibilities Choose someone s engine to use or integrate engines For groups of 3 or more Explain how you will use version control

Week 4: Weeks 4-8 Engine should be mostly done Game exists Week 5: Engine should be done Game is playable 5 playtests per member from people not in CS195n

Week 6: Weeks 4-8 Game should be mostly done 5 more playtests per member from outsiders Week 7: Game should be done 5 playtests per member Powerpoint slideshow for postmortem presentation

Week 8: Weeks 4-8 Polish up your game, bug fixes, etc Create an executable and put it in /contrib Make a video demo of your game from gameplay footage It is now December 19 th And then you re done!

Final Project Overview QUESTIONS?

Raycasting Groups Similar to collision groups Some objects shouldn t be raycasted on, just like some objects are not meant to be collided Special case: the source If you re raycasting from a shape, you don t want to check the shape itself

Jumping Properly Extra requirement this week: player can jump once iff standing on a solid object Use information from your collision response object! If the MTV points downwards, then the player has hit something solid below it Player is now allowed to jump

Fixed Timestep Most of you will have noticed weird behavior when you fullscreen/resize It screws around with the nanossinceprevtick Solution: fixed timestep Give the physics world some constant time when ticking Tick as many times as possible on each game tick

Tips for M II JAVA TIP OF THE WEEK

Methods of Object Object has a few methods that you should know/care about: hashcode() equals(object o) tostring() public class Object { int hashcode(); boolean equals(object obj){ return (this == obj); } Object clone(); String tostring(); }

tostring Called whenever you use the object as a string You should override this in your classes to return meaningful strings It s worth doing if you debug with printlines See Vec2f for examples public class Object { public String tostring(){ return getclass().getname() + @ + hashcode(); } } public class PhoneNumber { public String tostring(){ return ( + _areacode + ) + _number; } }

equals Determines if object is equal to another object The default method compares references Doesn t work if you want equal but not the same object (e.g. String) public class Object { boolean equals(object obj){ return (this == obj); } }

equals To override: Use default check first Check if instanceof Cast to object Compare things You can access fields directly! public class Book { String author; String title; boolean equals(object obj){ if (this == obj) return true; if (!(obj instanceof Book)) return false; Book o = (Book) obj; return o.author.equals(author) && o.title.equals(title); } }

Contract of equals A few things must be true about your equals(): o.equals(o) must be true o.equals(null) is always false must be symmetric must be transitive o1.equals(o2) changes only if o1 or o2 changes public class Book { String author; String title; boolean equals(object obj){ if (this == obj) return true; if (!(obj instanceof Book)) return false; Book o = (Book) obj; return o.author.equals(author) && o.title.equals(title); } }

hashcode Returns the hash of the object This value is used by Java s Map data structures You must override hashcode if you override equals Otherwise data structures can do weird things public class Object { } public int hashcode();

Contract of hashcode hashcode must return the same value for the same object unless it is changed If two objects are equal, they have the same hashcode If two objects are unequal, ideally they will have different hashcode public class Object { } public int hashcode();

Overriding hashcode Many ways of actually calculating hash of an object You can look them up if you want public int hashcode(){ int hash = 5; //prime int prime = 89; //prime hash = prime*hash + x; hash = prime*hash + y; hash = prime*hash + z; return hash; }

Tips for M II QUESTIONS?