Friday, December 18, 2015

B3 Interactive Narrative

This is our final Unity project!
enjoy it
Thanks all teammate and all TA's and professor


Github link https://github.com/CG-F15-14-Rutgers
  Youtube :https://www.youtube.com/watch?v=ISsq27dKzLo
  WebPlayer: http://rcssa.org/WebGame/WebPlayer.html


Story Name: The Lost Phone

This project could be separated into Three Chapters, which are related to three part of project description.
We combine the Three parts into one. 

Chapter I

This Chapter shows the start scene of the story. The environment is a complex street cafe. Some telegraph pole, tables, chairs, sunshades and long benches. There are a crowd of people in the cafe have a fight, two and are fight with each other and seven people are looking the fight and yelling and clapping. A red cost man coming from the left hand side of screen to meet a girl in the right and side. Characters animations are using KADAPT Library and some self-edited animations. They have a conversation and act some conversion animation such as wave hands, applaud, crying and etc. we also implemented the conversation dialog box for both characters. They are talking about the graphic class B3 assignment. After they are talking, then the conversation end and say goodbye to each other, the girl using Final IK interaction system to sit, and the man in the red dress finds an IPhone on the ground. And he picks up the iPhone. At same time the phone is ringing. There is a man talks from the iPhone and says he will come back to get his lost phone.

Tech Specs:
Using TreePlusSharp to construct behavior tree, Final IK interaction system, GUI on screen, Camera Script;

Character Capability: Go to the position, Oriented to another character, talk to character, fight to another character, Pick up object, Sit on the bench, To on the phone, claps, cheers, sad, cry, ect;

Multi-actor: conversation, fight, sees the fight;
Behavior Tree:




Chapter II

After the Chapter I, main character came to be on the scene, the Second Chapter this character could interact with other characters in the scene. Use the key board to control the character. You can see in the game, GUI had instruction how to control interaction.

There are three interaction between characters, ask the phone back, ask the girl dance, and stop the fight.

I created an Event Controller to interrupt with the behavior tree, which we could consider behavior tree as action library.


Control Graph:
Character Control: using keyboard key. To make three different interaction: T, Y and U.

Chapter III

This chapter demonstrated to select any characters in the scene to stop the War. This means we could select any character to interrupt behavior tree.


Character Control: using keyboard key. To select three different people: T, Y and U.


Conclusion

In this projects, I did lots of work to figure out the Final IK library and KADAPT library, unlike the old ADAPT library, KADAPT combined the Final IK to make character’s actives easier however it limited on access individual node in real-time, In ADAPT library the BehaviorEvent had a public function BehaviorEvent.run() which could make more easier to process behavior three in real time instead of interrupt the whole tree. It is possible to re-implement the run function for KADAPT library.


Friday, December 11, 2015

Assignment A5


To execute our simulation the command is
./steersim –config Myconfig.xml –testcase testcasename –ai sfAI

The idea of this complex crowd simulation is combine social forces and A* path finder.
The idea of pathfinder work with social forces is put the sequence of nodes that generate by A* into the waypoint and goalqueue list, after reach the current local goal, set the current local goal to the next goal in the waypoint and goal queue list. Sometimes, the agent will crack when it reach the corner of obstacles, so we need to recompute the path in four way A*.

We merge the A* pathfinder into our social forces AI
In reset function push the sequence of node that compute by A* into waypoints and midtermpath and goalQueue list.

In the updateAI we use hasLineOfSightTo function to check is there any obstacles between the agent current position and the current local goal.  If there is an obstacles between the way to the local goal, recalculate the path with four way A* algorithm. in addition, if the local goal is to far away from the current position, it will also recalculate the path.
In most case the OBSTACLE_CLEARANCE = 0 In Maze testcase, the agent size is bigger than other testcase, so we increase the OBSTACLE_CLEARANCE = 2;

In A* we decide to choice weight to 2 and also chose big G value and Manhattan distance.

In the test case hallway-four-way-rounded-roundabout we have solve the polygon obstacles

Implementation method:
1. How to detect if polygon obstacle is in the agents' query area?
Using GJK to detect if agent. Position + query radius colloid with polygon obstacle. If so, we start to compute the repulsion force between polygon obstacle and agents. else, do nothing.
2. How to calculate the force between agents and polygon obstacle?
If polygon obstacle is in the query area of agents, first, we get the nearest vertices in the polygon and split the angel of this vertices in to two parts. Then we compare the vector from the vertices to agent and the vector from vertices to its next vertices to determine which side of the vertices the agent is. Then we treat the face of side of the polygon obstacle as wall to calculate the repulsion force.

