-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollisionLogger.java
More file actions
69 lines (64 loc) · 3.77 KB
/
CollisionLogger.java
File metadata and controls
69 lines (64 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
Corey Carter
carte731@umn.edu
ID: 5026487
CSCI_1933, Sec-001
Project 2:Object-oriented geometry and graphics - Collision Logger Class
*/
public class CollisionLogger {
int screenWidthWindow; //Creates private variables, need methods to change or use.
int screenHeightWindow;
int bucketWidthWindow;
int[][] masterList = new int[80][80]; //Allows for 10 rows and columns buckets for heatmaping a 800x800 grid
public CollisionLogger(int screenWidth, int screenHeight, int bucketWidth){
screenWidthWindow = screenWidth;
screenHeightWindow = screenHeight;
bucketWidthWindow = bucketWidth; //bucket width allows 1/10th of total grid size
for(int window = 0; window < screenHeight/bucketWidth; window++){ //creates nested heatmap
int subList[] = new int[screenWidth/bucketWidth]; //creates sub list used for nesting list, or cleans out list
for(int subwindow = 0; subwindow < bucketWidth/bucketWidth; subwindow++){ //assigning nested list values, not really needed since empty list default to 0, but I wanted to make sure for certain.
subList[window] = 0; //saves default value of 0
}
masterList[window] = subList; //Saves the nested sub list to master list
}
}
public void collide(Ball one, Ball two) {
int avgYPos = ((int)one.getXPos() + (int)two.getXPos()) / 2; //gets average postion between balls
int avgXPos = ((int)one.getYPos() + (int)two.getYPos()) / 2;
int collisionYGrid = avgYPos / bucketWidthWindow; //removes remainder from number by deiving by bucket amount, the leading int assigns it to the proper nested X and column Y
int collisionXGrid = avgXPos / bucketWidthWindow;
collisionYGrid = Math.abs(collisionYGrid); //Grabs the absolute value incase a ball escapes the play pen
collisionXGrid = Math.abs(collisionXGrid);
if(collisionXGrid < (masterList.length-1)){ //Checks if ball is in play pen border
if(collisionYGrid < (masterList.length-1)){
masterList[collisionYGrid][collisionXGrid] += 1; //Saves 1 to nested location
}
}
}
public int[][] getNormalizedHeatMap() {
int indexYPos = 0; //largest X position
int indexXPos = 0; //largest Y position
int maxValue = 0; //largest value used fro comparison
int maxYDimensions = 0; //Max window size
int maxXDimensions = 0;
for(int maxValYScanner = 0; maxValYScanner < masterList.length; maxValYScanner++){ //scans through columns
for(int subScanner = 0; subScanner < masterList[maxValYScanner].length; subScanner++){ //scans through nested X values
if(masterList[maxValYScanner][subScanner] > maxValue){ //if FOR loop element is greater than saved max value save over it
maxValue = masterList[maxValYScanner][subScanner]; //reassigns max value to new max value
indexYPos = maxValYScanner; //saves Max values positions
indexXPos = subScanner;
}
}
maxYDimensions = masterList.length; //saves max Y length
maxXDimensions = masterList[maxValYScanner].length; //saves max X lengths
}
masterList[indexYPos][indexXPos] = 255; //Changes max value from masterlist to 255
int[][] normalizedHeatMap = new int[maxYDimensions][maxXDimensions]; //Creates Heatmap nesetd list
for(int sweep = 0; sweep < masterList.length; sweep++){ //This copies masterlist values to new Heatmap neste lst
for(int subSweep = 0; subSweep < masterList[sweep].length; subSweep++){
normalizedHeatMap[sweep][subSweep] = masterList[sweep][subSweep];
}
}
return(normalizedHeatMap); //return heatmap
}
}