In the office complex, we got segmentation fault. The reason is in this testcase the wide of obstacle is so small so many agent crack in the corner of the obstacles. So many recalculate path in this test case.

We increase the goal force time 4. So it can reduce the bounce between agents.


Our created test case is an airport simulation. Some plane are departing and some are arriving. And we also change the shape of agent and color. So it likes look UFO. 

wall squeeze CG Group 14
https://youtu.be/J2vI5Q-txbw

plane ingress CG Group 14
https://youtu.be/9qO_MUMFOpU

hallway four way rounded roundabout CG Group 14
https://youtu.be/fwh1C3knhEU

double squeeze CG Group 14
https://youtu.be/34lVXvQEG2k

airport CG Group 14
https://youtu.be/NdibtJ2kwZk

bottleneck squeeze CG Group 14
https://youtu.be/kbqUvrYE1rA

office complex CG Group 14
https://youtu.be/4iIxO_zA3ms

maze CG Group 14
https://youtu.be/yZ5s-hunnME

plane egress CG Group 14
https://youtu.be/75xuuXNNBmg

doorway two way CG Group 14
https://youtu.be/ZAhxFKZjubA

hallway two way CG Group 14
https://youtu.be/6xyE49ldB9w

crowd crossing CG Group 14
https://youtu.be/hiDJ5Dt19Bo


Sunday, December 6, 2015

Assignment A4 Pathfinding


Blog post : http://rutgerscg14.blogspot.com/

Our submitted AstarPlanner.cpp is
Manhattan distance
Set bigger G for breaking ties
Weighted of heuristics is 2
You are free to change weighted to 1 or 4 or 8;
You are free to change Manhattan to Euclidian
You are free to change to choice smaller G when F-value is same



Part 1
Manhattan, testcase search-1.xml, Path length = 30, # expanded nodes = 852;
https://www.youtube.com/watch?v=YDCcYahzFNs
Manhattan, testcase search-2.xml, Path length = 76, # expanded nodes = 4846;
https://www.youtube.com/watch?v=w0E_9ZsrFJI
Euclidian, testcase search-1.xml, Path lenght = 26, # expanded nodes = 1016;
https://www.youtube.com/watch?v=Az18MZGJ_wE
Euclidian, testcase search-1.xml, Path length = 75, # expanded nodes = 6418;
https://www.youtube.com/watch?v=u8HZ5RLU4AY



Part 2
Manhattan, testcase search-1.xml, g_smaller, Path length = 30 , # expanded nodes = 852;
https://www.youtube.com/watch?v=BMBXyfsSupk
Manhattan, testcase search-2.xml, g_smaller, Path length = 76, # expanded nodes = 4846;
https://www.youtube.com/watch?v=4K5rJQ13vPA
Manhattan, testcase search-1.xml, g_bigger, Path length = 30, # expanded nodes = 840;
https://www.youtube.com/watch?v=eDxocYNuMXw
Manhattan, testcase search-2.xml, g_bigger, Path length = 76, # expanded nodes = 4844;
https://www.youtube.com/watch?v=YywlJysrA0s
Euclidian, testcase search-1.xml, g_smaller, Path length = 26, # expanded nodes = 1016;
https://www.youtube.com/watch?v=hKIopU3Q90I
Euclidian, testcase search-2.xml, g_smaller, Path length = 75, # expanded nodes = 6418;
https://www.youtube.com/watch?v=76qTtNQe_8k
Euclidian, testcase search-1.xml, g_bigger, Path length = 26, # expanded nodes = 1016;
https://www.youtube.com/watch?v=ftll1vgiP08
Euclidian, testcase search-2.xml, g_bigger, Path length = 75, # expanded nodes = 6418;
https://www.youtube.com/watch?v=udeoZ1rdGT0



Part 3
Manhattan, testcase search-1.xml, g_bigger, Path length = 30 , # expanded nodes = 840 ;
https://www.youtube.com/watch?v=8kLODjbFKKM
Manhattan, testcase search-2.xml, g_bigger, Path length = 76, # expanded nodes = 4844;
https://www.youtube.com/watch?v=neEN3RYP3fY
Euclidian, testcase search-1.xml, g_bigger, Path length = 26, # expanded nodes = 1016;
https://www.youtube.com/watch?v=6dD3jCVay3k
Euclidian, testcase search-2.xml, g_bigger, Path length = 75, # expanded nodes = 6418;
https://www.youtube.com/watch?v=b2gu3HoHSxA



Part4
Manhattan, testcase search-1.xml, g_bigger, weight = 2, Path length = 28, # expanded nodes
= 348; 

https://www.youtube.com/watch?v=0U2kkM1Nly8
Manhattan, testcase search-2.xml, g_bigger, weight = 2, Path length = 77, # expanded nodes
= 2202; 

https://www.youtube.com/watch?v=PfaEt9NjDSI
Manhattan, testcase search-1.xml, g_bigger, weight = 4, Path length = 27, # expanded nodes
= 294 ;
https://www.youtube.com/watch?v=WKVNopz01hc
Manhattan, testcase search-2.xml, g_bigger, weight = 4, Path length = 77, # expanded nodes
= 988 ;
https://www.youtube.com/watch?v=haNxhOb5DQU
Manhattan, testcase search-1.xml, g_bigger, weight = 8, Path length = 37, # expanded nodes
= 304 ;
https://www.youtube.com/watch?v=I8DBYoSLx48
Manhattan, testcase search-2.xml, g_bigger, weight = 8, Path length = 77, # expanded nodes
= 512;
https://www.youtube.com/watch?v=Cq5W-ss0DjI
Euclidian, testcase search-1.xml, g_bigger, weight = 2, Path length = 29, # expanded nodes =
360;

https://www.youtube.com/watch?v=BquF1wOnQRc
Euclidian, testcase search-2.xml, g_bigger, weight = 2, Path length = 77, # expanded nodes =
2902;

https://www.youtube.com/watch?v=O4BGv3rpQaI
Euclidian, testcase search-1.xml, g_bigger, weight = 4, Path length = 28, # expanded nodes =
254; 

https://www.youtube.com/watch?v=MJdKdWbeNTs
Euclidian, testcase search-2.xml, g_bigger, weight = 4, Path length = 77, # expanded nodes =
1144; 

https://www.youtube.com/watch?v=brLsTtJn0Vo
Euclidian, testcase search-1.xml, g_bigger, weight = 8, Path length = 37, # expanded nodes =
232;

https://www.youtube.com/watch?v=oiLQ38If99M
Euclidian, testcase search-2.xml, g_bigger, weight = 8, Path length = 77, # expanded nodes =
488; 

https://www.youtube.com/watch?v=qEvN9FV1sSU

Monday, November 23, 2015

Assignment B2 Behavior Tree


Rutgers ­ Computer Graphics Course ­ Fall 2015 ­ Assignment B2 Unity: Behavior Tree

Online Game Link




We implement for Affordances, GanaStyle Dance , Lying  and stand up and Pick up Stick(IK), Pick up Phone(IK), and also use other animations in library, like Talk to phone, Duck, Fight, Sitdown, StandUp.

Gana Style Dance and Lying and Stand up is use animator controller to and states of animations and write in the Behavior Mechanic, Body Mechanic, and Character Mechanic.
Pick ups using IK library, to just the weight of the body skeletons.

Story:
A gang of three thugs come to a street side restaurant, which is the territory of another gang, to look for a fight. But, this time, the other gang has nobody there.
Character A is walks around, then get bored, so he lies down and sit on the bench.
Character B found a phone on the ground; he tried to use this phone to lure one member from the other gang to this restaurant, so they can outnumber him. After he successfully lure out the enemy, he was happy and start to dance.
Character B and Character A also had a conversation.
When triggered, Character C picked up a stick, and waving the stick to prepare to fight someone.

Trigger of interaction, we implement a trigger for object interaction, when player enter the area trigger the IK to pick up the object. When “Space” Key is entered, there will be a stick show up on the ground and the character C will pick it up, then walk and waving the stick, the sky also starting raining.


Tree.  We have 4 layers of the tree.

1




 2





3






The last layer in the layer 3 is layer 4.







     

Wednesday, November 4, 2015

Assignment A3 Social Forces



This assignment is focused on social forces
A social force model is a microscopic, continuous time, continuous space, phenomenological computer simulation model of the movement of pedestrians.








Social forces in bottleneck evacuation





Social forces in one way hallway





Social forces in two way hallway





Social forces in four way hallway





Monday, October 26, 2015

Assignment A2 Collision Detection

Part1 Output ploygons1:

 NO collision detected between polygon No.0 and No.1
 NO collision detected between polygon No.0 and No.2
 NO collision detected between polygon No.0 and No.3
 Collision detected between polygon No.0 and No.4 with a penetration depth of 0.707107 and penetration vector of (-0.707107,0,0.707107)
 Collision detected between polygon No.0 and No.5 with a penetration depth of 2 and penetration vector of (-0,0,1)
 NO collision detected between polygon No.1 and No.2
 NO collision detected between polygon No.1 and No.3
 NO collision detected between polygon No.1 and No.4
 NO collision detected between polygon No.1 and No.5
 NO collision detected between polygon No.2 and No.3
 NO collision detected between polygon No.2 and No.4
 NO collision detected between polygon No.2 and No.5
 Collision detected between polygon No.3 and No.4 with a penetration depth of 1 and penetration vector of (1,0,-0)
 NO collision detected between polygon No.3 and No.5
 Collision detected between polygon No.4 and No.5 with a penetration depth of 1.34164 and penetration vector of (0.894427,0,0.447214)




Part B Output ploygons2:
loaded module collisionAI
loaded module testCasePlayer
Initializing...
Preprocessing...
 NO collision detected between polygon No.0 and No.1
Simulation is running...
Postprocessing...
Simulated 14 frames.
Cleaning up...
Done.







Part C Output ploygons2 new:
In the testcase polygons1, all the polygons are convex, so that the GJK and EPA works nice. However in the testcase polygons2, the two polygons are not convex polygon, the GJK cannot determine the collision about concave polygon.  So we fix the testcase, change the two concave polygons to convex polygons. We ignore the point (3,0,0) of the first polygons and (5,0,-3) of the second polygons. And changed the order of the vertex in testcase. After we changed the testcase, there is a collision between two polygons.


loaded module collisionAI
loaded module testCasePlayer
Initializing...
Preprocessing...
 Collision detected between polygon No.0 and No.1 with a penetration depth of 1.00024 and penetration vector of (0.800072,0,-0.599904)
Simulation is running...
Postprocessing...
Simulated 13 frames.
Cleaning up...
Done.




EXTRA CREDIT ­­ PART D
We attempted the part D
The standard GJK algorithm cannot detect collision between concave polygons, if we just run the standard GJK for the testcase3, the output shows that there is a collision between to polygons. But actually there is no collision



The idea to fix the code is keep the GJK and EPA algorithm, and add a process which is polygonal decomposition. We separate the polygons to triangles. And detect collision between triangles of each polygons.
We have a function call separatepolygon. In this function, we find the left most point in the polygon A, and find the two adjacent vertices B and C , check this triangle that there is other polygon point P inside the triangle ABC or not. If there is not vertex in the triangle, remove the point A and do the algorithm recursively.  If there is a vertex of polygon P in the triangle, we connect the A and P. the one polygon become to 2 polygons, and call separatepolygon for those two new polygon.
After did this the output of polygon3 is correct.
Output ploygons3:
loaded module collisionAI
loaded module testCasePlayer
Initializing...
Preprocessing...
 NO collision detected between polygon No.0 and No.1
Simulation is running...
Postprocessing...
Simulated 96 frames.
Cleaning up...
Done.
And we edit polygon3 to polygon4 that move the up-right polygon to negative x direction 2 to make two polygon collision, the shapes likes look below. And our algorithm detect the collision correctly


Output ploygons4:
ploygons4:
loaded module collisionAI
loaded module testCasePlayer
Initializing...
Preprocessing...
 Collision detected between polygon No.0 and No.1 with a penetration depth of 2.00048 and penetration vector of (0.800072,0,-0.599904)
Simulation is running...
Postprocessing...
Simulated 215 frames.
Cleaning up...
Done.

We also make a new testcase which is more complex concave polygon to check our separate function is correct or not. The lower polygon separate to five triangle which are
the new triangle is (2,0,1)(0,0,0)(1,0,0)
the new triangle is (2,0,1)(1,0,0)(4,0,1)
the new triangle is (3,0,3)(2,0,1)(4,0,1)
the new triangle is (2,0,-1)(0,0,0)(1,0,0)
the new triangle is (2,0,-1)(1,0,0)(4,0,-1)




Actually, we did some research and found there are many ways to do the polygon decomposition, the way we used is the simplest way to do that. But I think if the polygon is complex enough like it contain so many vertices, our method is not that efficiency. 
After did this, we found a problem that the EPA sometimes does not work correctly to compute the penetration depth and vector when we separated the polygon to triangles. When we detect collision by using two triangles from each polygons, and compute the EPA, the penetration depth and vector is not the depth and vector of polygons. Maybe moving the triangle to a vector with depth can avoid collision with other triangle, but the polygons may also collision in other parts.  We tried to find a way to deal this problem, but unfortunately, we did not find a way to do that.