Home
Simulating the Breaking of Glass in Real Time
Contents
1. 23 bendEnergy numNewCracks ENERGY LOSS allPoints deadEnds else deadEnds push back tempPoint void createCrack CrackStarter starter vector lt Point gt allPoints vector lt Point gt deadEnds Position the first point and add it to the main Point vector Point startPoint new Point starter gt getX starter gt getY allPoints gt push back startPoint Temp variables used below float crackCosAngle float crackSinAngle float tempDist float tempX float tempY Point tempPoint if starter gt getRadialDistance NULL Create vector for start points of each bending stress crack vector lt Point gt bendStarts new vector lt Point gt Create vector for holding the impact stress cross crack points vector lt vector lt Point gt gt impactPoints new vector lt vector lt Point gt gt Position the impact stress cross crack points and bending stress start points for int crack 0 crack lt starter gt getAngles gt size crack Check if this radial crack has no cross cracks if so continue with the next crack if starter gt getRadialDistance gt at crack NULL Place bend start extra point but skip cross cracks impactPoints gt push back NULL crackCosAngle cos starter gt getAngles gt at crack PI 180 0f crackSinAngle sin starter gt getAngles gt at crack PI 180 0f tempDist starter gt
2. 20 Decides what breakLimit will be this is different from time to time switch weibull case 1 breakLimit NORMAL BREAK 0 55 break case 2 breakLimit NORMAL BREAK 0 65 break case 3 breakLimit NORMAL BREAK 0 70 break case 4 breakLimit NORMAL BREAK 0 75 break case 5 breakLimit NORMAL BREAK 0 80 break case 6 breakLimit NORMAL BREAK 0 83 break case 7 breakLimit NORMAL BREAK 0 85 break case 8 breakLimit NORMAL BREAK 0 87 break case 9 breakLimit NORMAL BREAK 0 89 break case 10 breakLimit NORMAL BREAK 0 92 break case 11 breakLimit NORMAL BREAK 0 95 break case 12 breakLimit NORMAL BREAK 0 97 break case 13 breakLimit NORMAL BREAK 1 01 break case 14 breakLimit NORMAL BREAK 1 03 break case 15 breakLimit NORMAL BREAK 1 05 break case 16 breakLimit NORMAL BREAK 1 07 break case 17 breakLimit NORMAL BREAK 1 10 break case 18 breakLimit NORMAL BREAK 1 14 break case 19 breakLimit NORMAL BREAK 1 20 break case 20 breakLimit NORMAL BREAK 1 30 break return breakLimit This changes the break
3. Draw the ceiling and set new texture glEnable GL TEXTURE 2D giBindTexture GL TEXTURE 2D textureID 4 glPushMatrix glColor3f 1 0f 1 0f 1 0f glTranslatef 0 0f 10 08 0 08 glRotatef 90 0f 1 0f 0 0f 0 0f drawTexturedQuad 15 0f 15 0f glPopMatrix void drawFloor Draw the floor glPushMatrix glRotatef 90 0f 1 0f 0 0f 0 0 drawTexturedQuad 15 0f 15 0f glPopMatrix void drawWalls Draw walls and set new texture giBindTexture GL TEXTURE 2D textureID 0 giPushMatrix glYranslatef l5 0f 5 0f 0 08 glRotatef 90 0f 0 0f 1 0 0 0 drawTexturedQuad 15 0f 5 0f glPopMatrix glPushMatrix glTranslatef 15 0f 5 0f 0 0f glRotatef 90 0f 0 0f 1 0 0 0 drawTexturedQuad 15 0f 5 0f glPopMatrix glPushMatrix glTranslatef 0 0f 5 0f 15 0f drawTexturedQuad 15 0f 5 0f glPopMatrix glPushMatrix gilTranslatef 0 0f 5 0f 15 06 glR tatet 190 01 0 01 1 01 0 08 drawTexturedQuad 15 0f 5 0f glPopMatrix void drawWindowFrame Draw the window frame giBindTexture GL TEXTURE 2D textureID 1 giPushMatrix glTranslatef 6 75f 3 58 0 08 drawTexturedBlock 3 25f 3 5f 0 25f glPopMatrix glPushMatrix glYranslatef 6 75f 3 51 0 08 drawTexturedBlock 3 25 3 5f 0 25f glPopMatrix glBindTexture GL TEXTURE 2D textureID 2 giPushMatrix glTranslatef 9 25f 8 5f 0 0f drawTexturedBlock 5 75f 1
4. n 2 where n is the number of corners in the hole polygon the polygon was traversed counter clockwise otherwise the sum will be 180 n 2 and travers ing was clockwise Now we know how to find all the smallest holes but there is still a possibility to find the same hole several times Therefore we added a condition that a segment may only be traversed once in each direction A small example to make it a bit clearer is shown in figure 4 Thanks to the design the loose piece identification is carried out with linear time complexity Figure 4 Finding loose pieces The black dot is the starting point Black arrows indicate the first hole found taking the left most connection at every point At returning to the start point it is checked that the traversal was done counter clockwise Starting again in the same point now marked as light gray almost white the next path is indicated by light gray arrows always using the left most connection When finished the sum of the angles indicate a clockwise traversal which means that the hole is not stored since there is no guarantee that it is minimal Since all the connections from the start point have now been used the next point marked with a dark gray dot is the new starting point Traversing again gives the path of the dark gray arrows and a hole is found since counter clock wise orientation Now all the connections from the dark gray point are used once in each direct
5. Generating the crack pattern is a matter of building the web of Points by following simple rules that makes sure the model is being used correctly The last step may seem like a simple task but it is really non trivial and can be a significant bottle neck from a computational point of view if implemented without caution We found a solution that is not per fect but works reasonably well and utilizes the benefits of the chosen data structure All in all we are satisfied with the result of our work Our demonstration software that is probably not fully optimized shows that it is possible to simulate interesting glass crack patterns in real time on a stan dard PC Even if our solution has some known issues we think that it fulfils its purpose in approaching the subject from in a different direction than other existing attempts ACKNOWLEDGEMENTS We would like to thank Anna Lombardi for providing useful feedback throughout the project Amir Ba ranzahi gave us an invaluable lecture on the basics of amorph materials in general and glass in particular We are also grateful towards Michael H rnquist for answering some important questions during our work with the loose piece identification algorithm and we wish to thank Aida Vitoria for interesting points and discussions regarding the same issue Last but not least Tomas Larsson helped us out when we were strug gling with the statistical aspects of the model All of the persons mentioned above work
6. Maximum number of radials float DISTANCE FACTOR A distance factor to determine the radial cracks int MAX CRACKS The maximun number of cracks int MIN CRACK DIFFERENCE minimum difference between the cracks vector float angleVector vector float safeDistance vector float bendingEnergyVector vector lt float gt impactEnergyVector vector lt vector lt float gt gt radialCrackVector int numberOfCracks float crackEnergy endif CrackStarter cpp This is a class that contains functions that test if there will be any cracks if so how many and to what direction they will propagate It also have functions that give each crack circumferential cracks at given distances Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This file is part of Splitter Splitter is free software you can redistribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public
7. gt getNumConnections i thisPoint gt setTestFlag i true Checks for collisions with all other connections for int i 0 i lt allPoints gt size i if allPoints gt at i thisPoint for int j 0 j lt allPoints gt at i gt getNumConnections j if allPoints gt at i gt getTestFlag j false if findNewIntersection allPoints gt at i allPoints gt at i gt getPoint j thisPoint newPoint amp tempDist pl allPoints gt at i 21 p2 allPoints gt at i gt getPoint j collision true Resets the flags for all the connections when arriving to the second point in the connection allPoints gt at i gt setTestFlag j allPoints gt at 1 gt getTestFlag j In case of a collision connect the new connection with the one colliding with and modify the previous connection If collision with an exact point connection is made to the point in question if collision if newPoint gt getX pl gt getX amp amp newPoint gt getY pl gt getY thisPoint gt connect pl delete newPoint else if newPoint gt getX p2 gt getX amp amp newPoint gt getY p2 gt getY thisPoint gt connect p2 delete newPoint else thisPoint gt connect newPoint pl gt disconnect p2 pl gt connect newPoint p2 gt connect newPoint allPoints gt push_back newPoint else thisPoint gt connect
8. if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA HOHO OH HO XX XX XX XX XX XX XX XX XX XX F F F HF X include lt iostream gt include lt math h gt include lt cstdlib gt include Point h include CrackStarter h include crackCreation h include holes h using namespace std ifndef SPLITTER PI define SPLITTER PI const float PI 3 14159265 endif namespace splitter const float STEPSIZE 0 2f const float ENERGY LOSS 0 025f const int MAX BUBBLE CRACKS 3 Not allowed to be greater than 30 const int MIN DIFFERENCE ANGLE 12 Guarantees visibility of cracks bool findNewIntersection Point pointl Point point2 Point thisPoint Point newPoint float oldDist oat xl pointl gt getX oat yl pointl gt getY oat x2 point2 gt getX oat y2 point2 getY oat x3 thisPoint gt getX oat y3 thisPoint gt getY 7 7 OG tX 07 oat x4 newPoint getX oat y4 newPoint gt getY Ch ES Ch ES CS ES hh ES t 7 Calculate intersection coordinates If den is 0 there is no intersection between the two lines If den is not 0 there is an intersection at apoint along the infinitely long lines with coordinates xnum den ynum den That point may however lie outside of thesupplied points in which case the intersection is not interesting floa
9. impactVelocity lt 20 0f impactVelocity 10 0f frameTime else if impactVelocity gt 20 0f impactVelocity 50 0f frameTime void GLFWCALL updateCrackPattern int button int action if button GLFW_MOUSE BUTTON LEFT amp amp action GLFW PRESS amp amp pos 2 gt 0 if mlClickedAlready false getOGLPos WIDTH 2 HEIGHT 2 posX posY posZ if posX lt 3 5 amp amp posX gt 3 5 amp amp posY lt 8 5 amp amp posY gt 1 5 gg posZ lt 0 1 amp amp posZ gt 0 1 Test if the glass breaks propagate cracks etc cs gt crackTester impactVelocity posX posY 3 5f 8 5f 3 5 1 5 if cs gt getAngles NULL mlClickedAlready true createCrack cs allPoints deadEnds if button GLFW MOUSE BUTTON RIGHT amp amp action GLFW PRESS amp amp pos 2 gt 0 if mlClickedAlready true amp amp mrClickedAlready false findDeadEnds deadEnds allPoints findHoles holes allPoints mrClickedAlready true 44 GLFONT fontCreate HDC hdc const char typeface int height int weight DWORD italic GLFONT font Font data pointer font new GLFONT Memory allocation HFONT fontid Windows font ID int charset Character set code Allocate display lists if font gt base glGenLists 256 0 free font return 0 charset ANSI CHARSET Load the font fontid CreateFont height 0 0 0 w
10. newPoint allPoints gt push_back newPoint return collision void propagate Point thisPoint float prevAngle float bendEnergy vector lt Point gt allPoints vector lt Point gt deadEnds Chance of an airbubble is 10 int chance rand 20 bool airBubble false if chance 1 amp amp bendEnergy gt 0 1 airBubble true int numNewCracks 1 float newAngle 0 0f float newX 0 0f float newY 0 0f float perfectAngle 0 0f float maxDifference 0 0f Temp variables used in loops below Point tempPoint bool collision if airBubble Randomize how many airbubble point if bendEnergy lt 0 2 Make sure there is no airbubble at the end of a crack for esthetic reasons only numNewCracks 1 w new cracks that should start from the else 22 a numNewCracks 1 rand MAX BUBBLE CRACKS 1 perfectAngle maxDifference 360 numNewCracks 1 360 numNewCracks 1 MIN_DIFFERENCE ANGLE f 23g for int i 1 i lt numNewCracks i if airBubble if an air bubble except that they are not allowed to be closer than MIN DIFFERENCE ANGLE to each other newAngle perfectAngle i fmod rand maxDifference 2 newAngle prevAngle 180 0f In the current implementation there is a bug that cracks of angles that are multiples of 90 degrees somehow bypass the collision detection algorithm
11. pl getY 0 0f glVertex3f p2 gt getX p2 gt getY 0 0f glEnd glPopMatrix Draw the rest of the cracks i e the dead ends if pl gt getTestFlag j false amp amp pl gt getEndFlag j true glPushMatrix glBegin GL LINES glVertex3f pl gt getX pl gt getY 0 0f glVertex3f p2 gt getX p2 gt getY 0 0f glEnd glPopMatrix Switch the flag indicating that the connection has been drawn or just resetting it pl gt setTestFlag j pl getTestFlag j glDisable GL BLEND void GLFWCALL reshape int w int h glViewport 0 0 GLsizei w GLsizei h glfwSetMousePos 0 0 mouseX 0 mouseOldX 0 mouseY 0 mouseOldY 0 glMatrixMode GL PROJECTION glLoadIdentity gluPerspective 80 0 double w double h 1 07 300 void GLFWCALL keyPressed int key int action if action GLFW PRESS switch key case GLFW KEY UP upPressed true break case GLFW_KEY DOWN downPressed true break case GLFW KEY LEFT leftPressed true break case GLFW_KEY RIGHT rightPressed true break case W upPressed true break case S downPressed true break case A leftPressed true break case D rightPressed true break case GLFW KEY KP ADD plusPressed tr break case GLFW KEY KP SUB minusPressed t break default bre
12. 2x by 2y by 2z centered on the local origin with texture coordinates for each face Input x side is 2x y side is 2y z side is 2z Qutput void zy void drawTexturedBlock float x float y float z Draw a quad with size 2x by 2y centered on the local origin with texture coordinates for each face Input x side is 2x y side is 2y Output void x void drawTexturedQuad float x float y 60 room cpp File to create all primitives needed in graphics cpp Includes room h Point h and tesselate h Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This file is part of Splitter Splitter is free software you can redistribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Splitter if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA HOO OH XO XX FF XX HF HF F HF X
13. 5f 0 25f glPopMatrix glPushMatrix glTranslatef 9 25f 8 5f 0 0f drawTexturedBlock 5 75 1 5f 0 25f glPopMatrix glBindTexture GL TEXTURE 2D textureID 3 glPushMatrix glTranslatef 0 0f 9 25f 0 0f drawTexturedBlock 3 5f 0 75f 0 25f glPopMatrix giPushMatrix glTranslatef 0 0f 0 75f 0 08 drawTexturedBlock 3 5f 0 75f 0 25f glPopMatrix void drawWindow vector lt vector lt Point gt gt holesVector Draw the glass window with blending and disable textures glEnable GL BLEND glDisable GL TEXTURE 2D glPushMatrix glColor4f 1 0f 1 0 1 0f 0 5f need color with alpha channel if holesVector gt size 0 tesselate holesVector else glTranslatef 0 0f 5 0f 0 0 drawTexturedQuad 3 5f 3 5f glPopMatrix glEnable GL TEXTURE 2D glDisable GL BLEND void drawTexturedBlock float x float y float z glBegin GL QUADS Top face giNormal3f 0 1 0 glTexCoord2f 0 0f 1 0f glVertex3f x y Z glTexCoord2f 1 0f 1 0f glVertex3f x y z glTexCoord2f 1 0 0 0f glVertex3f x y z glTexCoord2f 0 0f 0 0f glVertex3f x y Z Back face glNormal3f 0 0 1 glTexCoord2f 0 0f 1 0f glVertex3f ed 2 glTexCoord2f 0 0f 0 0f glVertex3f x 2 glTexCoord2f 1 0f 0 0f glVertex3f x 2 glTexCoord2f 1 0f 1 0f NN 2 Front face glNormal3f 0 0 1 glTexCoord2f 0 0f 1 0f glVertex3f
14. BIT GL DEPTH BUFFER BIT updateFrameTime updateMousePos updateDirPos updateImpactVelocity glMatrixMode GL_MODELVIEW glLoadIdentity Draw the crosshair centered on the screen center alignment glPushMatrix glColor3f 1 0f 0 0f 0 0f glTranslatef 0 0f 0 0f 1 5f glRasterPos2i 0 0 fontPrintf font 0 X glPopMatrix Draw text in lower right corner left alignment glPushMatrix glColor3f 1 0f 0 0f 0 0 glTranslatef 1 0f 1 0f 1 5 glRasterPos2i 0 0 fontPrintf font 1 Impact velocity 34 0f impactVelocity glPopMatrix Rotate and translate the world glRotatef vAngle 1 0 0 0 0 0 glRotatef hAngle 0 0 1 0 0 0 glTranslatef pos 0 pos 1 pos 2 Execute the room display list glCalllist roomList if allPoints gt size gt 1 drawCracks allPoints drawWindow holes glFlush void drawCracks vector lt Point gt allPoints Point pl Point p2 glEnable GL BLEND glColor4f 1 0f 1 0f 1 0f 0 5 glLineWidth 0 5f for int i 0 i lt allPoints gt size i pl allPoints gt at i for int j 0 j lt pl gt getNumConnections j I p2 pl gt getPoint j if holes gt size 0 Draw all the cracks belonging to holes if pl gt getTestFlag j false amp amp pl gt getEndFlag j false glPushMatrix glBegin GL LINES glVertex3f pl gt getX
15. This file is part of Splitter Splitter is free software you can redistribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Splitter if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA HOO OH FF FF FF FF HF HF HF XX XX XX XXX F F F F F HF HF X include Point h include CrackStarter h using namespace std namespace splitter Used by safeConnect This function checks whether the supplied points form lines that intersect closer to the start point than the last found intersection Input pointl First point used in the first line point2 Second point used in the first line a thisPoint The start point of the proposed new line newPoint The end point of the proposed new line oldDist The city block distance from thisPoint to the nearest previously detected intersection Should be 0 to indicate that no intersection has been detected before Output TRUE if a new intersection is found closer than any p
16. at the Department of Science and Technology ITN at Link ping University CONTENTS I INTRODUCTION nenne ee I 1 1 BACKGROUND AND PURPOSE 2000000000000000 na I TED SOURCES Hin er ies ee een I 1 3 METHOD P vekket os I TA STRUCTURE pe Gad bee ee pu tona eun 2 2 SIMULATING THE BREAKING OF GLASS IN REAL TIME 2 2 1 THE MODEL 2 3 1 1 PHYSICAL FOUNDATION Vanse ansehe 2 3 172 SIMPLIFICATIONS ik nee 3 2 2 THE IMPLEMENTATION esee eene SA 6 2 2 1 WG HE GLASS BREAKS iate ters tite Ug Pe uet irt rd ost rex iren ius 6 2 2 2 DATA STRUCTURE FOR REPRESENTING CRACKS eese nee 6 2 23 CRACK PROPAGATION 45 Garde dena vend reser arter eden 7 2 2 4 LOOSE PIECE IDENTIFICATION c csssesscececenseaussesescescececeaueascsecesceeeeeeeeanens 8 2 3 GRAPHICAL REPRESENTATION eese enne enhn enne ennt senes nns 9 2 4 KNOWN ISSUES niet nennen IO 3 IHE RESUDE een II A DISCUSSION EE NE II REFERENCES 13 APPENDIX SCREENSHOTS FROM THE SIMULATION 13 APPENDIX B SYSTEM REQUIREMENTS IS APPENDIX C USER MANUAL eerte 16 APPENDIX D SOURCE COoDE 1 1 eee 17 FIGURES FIGURE 1 THE WEIBULL PROBABILITY FUNCTION FIGURE 2 IMPACT STRESS CRACK PATTERN FIGURE 3 MINIMAL LOOSE PIECES FIGURE 4 FINDING LOOSE PIECES FIGURE 5 THE DEAD END PROBLEM 1 INTRODUCTION This report aims to pr
17. float prevAngle float bendEnergy vector lt Point gt allPoints vector lt Point gt deadEnds Creates the data representation of a crack from impact to stationary phase Input starter CrackStarter object with init info for the propagation u allPoints Vector containing all the crack segment points deadEnds Vector that includes all the end points in the crackpattern and their connections Output None xy void createCrack CrackStarter starter vector lt Point gt allPoints vector lt Point gt deadEnds I9 crackCreation h Contains functions for creating the crack pattern crack propagation with collision detection between cracks Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This file is part of Splitter Splitter is free software you can redistribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Splitter
18. free software you can redistribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Splitter if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA fndef SPLITTER POINT define SPLITTER POINT include lt vector gt us ing namespace std namespace splitter class Point public Creates a Point object with unspecified coordinates Input void Output A Point object Point Creates a Point object with the specified coordinates Input x the new X coordinate d y the new Y coordiante Output A Point object Point float x float y Point Point numPoints void setXY float x float y this gt x x this gt y y void setX float x this gt x x void setY float y this gt y y Sets the intersection test flag at position i to the specified value Note that the flag is shared between the two connected points so this method only has to be run on one
19. getSafeDistance gt at crack 0 01 tempX tempDist crackCosAngle tempY tempDist crackSinAngle tempX starter gt getX tempY starter gt getY tempPoint new Point tempX tempY bendStarts push back tempPoint startPoint gt connect tempPoint allPoints gt push back tempPoint continue impactPoints push back new vector lt Point gt crackCosAngle cos starter gt getAngles gt at crack PI 180 0f crackSinAngle sin starter gt getAngles gt at crack PI 180 0f for int p 0 p lt starter gt getRadialDistance gt at crack gt size ptt 24 tempDist starter gt getRadialDistance gt at crack gt at p tempX tempY tempX tempY tempDist crackCosAngle tempDist crackSinAngle starter gt getX starter gt getY tempPoint new Point tempX tempY impactPoints gt at crack gt push_back tempPoint allPoints gt push_back tempPoint if p 0 startPoint gt connect impactPoints gt at crack gt at p else impactPoints gt at crack gt at p 1 gt connect impactPoints gt at crack gt at p Position bend start point if starter gt getRadialDistance gt at crack gt size gt 0 int pos starter gt getRadialDistance gt at crack gt size 1 tempDist starter gt getRadialDistance gt at crack gt at pos tempDist starter gt getSafeDistance
20. is considered part of a dead end if it has less than two non dead end connections A boolean flag indicating this had already been set during the algorithm that checks if a crack is a dead end Using this method gave rise to a small issue explained in detail in the next section 2 4 Known ISSUES One of our main goals was to make our algorithms as general as possible expecting that this would result in few issues Despite this two issues not to be overlooked rose The first problem occurs when the velocity of the colliding object is high enough to contain impact stress energy When the resulting radial cracks or circumferential cracks are calculated and if some crack is given an angle that is an integer multiple of 90 degrees this crack doesn t connect to other cracks in a proper way the collision detection methods somehow cannot handle it To get around this we decided to increase such angles by 0 1 degrees This will not significantly alter the visual result but eliminates the bug The second problem is a result of simplifications in our implementation In the second step of our visual ization when the created holes are shown we only draw the cracks that are dead ends since other cracks are part of loose pieces and are thus removed In almost every case this gives us our expected result but when two not adjacent holes are connected corner to corner by a crack see figure 5 it does not The crack join ing the two holes is by the algorith
21. is high resulting in many cracks there is a delay for a fraction of a sec ond This is noticeable when the camera is moving at the same time as the crack pattern is calculated and visualized The most time consuming part is the naive collision detection that checks if a crack intersects another crack which we believe to be the bottle neck of the crack generation algorithm To summarize the final program has some flaws but still produces realistic and interesting crack patterns The loose pieces are always found something that is done in linear time It is fair to say that we managed to reach the goals we had set up for this project 4 DISCUSSION Even though we are satisfied with the result of our work there are a number of points that could be im proved First of all there is the obvious business of animated loose pieces falling off the window pane This we skipped since it was not really connected with the main issue of producing realistic crack patterns but we did prepare for such an extension by being thorough in our work with the loose piece identification Not so thorough though that the solution is flawless there is currently the problem with some dead ends indeed uncommon but still there This could probably be solved in some more or less simple manner but we have failed to produce such a solution The method could of course be considered improved if we had added support for multiple strikes This was our intent
22. just as they can in reality Each radial crack is assigned some kind of energy in terms of how long it can get at a maximum We also model the probability and effect of cracks hitting air bubbles Cracks do not divide into several new ones if the crack that hit the air bubble is close to run out of energy This represent our assumption that a certain amount of energy is needed for the outgoing cracks to break through the walls of the air bubble We use a linear model when calculating the number of circumferential cracks their distances to the impact point and so on This is probably not physically correct in fact we have not found any written material that states any facts about how it really works but it looks good enough and makes computations fast and simple 2 2 THE IMPLEMENTATION We broke down the problem into four separate logical steps namely deciding whether and how the glass breaks generating the crack pattern from these starting conditions building of a data structure to represent the pattern and finally identification of the loose pieces that may or may not have formed in the pattern In the following sections each of these steps are described more in detail 2 2 1 Witt THE GLASS BREAK The first thing that happens when you have hit the glass with a certain speed and at a certain place on the window glass is that the program calculates if the glass will break at all This is first done with a random function
23. limit if you don t hit in the center of the window float CrackStarter realBreakLimit float breakLimit float placeX float placeY float cornerOneX float cornerOneY float cornerTwoX float cornerTwoY centerX cornerTwoX cornerOneX 2 cornerOneX centerY cornerOneY cornerTwoY 2 cornerOneY distanceToCenter pow centerX placeX 2 pow centerX placeX 2 actualBreakLimit breakLimit BREAK LIMIT sqrt distanceToCenter return actualBreakLimit void CrackStarter crackGenerator float hitsize float actualBreakLimit crackEnergy hitsize actualBreakLimit if crackEnergy lt 0 numberOfCracks 0 else There should always be an even number of cracks numberOfCracks 2 int crackEnergy CRACK NUMBER if numberOfCracks gt MAX CRACKS numberOfCracks MAX CRACKS void CrackStarter angleGenerator vector lt float gt angleVector float perfectAngle 360 numberOfCracks int maxDifference 360 numberOfCracks MIN CRACK DIFFERENCE 2 float angle for int i 0 i lt numberOfCracks 2 i Give each crack an angle angle maxDifference 2 perfectAngle i rand maxDifference maxDifference 2 if angle O angle 90 Jangle 180 Jangle 270 angle 0 1 Due to the multiple of 90 degrees bug 33 angleVector gt push_back angle for int i 0 i lt numberOfCracks 2 i Cracks continue in bot
24. parameters at the command line The following command starts the program and sets the resolution to 1600 x 1200 pixels splitter exe 1600 1200 If no resolution parameters are specified the resolution will default to 1024 x 768 pixels Once the program is running use the mouse to look around in the virtual environment It is possible to move around and control the simulation using the following keys W or UP arrow Move forward S or DOWN arrow Move backward A or LEFT arrow Move left D or RIGHT arrow Move right Keypad Increase impact velocity Keypad Decrease impact velocity Left mouse button Hit the glass window where the crosshair points Right mouse button Remove loose glass pieces after a crack pattern has formed SPACE Reset the simulation ESCAPE Quit the program I6 APPENDIX D SOURCE CODE splitter cpp The main application file of the Splitter project This file contains the main program loop Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This file is part of Splitter Splitter is free software you can redistribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOU
25. prevent aliasing in blending LfwOpenWindow WIDTH HEIGHT 8 8 8 8 24 O GLFW FULLSCREEN 41 glEnable GL LINE SMOOTH glEnable GL POINT SMOOTH Create a new font font fontCreate wglGetCurrentDC Verdana 15 O 0 Init point vector and CrackStarter object resetCracks void resetCracks if allPoints NULL Delete all points in the vector and the vector for int i 0 i lt allPoints gt size i delete allPoints gt at i delete allPoints if deadEnds NULL Delete the vector delete deadEnds if holes NULL Delete the different vectors including the hole points for int i 0 i lt holes gt size i delete holes gt at i delete holes holes new vector lt vector lt Point gt gt Create a new vector including all the points and the points marked as dead ends allPoints new vector lt Point gt deadEnds new vector lt Point gt if cs NULL delete cs Create a new object that determents the crack pattern cs new CrackStarter resetTessList mlClickedAlready false mrClickedAlready false void initUIInput glfwSetWindowSizeCallback reshape glfwSetKeyCallback keyPressed glfwSetMouseButtonCallback updateCrackPattern glfwEnable GLFW STICKY KEYS void showFPS double fps Get current time double t glfwGetTime Gets number of seconds since glfwI
26. the characteristics of crack patterns depend heavily on the type of glass we have limited ourselves to considering the type of window glass that can be found in a typical display window of a shop That is not exactly bullet proof but not really wine glass thin either Initially we wanted to be able to hit the same window several times but we soon decided just to allow one hit Because of this we could set up a simpler and more general model for how the cracks will propagate A simplification that is perhaps not so easy to justify is our choice of impact force Since we could not find any facts about the relationship between the breaking point of the glass and the velocity size or mass of the crushing object we decided to assume that the object is of a fixed size about the size of a tennis ball in this case has a constant unknown mass and hits the glass pane with some impact velocity The 3 o applied lo o 0 0 80 1 00 1 20 1 40 0 80 0 60 0 40 Characteristic Strength o 0 20 0 0 Applied Stress Figure 1 The Weibull probability function Glass has a Weibull number of between fire and eight In the figure m is the Weibull number The higher the number the more determined is the breaking point of the material Having a relatively low number glass will exhibit a breaking behavior that is quite hard to predict Figure 2 Impact stress crack pattern The photo shows a cracked glass window pane where c
27. the following check is made just to make sure no are allowed to be an exact multiple of 90 degrees newAngle HI newAng newAng le le newAngle newAngl else If not an air bubble interval newAngle a rand MIN DIFFERENCE ANGLE MIN DIFFERENCE ANGLE 2 newAngle prevAngle Same check as above if newAngle newAngle newAngle newAngle newAngle newAngle fmod newAngle 360 0f 360 0f Calculate the coordinates for the new point points maxDifference the new angles are randomized fully causes to Therefore angles the angle is randomized in a narrow newX STEPSIZE cos newAngle PI 180 0f newY STEPSIZE sin newAngle PI 180 0f newX thisPoint gt getX newY thisPoint gt getY tempPoint new Point newX newY collision safeConnect thisPoint tempPoint allPoints if collision In the current implementation there is no phase where the loose pieces actually fall off the window pane One could imagine that spare energy that is left when a crack joins with another somehow affects how the piece that may result is hurled away In that case the calculation of that energy should probably be performed here else if bendEnergy numNewCracks ENERGY_LOSS gt 0 I the energy in the crack is not zero after decreasing it propagate is run again with less energy propagate tempPoint newAngle
28. trough all dead ends for int i 0 i lt deadEnds gt size i id deadEnds gt at i gt getID p allPoints gt at id dead end and function for finding all the smallest holes i e the smallest If number of connections in one point is larger than four it must be a hole due to the number of possible cracks from an airbubble if p gt getNumConnections lt 5 int j p gt getNumConnections while j gt 0 amp amp j lt 5 counter 0 Checks how many connections already set to dead end If the number of dead ends are one less than the number of connections then the connection is also a dead end for int connection 0 getNumConnections connection lt p gt connection if p gt getEndFlag connection counter else notDeadEnd connection if counter p gt getNumConnections 1 p gt setEndFlag notDeadEnd true p p gt getPoint notDeadEnd else break j p getNumConnections void findHoles vector lt vector lt Point gt gt holes vector lt Point gt allPoints bool checkedAll false float polygonAngle 0 0f float thisAngle 0 0f float nextAngle 0 087 float firstAngle 0 08 int pos 0 Point firstPoint Point thisPoint Point prevPoint Point nextPoint Point p vector lt Point gt holePoints new vector lt Point gt Loop through all points for int i 0 i lt al
29. vector with distances to each radialcrack for each crack and a vector with a safe distance to next crack Input radialCrackVector A pointer to a vector that for each X crack containing points to other vectors in which the radial 29 distances is stores safeDistance A pointer to a vector containing safe distances to next crack Output void 7 void radialCrackGenerator vector lt vector lt float gt gt amp radialCrackVector vector lt float gt amp safeDistance 0X int weibull A number between 1 20 every number symbols five percent float breakLimit Our windows break limit in the centre of the window float actualBreakLimit Break limit where the hit stroke float centerX Our windows center point float centerY float distanceToCenter The distance from the hit to the center float maxDifference The maximum difference between angles float placeX Hit position float placeY float BREAK LIMIT how much the position change the break limit float CRACK NUMBER How many cracks will errupt due to the energy float ENERGY DIFFER How much will the energy differ between the cracks int NORMAL BREAK A window normal break limit int BENDING INTERVAL The energy interval where only bending accurs int CROSS INTERVAL The energy interval where both bending and impact accurs float RADIAL FACTOR Decides the number of cracks int MAX RADIALS
30. x y Z glTexCoord2f 1 0f 1 0f glVertex3f x y z glTexCoord2f 1 0f 0 0f glVertex3f x p glTexCoord2f 0 0f 0 0f glVertex3f x y Z Left face giNormal3f 1 0 0 glTexCoord2f 1 0 0 0f glVertex3f x y z glTexCoord2f 1 0f 1 0f ee dd A 2 glTexCoord2f 0 0f 1 0f glVertex3f x 2 3 glTexCoord2f 0 0 0 0 glVertex3f x ee Right face giNormal3f 1 0 0 glTexCoord2f 1 0f 1 0f glVertex3f x y Z glTexCoord2f 1 0f 0 0f glVertex3f x y Z glTexCoord2f 0 0f 0 0f glVertex3f x ie glTexCoord2f 0 0f 1 0f glVertex3f x 2 Bottom face glNormal3f 0 1 0 glTexCoord2f 0 0f 1 0f glVertex3f x Aag glTexCoord2f 0 0f 0 0f glVertex3f x u glTexCoord2f 1 0f 0 0f glVertex3f x 2 glTexCoord2f 1 0f 1 0f glVertex3f x 2 glEnd void drawTexturedQuad float x float y glBegin GL QUADS Front face glNormal3f 0 0 1 glTexCoord2f 0 0f 1 0f glTexCoord2f 0 0f 0 0f glTexCoord2f 1 0f 0 0f glTexCoord2f 1 0f 1 0f glEnd H glVertex3f x y 0 0f H glVertex3f x y 0 0f H glVertex3f x y 0 0f H glVertex3f x y 0 0f tesselate h Contains functions that tesselates the glass according to the holes Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This file is part of Splitter Splitter is free software you can redi
31. 004 07 1090933065 Ph r html Verified 2004 12 18 I2 APPENDIX A SCREENSHOTS FROM THE SIMULATION Below are eight screenshots from the actual simulation demonstrating the generated crack patterns for dif ferent impact velocities The images have been processed for contrast enhancement Figure A 3 Impact velocity 16 Figure A 4 Impact velocity 19 13 Figure A 7 Impact velocity 30 Figure A 8 Impact velocity 40 14 APPENDIX B SYSTEM REQUIREMENTS The simulation has not been tested on that many machines but we have found it working excellently on a PC with the following hardware AMD 64 3500 or equivalent 32 Mb of working memory RAM Nvidia GeForce 6800GT or equivalent 7 Mb of free harddrive space Microsoft Windows with OpenGL installed The program will probably run quite smoothly even if the machine is not as powerful as the one above but lesser lags could occur Generally an OpenGL enabled graphics card is highly recommended The source code should compile under other operating systems as well possibly with some modifications needed For this OpenGL GLU and GLFW are all required IS APPENDIX C User MANUAL We have tried to make our program quite easy to use even though we must admit that the user interface has not been a top priority issue The simulation runs in full screen mode but the resolution can be changed to match the available hard ware This is done by supplying a couple of extra
32. AD hAngle pos 2 frameTime WALKING SPEED cos DEG2RAD hAngle if leftPressed pos 0 frameTime WALKING SPEED cos DEG2RAD hAngle pos 2 frameTime WALKING SPEED sin DEG2RAD hAngle if rightPressed pos 0 frameTime WALKING SPEED cos DEG2RAD hAngle pos 2 frameTime WALKING SPEED sin DEG2RAD hAngle if pos 0 gt 13 pos 0 13 else if pos 0 lt 13 pos 0 13 if pos 2 gt 13 I pos 2 13 else if pos 2 lt 13 pos 2 13 43 void getOGLPos int x int y GLfloat amp posX GLfloat amp posY GLfloat amp posZ GLint viewport 4 GLdouble modelview 16 GLdouble projection 16 GLfloat winX winY winZ GLdouble tempX tempY tempZ glGetDoublev GL MODELVIEW MATRIX modelview glGetDoublev GL PROJECTION MATRIX projection glGetIntegerv GL VIEWPORT viewport winX float x winY float viewport 3 float y glReadPixels x int winY 1 1 GL DEPTH COMPONENT GL FLOAT amp winZ gluUnProject winX winY winZ modelview projection viewport amp tempX amp tempY amp tempZ posX tempX posY tempY posz tempZ void updateImpactVelocity if plusPressed if impactVelocity 20 0f impactVelocity 10 0f frameTime else if impactVelocity gt 20 0f amp amp impactVelocity lt 40 0f impactVelocity 50 0f frameTime if minusPressed if impactVelocity gt 0 1f amp amp
33. GHT 768 Impact velocity float impactVelocity 0 0f For the fps double t0 0 0 int frames 0 char titlestring 200 To get the frametime float frameTime 0 double tOld 0 Angles for the view vector float hAngle 0 07 float vAngle 0 07 Keyboard inputs bool upPressed false bool downPressed false bool leftPressed false bool rightPressed false bool plusPressed false bool minusPressed false Mouse coordinates int mouseX 0 int mouseY 0 int mouseOldX 0 int mouseOldY 0 Projection GLfloat posX posY posZ Font data LFONT font Q Ambient light GLfloat globalLight 0 5 0 5 0 5 1 0 Room display list index GLuint roomList void initGraphics int resW int resH WIDTH resW HEIGHT resH LfwInit LfwSetWindowPos 200 200 LfwDisable GLFW MOUSE CURSOR lfwEnable GLFW STICKY KEYS 2a aaa 1ClearColor 0 0 0 0 0 0 0 0 lShadeModel GL SMOOTH LPolygonMode GL FRONT AND BACK GL FILL ILightModelfv GL LIGHT MODEL AMBIENT globalLight LLightModeli GL LIGHT MODEL LOCAL VIEWER GL TRUE LEnable GL DEPTH TEST lEnable GL LIGHTING lEnable GL NORMALIZE 2 0222242 Initialize textures initTextures Init room display list roomList initRoomDisplayList Used to enable blending glEnable GL COLOR MATERIAL glBlendFunc GL SRC ALPHA GL ONE MINUS SRC ALPHA Used to
34. Last for int i 0 i numberOfCracks 1 i if radialCrackVector gt at i NULL thisLast radialCrackVector gt at i gt at radialCrackVector gt at i gt size 1 else thisLast 0 0f if radialCrackVector gt at i 1 NULL nextLast radialCrackVector gt at i 1 gt at radialCrackVector gt at i 1 gt size 1 else nextLast 0 0f 35 if nextLast thisLast gt 0 safeDistance push back nextLast thisLast else safeDistance gt push_back 0 if radialCrackVector gt at numberOfCracks 1 NULL thisLast radialCrackVector gt at numberOfCracks else thisLast 0 0f if radialCrackVector gt at 0 NULL nextLast radialCrackVector gt at 0 gt at else nextLast 0 0f if nextLast thisLast gt 0 safeDistance push back nextLast thisLast else safeDistance push back 0 vector float CrackStarter getAngles if numberOfCracks 0 return NULL return angleVector vector lt float gt CrackStarter getBendingEnergyVector return bendingEnergyVector vector lt float gt CrackStarter getSafeDistance return safeDistance float CrackStarter getX return placeX float CrackStarter getY return placeY vector lt vector lt float gt gt CrackStarter getRadialDistance return radialCrackVector radialCrackVector gt at numberOfCracks 1 gt si
35. License along with Splitter if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA TH include CrackStarter h include lt iostream gt include lt cstdlib gt include lt cmath gt include lt vector gt using namespace std namespace splitter CrackStarter CrackStarter initials the constants BREAK LIMIT 1s CRACK NUMBER 1 ENERGY DIFFER 0 099 NORMAL BREAK 10 BENDING INTERVAL 5 CROSS INTERVAL 20 RADIAL FACTOR 20 0f MAX RADIALS 10 DISTANCE FACTOR 3 MAX CRACKS 30 MIN CRACK DIFFERENCE 12 angleVector new vector lt float gt bendingEnergyVector new vector lt float gt impactEnergyVector new vector lt float gt radialCrackVector new vector lt vector lt float gt gt safeDistance new vector lt float gt void CrackStarter crackTester float hitSize float placeX float placeY float cornerOneX float cornerOneY float cornerTwoX float cornerTwoY this gt placeX placeX this gt placeY placeY actualBreakLimit realBreakLimit configureBreakLimit placeX placeY cornerOneX cornerOneY cornerTwoX cornerTwoY crackGenerator hitSize actualBreakLimit if numberOfCracks 0 angleGenerator angleVector energyGenerator bendingEnergyVector impactEnergyVector radialCrackGenerator radialCrackVector safeDistance float CrackStarter configureBreakLimit weibull 1 rand
36. Link ping University 2005 01 13 SPLITTER Simulating the Breaking of Glass in Real Time SR NAG Jesper Carlson jescal44 student liu se Daniel Enetoft danen736 student liu se Anders Fjeldstad andfj645 student liu se a M AN NG Kristofer G rdeborg kriga592 student liu se ABSTRACT The goal of the Splitter project was to simulate the breaking of glass window panes in a graphical applica tion in real time with some degree of realistic physics We accomplished this by starting from what is known about the different types of crack patterns that can arise working our way towards a simple and fast model that still produces reasonable looking results The simulation can be broken down into four main steps namely 1 Deciding if and how the glass will break 2 Setting up the data structure that represents the pattern 3 Generating the crack pattern 4 Detecting all loose pieces that may have formed in the pattern Whether and how the glass breaks is in our model partly based on real physics but mostly on general knowledge of different possible crack patterns and their characteristics This makes the process fast while not sacrifying too much realism in our opinion The data structure we developed can be described as a web of connected Points each having information about itself and its connection to other Points There is also a separate list of all Points kept for making ac cess to Points faster in some cases
37. RULE GLU TESS WINDING POSITIVE Draws the window gluTessBeginContour tobj for int i 3 i gt 0 i gluTessVertex tobj vertexVector gt at 0 i vertexVector gt at 0 i gluTessEndContour tobj Draws the contour of the holes starts from behind since the holes is defined counter clockwise for int i 1 i lt vertexVector gt size i gluTessBeginContour tobj for int j tessVector gt at i 1 gt size 1 j gt 0 j gluTessVertex tobj vertexVector gt at i jl vertexVector gt at i j gluTessEndContour tobj gluTessEndPolygon tobj glEndList gluDeleteTess tobj else glCallList objektList 68
38. T ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Splitter if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 EEE GRO GRO ORO ORO AR ORO BO BO RRR RS OR AR AR AR RRR RRA include lt windows h gt include lt GL glfw h gt include lt cstdlib gt include graphics h using namespace std using namespace splitter Main method initializes everything includs the main loop that ends when Esc key is pressed Kj int main int argc char argv bool running true if arge gt 2 initGraphics atoi argv l atoi argv 2 else initGraphics 1024 768 initUIInput srand time 0 while running ShowFPS draw Swap the drawing buffers glfwSwapBuffers Check if esc is pressed or if the window is closed running glfwGetKey GLFW KEY ESC amp amp glfwGetWindowParam GLFW OPENED deinitGraphics return 0 USA 17 crackCreation h Contains functions for creating the crack pattern crack propagation with collision detection between cracks Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg
39. X XX XX XX XX XX F F HF KF X include lt GL glfw h gt include room h include Point h include tesselate h ifndef SPLITTER TEXTUREID define SPLITTER TEXTUREID For textures sets number of textures GLuint textureID 5 endif using namespace std namespace splitter void initTextures Load and set up textures use GLFW to make this easier glEnable GL TEXTURE 2D Enable texturing glGenTextures 5 textureID Generate 5 unique texture IDs to use glBindTexture GL TEXTURE 2D textureID 0 Activate first texture glfwLoadTexture2D textures grycon tga GLFW BUILD MIPMAPS BIT glBindTexture GL TEXTURE 2D textureID 1 Activate second texture glfwLoadTexture2D textures yellobrk2 tga GLFW BUILD MIPMAPS BIT glBindTexture GL TEXTURE 2D textureID 2 Activate third texture glfwLoadTexture2D textures yellobrk3 tga GLFW BUILD MIPMAPS BIT glBindTexture GL TEXTURE 2D textureID 3 Activate fourth texture glfwLoadTexture2D textures yellobrk4 tga GLFW BUILD MIPMAPS BIT glBindTexture GL TEXTURE 2D textureID 4 Activate fifth texture glfwLoadTexture2D textures stucco tga GLFW BUILD MIPMAPS BIT GLuint initRoomDisplayList GLuint index glGenLists 1 glNewList 1 GL COMPILE drawCeiling drawFloor drawWalls drawWindowFrame glEndList return index void drawCeiling
40. ak if action GLFW_RELEA switch key case GLFW KEY U upPressed break case GLFW KEY DOWN downPressed break case GLFW_KEY LEFT leftPressed break case GLFW KEY RIGH rightPressed break case WW upPressed break case S downPressed break case A leftPressed break case D rightPressed break case GLFW KEY K plusPressed fa break case GLFW KEY KP SUB minusPressed break case GLFW KEY SPACE resetCracks break default break void deinitGraphics fontDelete font glfwTerminate ue TRACT i1 rue SE Pr i false false toi false T false false false false false P ADD lse TRACT false 48 holes h File to find all the parts of the crack pattern belonging to a dead end and function for finding all the smallest holes i e the smallest glass pieces made by the crack pattern Included in graphics cpp Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This file is part of Splitter Splitter is free software you can redistribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later
41. allback GLenum errorCode void CALLBACK endCallback void void CALLBACK vertexCallback GLvoid vertex void CALLBACK combineCallback GLdouble coords 3 GLdouble vertex data 4 GLfloat weight 4 GLdouble dataOut 65 tesselate cpp Contains functions that tesselates the glass according to the holes Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This file is part of Splitter Splitter is free software you can redistribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Splitter if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA HOO FF FF FF FF FF KF HF XX XX XX XX HF F XX F HF HF HF Tag include lt vector gt include Point h include tesselate h include lt GL glfw h gt using namespace std static GLuint objektList void resetTessList glDeleteLists obj
42. attached as an appendix 2 SIMULATING THE BREAKING OF GLASS IN REAL TIME The objective was to simulate the breaking of glass in a way that is to some extent reasonable from a physi cal point of view On one hand we had the aim to make the simulation realistic on the other we had the restriction on the computations involved the simulation was to run in real time This required a model quite simplified compared to the reality and a well planned implementation The following section will present our thoughts and decisions made during the development process 2 1 THE MoDeL Glass is a very complex material There is no exact formulas which can tell how glass will shatter and the for mulas there are demand a high level of knowledge of physics and chemistry We didnt have the time to learn all the things we would need to understand everything and we needed a simplified model for the simulation to run in real time We decided to go through the physics to get an overview then extract the properties that have the largest impact on how shattered glass really looks and to build a model based on this 2 1 1 PHYSICAL FOUNDATION The following text is based on a conversation with Amir Baranzahi ITN Link ping University that took place on 10 November 2004 when not stated otherwise Glass SiO2 is an amorphous material which means that the material is a mix between a solid and a fluid On a microscopic level this means that in glass the ato
43. bubble are the weakest and there may be several such spots The number of air bubbles in a glass is impossible to tell in advance but if there are visible ones there are prob ably many more that are so small that you cannot see them A crack propagates with a very high speed This differs from different sorts of glass but in general you can say that the speed is approximately 1950 m s Weeks 2004 compared to a bullet that travels in about 800 m s This means that you will never be able to see a crack spread in a window glass When a strike hits a window cracks will form if the glass bends more than it can withstand Glass as a material is quite non elastic which is why a window easily cracks If a strike is hard enough circumferential crack patterns will form see figure 2 Also the number of radial cracks will be larger Mencik 2002 There is no way of telling how many cracks will form when the window is hit by a given blow but in general you can say that if you hit harder more cracks will form There will almost always be cracks forming at opposite directions from each other i e if one crack propagates out from the impact point at one direction there will be another that starts off with the angle of the other one plus 180 degrees When you hit hard enough the holes in the window will no longer get larger but smaller This is because the object you hit with will go through the glass before it has time to expose the material to any signif
44. ces to technical publications and books as well as online documents 1 3 METHOD Since the purpose of the project was to develop a model imitating a physical process we began by collecting and discussing known facts about the behavior of cracks in glass materials In parallel with this we draw the first outlines for the main parts of the algorithm as well as some of the more complicated sub algorithms such as crack propagation and the method for finding loose glass pieces in the crack pattern When we felt sufficiently prepared we started to program the actual software done in the C and C languages using OpenGL and GLFW for graphics and user input During this processing we paused to test and debug our work regularly Notes about decisions made as well as important e mail dialogs physical theory and algorithm outlines were posted to a simple online log that we developed at the start of the project This simplified the process of writing this report since all important information was stored in one single document accessible over the World Wide Web 1 4 STRUCTURE We have tried to make this report as understandable and logically laid out as possible We begin by describ ing the physical facts that our model is based upon followed by the simplifications and the actual model Then the implementation of the model is explained in detail after which the result is presented and evalu ated The source code for the graphical program is
45. e same way since they together form a large hole The goal of the loose piece identification is to find each separate piece even if they together could count as a single hole 1 Start at an arbitrary Point in the pattern We start the trace for holes from the impact point but the algorithm is not depending on this 2 From the current point go to the next by always choosing the left most connection 3 If arriving back at the starting point we have a closed loop of connected Points describing the edge of a hole and a check is needed to find out whether it has been traversed clockwise or counter clockwise If the direction was counter clockwise the hole is guaranteed to be minimal in the way we are interested in If the orientation is found to be clockwise there is no such guarantee which in turn implies that a larger hole containing several minimal holes is found This is easy to understand with a figure but how to implement it is perhaps not as clear Our solution is to check all Points in the loop and their connections to other Points For every new Point which corresponds to a corner in the polygon defined by the loop we calculate the angle between incoming and outgoing segments that is the left most con nection viewed from the incoming one This is a simple operation since the angles are saved in every Point at the creation of the crack pattern At arrival at the starting point if the sum of all the angles are 180
46. ection which is also a limitation for viewing purpose If the bending energy left in the crack is very small the crack will not split in an air bubble When all the energy is used the crack stops After the crack pattern resulting from both impact and bending stress has been generated and stored in the Vector of Points the crack propagation step of the algorithm is finished Mainly due to the naive intersection test used the crack propagation takes quadratic time which could certainly be improved for faster execution 2 2 4 Loose PIECE IDENTIFICATION One of the main parts in our application was to come up with an algorithm to find all the holes in the window created by the crack pattern The idea is to find the smallest holes the holes corresponding to the smallest loose glass pieces and no holes that consists of other holes An example of this is shown in figure 3 This criteria was set because we wanted to make it possible to extend the application further with pieces falling off the glass window To start the process of finding all the holes the first thing to do is to eliminate all the cracks that are not important which in this case are the dead ends if the pattern is imag ined as a maze When all the dead ends are removed from consideration the method is as follows Figure 3 Minimal loose pieces The figure shows three different holes all numbered independently Hole number one and two is col ored in th
47. eight italic FALSE charset OUT TT PRECIS CLIP DEFAULT PRECIS DRAFT QUALITY DEFAULT PITCH typeface SelectObject hdc fontid Create bitmaps for each character wglUseFontBitmaps hdc 0 256 font gt base Get the width and height information for each character GetCharWidth hdc 0 255 font gt widths font gt height height return font void fontDelete GLFONT font if font GLFONT 0 return glDeleteLists font gt base 256 free font void fontPuts GLFONT font const char s if font GLFONT 0 s NULL return glPushAttrib GL LIST BIT glListBase font gt base glCallLists strlen s GL UNSIGNED BYTE s glPopAttrib void fontPrintf GLFONT font int align char format va_list ap Argument pointer char s 1024 ptr Output string Pointer into string int width Width of string in pixels if font GLFONT 0 format char 0 return Format the string va_start ap format vsprintf char s format ap va end ap Figure out the width of the string in pixels for ptr s width 0 ptr ptr width font gt widths ptr Adjust the bitmap position as needed to justify the text if align lt 0 45 glBitmap 0 0 0 0 width 0 NULL else if align 0 glBitmap 0 0 0 0 width 2 0 NULL Draw the string fontPuts font s void draw glClear GL COLOR BUFFER
48. ektList 1 The callback functions is called during tessellation at appropriate times void CALLBACK beginCallback GLenum which glBegin which void CALLBACK errorCallback GLenum errorCode const GLubyte estring estring gluErrorString errorCode fprintf stderr Tessellation Error s n estring exit 0 void CALLBACK endCallback void glEnd void CALLBACK vertexCallback GLvoid vertex const GLdouble pointer glVertex3dv GLdouble vertex void CALLBACK combineCallback GLdouble coords 3 GLdouble vertex data 4 GLfloat weight 4 GLdouble dataOut GLdouble vertex int x 66 vertex GLdouble malloc 6 sizeof GLdouble vertex 0 coords 0 vertex 1 coords 1 vertex 2 coords 2 dataOut vertex void tesselate vector lt vector lt Point gt gt tessVector if glIsList objektList objektList glGenLists 1 GLUtesselator tobj tobj gluNewTess Defines the callback functions gluTessCallback tobj GLU_TESS VERTEX void CALLBACK vertexCallback gluTessCallback tobj GLU TESS BEGIN void CALLBACK beginCallback gluTessCallback tobj GLU TESS END void CALLBACK endCallback gluTessCallback tobj GLU TESS ERROR void CALLBACK errorCallback gluTessCallback tobj GLU TESS COMBINE void CALLBACK combineCallback vector lt GLdouble gt vertexVect
49. esent the reader with all relevant information regarding our work with developing a fast method for simulating the breaking of glass The algorithm and is described in detail followed by a discussion of the result The source code of the actual implementation is available as an appendix for the technically interested reader 1 1 BACKGROUND AND PURPOSE Even today when realistic physics and sophisticated 3D graphics are important parts of many popular com puter games there is no well known serious attempt to simulate the breaking of glass in real time Instead developers settle with static animations or predefined crack patterns which may appear acceptable in some applications but nevertheless are unrealistic and a sometimes disturbing element in an otherwise appealing game experience We wanted to try to develop a simple fast and reasonably correct physical simulation of crack pattern generation and loose piece detection in breaking glass The aim was for it to run in real time on a standard PC 1 2 SOURCES Even though there has been research done in the area of the fracturing of brittle materials we have found no publication where the underlying physics have been simplified in such a way that they can be used in real time applications Therefore we have based our algorithm on observations intuition and a short lecture on the basics of breaking of glass given by Amir Baranzahi at ITN Link ping University There are also some referen
50. ffer Input void Output void x void draw Draw the crack pattern Input allPoints the vector containing all points and their connections Output void xy void drawCracks vector lt Point gt allPoints Configure camera options Input w widht of window h height of window Output void xy void GLFWCALL reshape int w int h Check keyboard inputs arrow keys and w a s d Input key specifies a key action checks if the specified key is pressed or relesed Output void a void GLFWCALL keyPressed int key int action Deinitialize all graphical elements Input void Output void zy void deinitGraphics 39 crackStarter h Point h holes h and tesselate h to run Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This file is part of Splitter Splitter is free software you can redistribute it and or modify the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU Gene
51. file is part of Splitter Splitter is free software you can redistribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Splitter if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA HOO OH FF HF HF FF KF HF XX FF FF HF XX F HF XX F F F F HF FHF X SS include Point h include lt math h gt include lt iostream gt include lt vector gt using namespace std namespace splitter ifndef SPLITTER PI define SPLITTER PI const float PI 3 14159265 endif int Point numPoints 0 Point Point ID Point numPoints tt points new vector lt Point gt angles new vector lt float gt testFlags new vector lt bool gt endFlags new vector lt bool gt pathFlags new vector lt bool gt Point Point float x float y this gt x x this gt y y ID Point numPoints tt points new vector lt Point gt angles new vector lt float gt testFlags new vector lt bool gt endFlags new vector lt b
52. gle compAngle 180 0f relAngle 2 0f thisAngle compAngle starter getAngles at crack 180 0f thisAngle fmod thisAngle 360 0f 360 0f if thisAngle thisAngle 90 thisAngle 180 thisAngle 270 thisAngle 0 1f tempCos cos thisAngle PI 180 0f tempSin sin thisAngle PI 180 0f The length of the cross crack is initially set to 1 5 times the distance from the cross crack start point to the original impact point This guarantees the cross crack to always join with the neighbouring radial crack to the right length 1 5f starter gt getRadialDistance gt at crack gt at starter gt getRadialDistance gt at crack gt size 1 tempX 0 0f tempY H ll o o Fh for int p 0 p lt starter gt getRadialDistance gt at crack gt size ptt tempX length tempCos tempY length tempSin tempX impactPoints gt at crack gt at p gt getX tempY impactPoints gt at crack gt at p gt getY tempPoint new Point tempX tempY safeConnect impactPoints gt at crack gt at p tempPoint allPoints Now proceed by propagating cracks caused by bending stress from all the previously defined start points for int i 0 i lt bendStarts gt size i if starter gt getBendingEnergyVector gt at i 0 propagate bendStarts at i starter gt getAngles gt at i star
53. gt at crack 0 01 tempX tempDist crackCosAngle tempY tempDist crackSinAngle tempX starter gt getX tempY starter gt getY tempPoint new Point tempX tempY bendStarts push back tempPoint impactPoints gt at crack gt at pos gt connect tempPoint allPoints gt push_back tempPoint Temp variables used below float relAngle float compAngle float thisAngle float tempCos float tempSin float length Position all impact stress cross cracks These always start from the predecided points along the radial cracks and take off to the right until they join with the nearest radial crack for int crack 0 crack lt starter gt getAngles gt size crack Check if this radial crack has no cross cracks if so continue with the next crack if starter gt getRadialDistance gt at crack NULL continue Aquire index of the nearest radial crack clockwise orientation int prevCrack crack 0 starter gt getAngles gt size 1 crack 1 Relative angle between this radial crack and the one to the right relAngle starter gt getAngles gt at crack starter gt getAngles gt at prevCrack relAngle relAngle gt 0 relAngle 360 0f relAngle Only create the cross crack if the angle between the radial cracks is less than or equal to 90 degrees if relAngle lt 90 0f 25 Calculate cross crack global an
54. h directions angleVector gt push_back angleVector gt at i 180 Divides the energy to two differnt types of energy One that decides how mant circumferential crack there will be and one that decides for how long the crack will go on after them void CrackStarter energyGenerator vector lt float gt bendingEnergyVector vector lt float gt impactEnergyVector float totalBendingEnergy float totallmpactEnergy float relationEnergy crackEnergy BENDING INTERVAL CROSS INTERVAL if relationEnergy lt 0 totalBendingEnergy crackEnergy totallmpactEnergy 0 else if relationEnergy gt 0 amp amp relationEnergy lt 1 totallmpactEnergy crackEnergy relationEnergy totalBendingEnergy crackEnergy totallmpactEnergy else totallmpactEnergy crackEnergy totalBendingEnergy 0 float impactEnergyPerCrack totallmpactEnergy numberOfCracks float bendingEnergyPerCrack totalBendingEnergy numberOfCracks for int i 0 i lt numberOfCracks i if impactEnergyPerCrack gt 0 Randomize the impact energy a bit impactEnergyVector push back impactEnergyPerCrack fmod rand ENERGY DIFFER ENERGY DIFFER 2 else impactEnergyVector gt push back 0 if bendingEnergyPerCrack gt 0 Randomize the bending energy a bit float tempEnergy bendingEnergyPerCrack fmod rand ENERGY DIFFER ENERGY DIFFER 2 if tempEnergy lt 0 bendingEnerg
55. handle in real time while still preserving many of the visual character istics of the real world counterpart We think that our method produces crack patterns that looks better than any other real time attempt that we have seen including current computer games like Half Life 2 Our method for finding loose pieces is very fast and could probably be used in a real application If the method would be used in a computer game or some such some modifications would probably have to take place Even if the simulation can run in real time on its own there are many more things for the computer to handle when the glass breaking is not the main activity The step size could be reduced the collision detection method replaced and the code optimized in general Still we believe that the idea behind our model could be used to improve today s real time simulation of the breaking of glass REFERENCES Mencik Jaroslav 2002 Strength and fracture of glass and ceramics Elsevier Baranzahi Amir of ITN at Link ping University Personal conversation 2004 11 10 Askeland Donald R 1996 The Science and Engineering of Materials Thomson Learning 3rd edition Hiroto Tanoue Kaneko 1998 Generation of crack patterns with a physical model Lower Nathan Weibull Statistics www lt http web umr edu nplc4b Weibull html gt Verified 2004 12 18 Weeks Joseph 2004 How fast does a crack in a glass travel www http www madsci org posts archives 2
56. hange the crack resolution and computational burden by adjusting the crack segment length and hence the total number of points Second we had to decide how the data structure was to be implemented Since we defined cracks as a number of connected points the logical choice was to create a Point class and for each crack instantiate a number of Point objects Each Point contains information about its own coordinates together with a list of all connected Points and the respective angles of these connections The Point also has a couple of flags used in crack propagation loose piece identification and drawing functions The Point objects have to be stored somewhere where they are easily accessible from all aspects of the algorithm We decided to use a Vector for this purpose A C Vector provides access to a specified posi tion Point and appending of new Points in constant time Searching for a Point given certain properties or inserting a Point at another position than the end of the Vector takes linear time All in all it is a flexible list that fit our purposes To summarize the data representation of the crack pattern in our solution is a Vector of Points where the connections between the Points defining the actual cracks are stored in the Points themselves Angles between the connections are calculated one time only and stored in the Points in the same way These angles are used both for crack propagation and loose piece identificat
57. icant amount of bending stress This also means that the cracks that form become shorter Mencik 2002 That is why there can be small holes of sizes almost equal to the bullets when certain types of glass windows have been shot upon A glass that already has cracks or holes or other flaws in it will break on a much lighter impact The cracks will behave and propagate in an even less predictable way Askeland 1996 2 1 2 SIMPLIFICATIONS As mentioned above to really understand how glass shatters you need a lot of special knowledge If you want to implement this knowledge with a precise physical model you will have to do a lot of processing before you will see the result This kind of realistic simulation of objects cracking has been done before and included heavy pre animation computations Hiroto et al 1998 One of he things that we wanted to achieve with this project was a simulation that should run in real time This implied that we had to do a lot of simplifications while still preserving a graphically plausible result The simplifications made are based on the physics presented above as well as our own experience with breaking glass and crack patterns The first and perhaps most important simplification that we made was to restrict our simulation to a two dimensional surface This means that our model only takes into account cracks that form in the plane of the window pane which in turn is assumed to be thin Also since many of
58. ight Height of characters GLFONT Initialize and set up the graphical environment Input void Output void Ey void initGraphics int resWidth int resHeight Initialize the allPoints and cs objects and set the clickedAlready flag to false so that it is possible to create new cracks This removes all previous cracks Input void Output void x void resetCracks Initialize and set up the input dependent user interface Input void Output void Ey void initUIInput Calculate and report frames per second updated once per second in the window title bar Input void 37 Output void xy void showFPS Calculates the time since the last frame This is used to update the inputs from the keyboards Changes the variable frameTime Input void Output void zy void updateFrameTime Get the mouse position from the screen Input void Output void x void updateMousePos Uppdate horizontal movment xz plane and view direction Input void Output void ay void updateDirPos Gets the cooridinate of the point that is projected on the screen coordinates x y Input x screen x coordinate A y screen y coordinate Output void xy void getOGLPos int x int y GLfloat amp posX GLfloat amp posY GLfloat amp pos2 Uppdate the impact velocity applied from the user with the and nu
59. ion so the dark gray e point is regarded as finished and the next point is chosen as the new starting point The figure shows the example at this point All connections that have been used in both directions are colored light gray almost white 2 3 GRAPHICAL REPRESENTATION To visualize the simulation we used OpenGL to create a wall containing a window which in turn is a trans parent glass pane The glass pane is made out of only two triangles and is thus in itself only defined in two dimensions although it is truly positioned in a 3D environment We used alpha blending on the glass pane which is a technique that simulates transparency In addition to the three color channels for every pixel in the pane of glass a fourth transparency channel alpha is used This alpha channel is used by the frame buffer to blend the pane with the environment behind the glass Since the simulation is executed in two parts we decided to separate the visualization in two steps In the first part we draw the lines that represent the crack pattern The second part is to visualize any holes that might have formed in the crack pattern The two parts is executed separately each triggered by input from the user In the first part the lines representing the crack pattern is created by iterating through the Vector contain ing all Points and for every Point lines are drawn to connected Points A boolean flag is used to indicate if a connection already has bee
60. ion from the beginning but we decided to concentrate our efforts on other factors after we TI realized how complex the problem would get What if the user with the second strike hit a piece of glass that hung to the frame by a single tiny shred Intuition would call for the entire piece to fall off with the shred cracked if the strike was moderate If it was severe perhaps only part of the piece would break We found no good way to simplify this complex matter and we would rather skip it than produce an ugly solution Hence the limitation to one strike per window pane as described earlier The collision detection method used during the creation of the crack pattern is quite naive and slow when a small stepsize is used the current crack segment is checked for intersection with every other existing seg ment This could be improved for example by dividing the pane into several smaller regions and handling intersection tests separately within this regions as far as possible This would probably speed up the process but with this project we wanted to try the crack creation and loose piece identification methods not develop a sophisticated collision handling system This is why we went for the obvious solution On the good side we can conclude that our method produces quite realistic crack patterns in very little time which is what we aimed for We think that we have succeeded in simplifying a very complex problem into something a standard PC can
61. ion later on in the process 2 2 3 CRACK PROPAGATION Once all the starting conditions for the crack pattern have been calculated and the initial data representation has been initialized the algorithm proceeds with the actual generation of cracks This is done recursively one Point at a time which is why we chose to refer to it as crack propagation The propagation consists of two individual phases the first creates cracks due to impact stress and the second creates cracks caused by bending stress For a brief description of these phenomena see the section Physical foundation above The impact stress phase consist of positioning a Point at the impact coordinates which are read from mouse input in our application then drawing radial cracks with length determined by how much energy each of them has On these radial cracks at predefined distances to the impact point near perpendicular cracks are created joining with the closest other radial crack to the right clockwise orientation to form the spider web like pattern At the end of each radial crack in the spider web bending stress crack propaga tion is initiated if there is any bending energy in the crack calculated previously depending on the impact velocity The bending stress propagation is represented slightly differently depending on if the impact velocity was large enough to obtain any impact stress or not In the case where there are no impact stress the first poi
62. ircumferential cracks have formed due to impact stress important thing is that the breaking point should be able to vary according to the Weibull distribution and also become lower if you hit closer to the frame of the window We decided to let 10 m s be the velocity that would cause the glass to break if hit in the center on average At a velocity of 35 m s on average and above there would no longer be any cracks around the hole caused by bending stress We set a maximum at 40 m s just to be sure that about every possible instance of the glass window will have all its possible break ing patterns included The number does not really mean anything and has no real physical correctness it is just needed for the model to be able to show the different types of crack patterns that can arise from the breaking of a glass pane We could probably easily adjust this to be more correct if we had any facts to base this particular part of the simulation on The number of cracks will depend of how hard you hit the glass and the angles will be randomized so that they can propagate at almost any directions We have two rules when randomizing the angles The first rule is that the difference in angle between two neighboring radial cracks will not be below 12 degrees This number is dependent of the maximum number of radial cracks originating from the point of impact which we set to 30 More cracks or cracks closer to each other will not contribute in a positive way t
63. lPoints gt size i p allPoints gt at i For every point check all the connections for int connection 0 connection lt p gt getNumConnections connection I the connection is already visited the path is not availible go to next connection Also checks if it s a dead end if p gt getPath connection false amp amp p getEndFlag connection false polygonAngle 0 0f firstPoint p Indicate that the connection has been visited firstPoint gt setPath connection false thisPoint firstPoint gt getPoint connection thisAngle fmod firstPoint gt getAngles gt at connection 180 360 firstAngle firstPoint gt getAngles gt at connection prevPoint firstPoint holePoints gt push_back firstPoint Stays iside of while loop during caluculations of one hole while true Loop trough the connections to find the previous point because it s angle is in intress for int j 0 j lt thisPoint gt getNumConnections j if prevPoint thisPoint gt getPoint j SI pos j break Get the left most connection from which connection comming from Only allowed to use a connection that is not allready tried or is set to be a dead end for int k pos 1 k if kx O k thisPoint gt getNumConnections 1 if k pos checkedAll true break else if thisPoint gt getPath k amp amp
64. ls You should have received a copy of the GNU General Public License along with Splitter if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA HOO FF FF FF HF FF FF HF XX XX XX F KF F F F F F F F KF X SS include lt GL glfw h gt include Point h using namespace std namespace splitter Initialize all textures Input void Output void af void initTextures Draw the ceiling with a quad object and textures Input void Output void x void drawCeiling Draw the floor with a quad object and textures Input void Output void EJ void drawFloor Draw the surounding walls with a quad object and textures Input void Output void xy void drawWalls Draw the middle wall with a hole for the glass window Applying textures for the block object Input void Output void x void drawWindowFrame Create a display list containing drawCeiling drawFloor drawWalls and 59 drawWindowFrame Input void Output Index of the display list 27 GLuint initRoomDisplayList Draw the window with a quad object and textures Input holesVector a vector containing the point objects defining the 2d different holes created by the crack pattern Output void 27 void drawWindow vector lt vector lt Point gt gt holesVector Draw a block with size
65. m that finds dead ends correctly not marked as one and will therefore not be drawn in the second visualization step The same problem also occurs if there is a dead end inside a loose piece After the removal of the piece the crack is still drawn appearing to be hanging in the air If we give the tennis ball a velocity that maximizes the chance of getting this wrong result these bugs occur ap proximately 1 out of 30 times This could be fixed by implementing the loose piece identification algorithm in a smarter way Figure 5 The dead end problem In this figure the light line marked as 2 will not be drawn since it is not registered as a dead end and the dead ends are the only lines drawn after the holes are found This type of hole occur only when a crack splits because of an air bubbule The air bubble is indicated with a large black dot marked as 1 in the figure IO 3 THE RESULT The first step in our simulation whether or not the glass pane cracks is implemented in a more or less physi cally correct way even though we make use of simplifications Since we use a randomization function based on a discreet Weibull distribution this is also fast and could easily be adjusted to a different resolution Concerning the accuracy of the model we can see in the figures of appendix A that the generated crack patterns compares well to the real glass fracture in figure 2 of the report Our model has despite the sim plifications sho
66. mpad keys Input void Output void void updateImpactVelocity Calls function getOGLPos to check if pointing on the glass window Runs the function crackTester to se if the glass breaks Also runs createCrack to calculate the crackPattern Only possible to press the button on one side off the wall Input button the specified button asigned for the task action is the button pressed or released Output void zy void GLFWCALL updateCrackPattern int button int action Create a bitmap font Input hdc Device Context typeface Font specification height Font height size in pixels d weight Weight of font bold etc italic Text is italic Output GLFONT The font ay GLFONT fontCreate HDC hdc const char typeface int height int weight DWORD italic Delete the specified font Input font Font to delete Output void void fontDelete GLFONT font Display a string using the specified font 38 Input font Font to use s String to display Output void zy void fontPuts GLFONT font const char s Display a formatted string using the specified font Input font Font to use align Alignment to use format printf style format string i e text to print Other arguments as necessary Qutput void void fontPrintf GLFONT font int align char format Draw all the graphics to the bu
67. ms dont lie in straight lines but instead a bit random Due to this it s almost impossible to say exactly how a crack will propagate in the material you never know on which side of an atom a crack will go What you can say is that the crack likely will continue in the same direction as it started in Whether the glass will crack at all is dependent on how hard the impact is This can differ a lot from object to object even if they are of the same size shape and have the same frames There is a statistical dis tribution though the Weibull distribution that can give a hint as to what the probability of cracks forming would be for a given input stress Askeland 1996 Glass have a Weibull number of 5 8 Lower exact date unknown see figure 1 with low numbers implying a wider distribution steel has a Weibull number of about 40 A window will stand a harder impact in the middle of the glass than at the edges This is because at the edges the glass is fixed to a frame and therefore it cannot oscillate as freely as in the center thus absorbing less stress and breaking more easily Inside the glass there are tiny air bubbles that formed when the glass solidified during the creation pro cess When a crack comes to an air bubble its behavior is undefined it can change direction completely divide itself into several new cracks or perhaps stop completely This is because the crack will continue in the direction where the edges in the air
68. n drawn The lines are drawn independent of the glass pane but in the same plane This makes the lines to look as if they where a crack pattern in the glass pane The second part of the visualization is more complex then the first one OpenGL is designed for low level operations and can only render simple convex polygons that is for every line that connects to points on the boundary of the polygon the line is contained entirely inside the polygon Our glass containing holes must therefore be subdivided into simple convex polygons before they can be rendered This subdivision is called tessellation and the OpenGL Utility Library GLU provides functionality for doing the actual work The tessellation function requires that the coordinates of the points is in the same order as they appear in the path that make out the hole Since we automatically store the holes in the correct order when we use our hole detection algorithm this was straightforward to implement The tessellated object is stored so that the tessellation only needs to be performed once and can later be reused in subsequent frames Since the drawing of the crack patterns is independent of the tessellation of the cracked window we had to modify the drawing so that only the cracks not being a part of any hole are drawn while the loose pieces are still in the window The partial solution we came up with was to draw only the cracks that are dead ends in the pattern A crack segment
69. nit If one second has passed or if this is the very first frame if t t0 gt 1 0 frames 0 fps double frames t t0 sprintf titlestring World 1f FPS fps glfwSetWindowTitle titlestring t0 t frames 0 frames void updateFrameTime double t glfwGetTime frameTime float t tOld told t void updateMousePos int x yi glfwGetMousePos amp x amp y mouseOldX mouseX mouseX x mouseOldY mouseY mouseY y void updateDirPos float xFactor float yFactor mouseX mouse01dX mouseY mouse01dY if yFactor vAngle vAngle yFactor vAngle hAngle xFactor lt 80 0 amp amp yFactor vAngle gt 80 MOUSE SENSITIVITY MOUSE SENSITIVITY 0 I if hAngle gt 360 0 hAngle 360 0 if hAngle lt 0 0 hAngle 360 0 hAngle if pos 0 lt 13 amp amp pos 0 gt 13 amp amp pos 2 gt 13 amp amp pos 2 lt 13 if pos 0 lt 11 amp amp pos 0 gt 11 amp amp pos 2 gt 2 amp amp pos 2 lt 2 Inside the brick wall not allowed to walk if pos 2 gt 0 pos 2 2 else if pos 2 lt 0 pos 2 2 else if upPressed pos 0 frameTime WALKING SPEED sin DEG2RAD hAngle pos 2 frameTime WALKING SPEED cos DEG2RAD hAngle if downPressed pos 0 frameTime WALKING SPEED sin DEG2R
70. nt Input p Point object to add to this point Output void void addPoint Point p float angle bool testFlag bool endFlag bool pathFlag Helper method for disconnect Removes the point p from this point If p is not connected to this point nothing happens Input p Point object to remove from this point Output void void removePoint Point p vector lt Point gt getPoints return points vector lt float gt getAngles return angles Returns the connected Point object at position pos Input pos The position of the Point object of interest Output The connected Point object at the specified position ka If there is no point at position pos NULL is returned Li This only happens if pos is larger than id number of points 1 Point getPoint short pos static int numPoints The total number of existing Point objects private float x float y int ID vector lt Point gt points vector lt float gt angles vector lt bool gt testFlags vector lt bool gt endFlags vector lt bool gt pathFlags supplied point and this point are not connected nothing happens 55 Point cpp Data represenation class for the crack line segment end points Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This
71. nts of the crack is positioned out randomly around the impact point the only condition is that the angle between two of the starting crack segments is greater than twelve degrees a limitation set for viewing purpose From here on the continuing process is equivalent no matter if there is impact stress or not In the last created points an angle is calculated which may deviate from the incoming angle to this Point by only a little Then a new Point is created a certain step size away from the current Point in the direction of the calculated angle Depending on the size of the step the bending energy is decremented Collision detection is preformed to make sure that the crack does not cross any other crack in the pattern If so the cracks are joined with appropriate adjustments to the data structure which may result in loose pieces making the pattern more realistic and interesting The mentioned collision detection is really a quite simple line line intersection test where the proposed new segment is tested against all existing segments This is a slow but straightforward approach In every step there is a slight possibility that the crack has entered an air bubble This is represented with a random function which may split the crack into maximum two new cracks propagating away independently of each other Since the structure of an air bubble is impossible to predict the new cracks may propagate in any direction except for the incoming dir
72. o the visible pattern but just make the computations more cumbersome The second rule is that all radial cracks will al ways have another crack that is directly opposite in direction to the first one For example if the simulation has decided that there should be a radial crack pointing out from the impact point at an angle of 30 degrees this implies that there will be a second crack at an angle of 30 180 210 degrees We also decided to make the radial cracks that are connected to the circumferential cracks completely straight That is not completely realistic but we thought it reasonable The main reason for this simplifica tion as for many others was to reduce the calculations needed We did an assumption that the first circum ferential crack will always form at a distance from the impact point that depends on how hard the impact was and after that the distances between subsequential circumferential cracks would get shorter and shorter before they would stop forming completely Also this seemed a reasonable assumption to make If you hit with an impact velocity just over the breaking point there will be no circumferential cracks at all The model does not create the circumferential cracks in the same distance on every radial crack the distances can differ a bit This makes it look more like real crack patterns After the forming of the circumferential cracks has ceased the radial cracks are able to change direction slightly as they propagate
73. of the crack pattern belonging to a glass pieces made by the crack pattern Needs to include holes h and Point h Executed from graphics cpp Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This file is part of Splitter Splitter is free software you can redistribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Splitter if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA HOO FF XO XX XX HF HF HF HF HF HF HF FF FF FF F F XX XX F HF XA X include lt vector gt include Point h include holes h include lt cmath gt using namespace std namespace splitter void findDeadEnds vector lt Point gt deadEnds vector lt Point gt allPoints int id 1 Point p int counter 0 int notDeadEnd 0 Check if there are any dead ends if deadEnds gt size 0 Loop
74. of the points for changes to take effect on both Input i the position of the intersection test flag to alter value the new value of the test flag Output void I void setTestFlag short i bool value 53 Sets the dead end flag at position i to the specified value Note that the flag is shared between the two connected points so this method only has to be run on one of the points for changes to take effect on both Input i the position of the dead end flag to alter value the new value of dead end flag Output void void setEndFlag short i bool value X This metod is only used from the findHoles metod Sets the Path flag at position i to the specified value The path is available to use once from both directions wich meens that every point has its own flag for everey connection If the value is TRUE the path is available to use else FALSE the path is closed Input i the position of the flag to alter value the new value of the flag Output void void setPath short i bool value const float getX return x const float getY return y Returns the specified intersection test flag Input i the position of the test flag of interest Output TRUE if the crack section at position i has been tested before FALSE otherwise FALSE is also returned if there is no flag at position i This happens only if i i
75. ool gt pathFlags new vector lt bool gt void Point connect Point p Calculate the angle between this and p float tempAngle 0 0f tempAngle 180 0f PI atan2 p gt getY getY p gt getX getX Make sure tempAngle is in the interval 0 360 tempAngle fmod tempAngle 360 0f 360 0f bool tempBool new bool tempBool false bool tempEnd new bool tempEnd false bool tempPath true Store the connection in the two points addPoint p tempAngle tempBool tempEnd tempPath p gt addPoint this fmod tempAngle 180 0f 360 0f tempBool tempEnd tempPath void Point addPoint Point p float angle bool testFlag bool endFlag bool pathFlag Find the correct position for the new value int insertPos 0 for insertPos lt angles gt size amp amp angles gt at insertPos lt angle insertPos Push the rest of the angles points and flags down a click if angles gt size gt 0 angles gt push_back angles gt at angles gt size 1 points gt push_back points gt at points gt size 1 testFlags gt push_back testFlags gt at testFlags gt size 1 endFlags gt push_back endFlags gt at endFlags gt size 1 pathFlags gt push_back pathFlags gt at pathFlags gt size 1 for int i angles gt size 2 i gt insertPos i angles gt at i angles gt at i 1 points gt at i poin
76. or new vector lt GLdouble gt Stores the window corners in the GLdouble array since that is required by gluTexVertex GLdouble vertexList new GLdouble 4 vertexList 0 new GLdouble 3 vertexList 0 0 3 5 vertexList 0 1 8 5 vertexList 0 2 0 0 vertexList 1 new GLdouble 3 vertexList 1 3 5 vertexList 1 8 5 vertexList 1 2 0 0 vertexList 2 new GLdouble 3 vertexList 2 0 3 5 vertexList 2 1 5 vertexList 2 2 0 0 vertexList 3 new GLdouble 3 vertexList 3 0 3 5 vertexList 3 1 5 vertexList 3 2 0 0 vertexVector push back vertexList Stores all the holes in GLdouble arrays for int i 0 i lt tessVector gt size i Creates a double array with the same number of rows as the size of the tessVector GLdouble vertexList new GLdouble tessVector gt at i gt size for int j 0 j lt tessVector gt at i gt size j I vertexList j new GLdouble 3 vertexList j 0 tessVector gt at i gt at j gt getX vertexList j 1 tessVector gt at i gt at j gt getY vertexList j 2 0 0 vertexVector gt push_back vertexList glNewList objektList GL COMPILE AND EXECUTE gluTessBeginPolygon tobj NULL Using positive rule so since the holes is sorted in counter clockwise order The glass is defined clockwise gluTessProperty tobj GLU_TESS WINDING
77. rack circumferential cracks at given distances Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This file is part of Splitter Splitter is free software you can redistribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Splitter if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA ifndef SPLITTER CRACKSTARTER define SPLITTER CRACKSTARTER include lt vector gt using namespace std namespace splitter class CrackStarter public CrackStarter Initialize the CrackStarter that calls other functions that calculates the crack properties The input parameters are stored globaly Input hitsize The amount of energy added to the glas placeX placeY The coordinates of the impact CornerOneX CornerOneY CornertTwoX CornerTwoY The 2d coordinates of two diagonal corners Output
78. ral Public License along with Splitter if not write to the Free Software e Ft FF FF HF HF HF HF HF KF HF HF HF HF XX XX XX XX XX F XA XX F F HF X include lt windows h gt include lt GL glfw h gt include lt math h gt include lt iostream gt include lt vector gt include room h include graphics h include crackCreation h include CrackStarter h include Point h include holes h include tesselate h using namespace std namespace splitter Point related CrackStarter cs vector lt Point gt allPoints vector lt Point gt deadEnds vector lt vector lt Point gt gt holes Checks if the left resp the right mouse button has been pressed bool mlClickedAlready false bool mrClickedAlready false Define camera position float pos 0 0 6 0 6 0 Constants Moving parameters const float MOUSE SENSITIVITY 0 1f const float WALKING SPEED 10 0f Convertion degrees to radians const float DEG2RAD 3 14159265 180 0 Window size it under the terms of the GNU General Public License as published by Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 graphics cpp File to handle all graphical parts except for the tesselation of the glass polygon done in tesselate cpp graphics cpp is executed from splitter cpp and needs to include graphics h room h carackCreation h USA 40 int WIDTH 1024 int HEI
79. revious one u FALSE if no intersection or intersection but further away than a previous one 27 bool findNewIntersection Point pointl Point point2 Point thisPoint Point newPoint float oldbist Connects a point to another one If the connection between these points is crossing previously made connections appropriate actions are taken Input thisPoint the point in question where a connection is to m occur newPoint the second proposed point for the connection wanted m allPoint a vector including all existing points and their connections Output bool True if there is a collision between the expected connection and any other existing connection False if no collision accured x thisPoint will be connected to another point in any case 27 bool safeConnect Point thisPoint Point newPoint 18 vector lt Point gt allPoints Propagates a crack until its energy is zero or the crack collides with another already existing crack Input thispoint point from where the crack segment are to be generated prevAngle the global angle on the previous crack segment bendEnergy how much bending energy left in the crack allPoints vector that includes all the different points and the internal connections deadEnds vector that includes all the end points in the crackpattern and their connections Output void 27 void propagate Point thisPoint
80. rtTwoX CornerTwoY The coordinates of two diagonal corners Output float float realBreakLimit float breakLimit float placeX float placeY float cornerOneX float cornerOneY float cornerTwoX float cornerTwo Calculates the number of cracks considering the hitsize and the real breaklimit The number of cracks is stored in the global variable numberOfCracks Zero cracks means that the glas didn t break Input hitsize The amount of energy added to the glas actualBreakLimit The breaklimit for the glas Qutput void void crackGenerator float hitsize float actualBreakLimit Calculates the angles for the different cracks The angle between two cracks is at least 12 degrees When one angle is calculated another cracks gets this angle 180 degrees to create an oposing crack Input angleVector The vector that will contain the angles Output void Kf void angleGenerator vector lt float gt angleVector Creates an energy for each crack Uses some randomisation The energy is divided into two different energies bending energy and impact energy Input bendingEnergyVector The vector that the bending energy is i stored in impactEnergyVector The vector that the impact energy is 2 stored in Output void void energyGenerator vector lt float gt bendingEnergyVector vector lt float gt impactEnergyVector Creates a
81. s larger than number of points 1 const bool getTestFlag short i Returns the specified dead end flag Input i the position of the dead end flag of interest Output TRUE if the connection belongs to a dead end FALSE otherwise const bool getEndFlag short i Returns the specified path flag Input i the position of the path flag of interest Output TRUE if the flag is available to use FALSE if the connection is visited once before from i the same direction const bool getPath short i Returns the point s unique ID Input void Output The point s ID Kj const int getID return ID Retrieves the number of points connected to this point Input void Output The number of neighbouring connected points const short getNumConnections return angles gt size Connects this point with the supplied point The connection is performed on both points This method uses the addPoint method of both points 54 endif Input p Point object to connect to this point Output void y void connect Point p Disconnects the supplied point from this point and vice versa This method uses the removePoint method of both points If the Input p Point object to disconnect from this point Output void void disconnect Point p XX X Helper method for connect Adds the point p to this poi
82. se return false void Point setTestFlag short i bool value if i lt testFlags gt size testFlags gt at i value const bool Point getTestFlag short i if i lt testFlags gt size return testFlags at i else return false void Point setPath short i bool value if i lt pathFlags gt size pathFlags gt at i value const bool Point getPath short i if i lt pathFlags gt size return pathFlags gt at i else return false Point Point getPoint short pos if pos lt points gt size return points gt at pos else return NULL 58 room h File to create all primitives needed in graphics h Needs to include Point h to run Is included in graphics cpp Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This file is part of Splitter Splitter is free software you can redistribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more detai
83. stribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Splitter if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA HOO FF FF FF FF FF KF HF XX XX XX XX HF F XX F HF HF HF SS include lt vector gt include lt GL glfw h gt include Point h using namespace std using namespace splitter Resets the objektlist containing the tesselated window void resetTessList Tessellates the window with holes into renderable polygons A display list is used since the holes only needs to be tesselated once Input tessVector A pointer to a vector with holes each hole is d pointer to another vector containing the points that is the hole E The points is sorted counter clockwise Output void void tesselate vector lt vector lt Point gt gt tessVector Callback functions that is run at appropiate times during the tessellation void CALLBACK beginCallback GLenum which void CALLBACK errorC
84. t den x1l y3 xl y4 x2 y3 x2 y4 x3 yl x4 yl x3 y2 x4 y2 float xnum x1 x3 y2 x1 x4 y2 x2 x3 yl x2 x4 yl x1 x3 y4 Xl x4 y3tx2 x3 y4 x2 x4 y3 float ynum x1 y2 y3 x1 y2 y4 x2 yl y3 x2 yl y4 x3 yl y4 x4 yl y3 x3 y2 y4 x4 y2 y3 bool intersection true if den 0 intersection false else float x xnum den float y ynum den Check if intersection lies between the given points on the lines if x gt xl amp amp x gt x2 x lt xl amp amp x lt x2 x gt x3 amp amp x gt x4 x lt x3 amp amp x lt x4 y gt yl amp amp y gt y2 HI HI feil yi y lt yl amp amp y lt y2 I y gt y3 amp amp y gt y4 I y lt y3 amp amp y lt y4 intersection false else Check if this intersection lies closer to the start point of the proposed new line than a previously found one If so this is the intersection to remember If not it is discarded float testDist abs x3 x abs y3 y if testDist oldDist oldDist 0 newPoint gt setX x newPoint gt setY y oldDist testDist else intersection false return intersection bool safeConnect Point thisPoint Point newPoint vector lt Point gt allPoints Point pl NULL Point p2 NULL float tempDist 0 bool collision false Marks the connections belonging to the point being checked for int i 0 i lt thisPoint
85. ter gt getBendingEnergyVector gt at i allPoints deadEnds else Temp variables used below float startCosAngle float startSinAngle float tempStartX float tempStartY Point tempStart Create start points for bending stress cracks vector lt Point gt bendStarts new vector lt Point gt for int i 0 i lt starter gt getAngles gt size i if starter gt getBendingEnergyVector gt at i 0 startCosAngle cos starter gt getAngles gt at i PI 180 0f startSinAngle sin starter gt getAngles gt at i PI 180 0f tempStartX STEPSIZE startCosAngle tempStartY STEPSIZE startSinAngle tempStartX starter gt getX 26 tempStartY starter gt getY tempStart new Point tempStartX tempStartY startPoint gt connect tempStart bendStarts gt push_back tempStart allPoints gt push_back tempStart Propagate cracks caused by bending stress with start point in the impact point because of no impact stress radial cross cracks for int i 0 i lt starter gt getAngles gt size i propagate bendStarts at i starter gt getAngles gt at i starter gt getBendingEnergyVector gt at i allPoints deadEnds 27 TH CrackStarter h This is a class that contains functions that test if there will be any cracks if so how many and to what direction they will propagate It also have functions that give each c
86. that count the break limit of this glass according to the Weibull distribution see Physical Founda tion above After that the program includes the spot where the glass was hit in the calculation and decide if the glass will break see Simplifications above If the glass did not break no further calculations will be car ried out Otherwise the program continues with calculations of how many cracks that will form together with their directions see Simplifications above Depending on the magnitude of the impact velocity the program will then decide if any circumferential cracks should form If that is the case their distance to the impact point are calculated This is done a bit random the distance is decided and then a random number is added to it 2 2 2 DATA STRUCTURE FOR REPRESENTING CRACKS To represent the generated cracks some kind of efficient data structure is required When the simulation is to be run in real time it is important that this structure can provide fast access to its data in all steps of the algorithm from collision detection line line intersection check to traversal for drawing purposes First of all we needed a representation for the actual cracks It was decided that a crack is made out of a number of segments where each segment consists of two connected points in the plane of the glass window pane This representation was chosen because of its simplicity ease of implementation and flexibility it is easy to c
87. thisPoint gt getEndFlag k false nextPoint thisPoint gt getPoint k nextAngle thisPoint gt getAngles gt at k thisPoint gt setPath k false break If all of the connections is already visited break the while loop if checkedAll checkedAll false break Sum the inner angles of the polygon polygonAngle fmod 360 thisAngle nextAngle 360 0f Save the point and go to the next one holePoints push back thisPoint prevPoint thisPoint thisAngle fmod nextAngle 180 0f 360 0f thisPoint nextPoint If the hole is completed if thisPoint firstPoint polygonAngle fmod 360 thisAngle firstAngle 360 0f break Check if the polygon was circumfered counter clockwise must be a bit wider limit because of some faults in calculation with many decimals if pol pol ygonAngle gt 179 9 holePoints gt size 2 amp amp ygonAngle lt 180 1 holePoints gt size 2 les gt push back holePoints lePoints new vector lt Point gt lePoints gt clear 52 HO FF FF FF HF XX XX FF F HF XX XX F F F F F F HF FH X SS fi Point h Data represenation class for the crack line segment end points Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This file is part of Splitter Splitter is
88. ts gt at i 1 testFlags gt at i testFlags gt at i 1 endFlags gt at i endFlags at i 1 pathFlags gt at i pathFlags gt at i 1 Insert the new angle point flags angles gt at insertPos angle points gt at insertPos p testFlags gt at insertPos testFlag endFlags gt at insertPos endFlag pathFlags gt at insertPos pathFlag else angles gt push_back angle points push back p testFlags gt push back testFlag endFlags gt push back endFlag pathFlags push back pathFlag void Point disconnect Point p removePoint p p gt removePoint this void Point removePoint Point p for int i 0 i lt points gt size i if points gt at i p Remove p from this together with angle and flag Shift the rest of the points angles flags down properly if i lt points gt size 1 for int j i J lt points gt size l j I points gt at j points gt at j 1 angles gt at j angles gt at j 1 testFlags gt at j testFlags gt at j 1 endFlags gt at j endFlags gt at j 1 points gt pop back angles gt pop back testFlags gt pop back endFlags gt pop back break void Point setEndFlag short i bool value if i lt endFlags gt size endFlags gt at i value const bool Point getEndFlag short i if i lt endFlags gt size return endFlags gt at i el
89. version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Splitter if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA HOO HO XO XO XO XX XX 00 XX XX XX XX XX XX XX F F SE HF X using namespace std namespace splitter Finds the part of the crack pattern that has propagated further after a hole or the hole crack pattern if there are no found holes Saves the found dead ends in the deadEnds vector Input deadEnds a vector containing the end points of all created cracks An end point is defined as A point where the bending energy is zero Output void a void findDeadEnds vector lt Point gt deadEnds vector lt Point gt allPoints Finds the smallest pieces in a crack pattern wich is all the holes not containing any other holes Saves the points defining the holes in the holes vector Input holes an empty vector to store the vectors fore the holes in allPoints vector containing all the points in the crack A pattern Output void Ey void findHoles vector lt vector lt Point gt gt holes vector lt Point gt allPoints 49 holes cpp File to find all the parts
90. void 7 void crackTester float hitSize float placeX float placeY float CornerOneX float CornerOneY float CornerTwoX float CornerTwoY Returns the bending energy Input void Output vector lt float gt si vector lt float gt getBendingEnergyVector Returns a vector containing the different cracks and their distances to the hitpoint Input void Output vector lt vector lt float gt gt Returns a pointer to a vector u containing pointers to other vectors Kl vector lt vector lt float gt gt getRadialDistance Returns the vector that contains the crack angle for the different 28 cracks Input void Qutput vector lt float gt Returns a pointer to a vector Bi vector lt float gt getAngles Returns the vector with the difference between the last radial cracks Input void Output float Kf vector lt float gt getSafeDistance Returns the coordinates for the impact X and Y respectively Input void Output float Kf float getX float getY private Using a Weibull function to calculate the crack limit for the glas Input void Output float Kf float configureBreakLimit Calculates and returns the real breaklimit for the glas considering the position of the impact Input hitsize The amount of energy added to the glas placeX placeY The coordinates of the impact CornerOneX CornerOneY Corne
91. wn that it gives acceptable to good results for most impact velocities It is hard for us to evaluate the results for extremely high velocity impacts since this is a rare phenomena in the real world Screenshots from the simulations taken at different velocities can be found in appendix A Even though we use a simple linear model for the distribution of energy between bending stress and impact stress the results are good With a higher knowledge of the complex physics involved the model could quite easily be altered to simulate the reality in a better way A lot of effort was put into the algorithm that finds the loose pieces It has been tested numerous times with complex crack patterns and it works good as expected The data structure we came up with largely made this possible In the loose piece identification algorithm all the possible glass pieces are marked as if they will fall out of the glass pane This is not always the case in a real situation where some pieces may still be in place even though they are surrounded by cracks Our model does not take this into account but since the pieces are identified and stored an extension of the program could model this behavior as well as pieces falling off the pane One of the most important goals was to make the whole simulation run in real time which succeeded in the sense that a high end PC with a decent graphics card can do it For recommended system requirements see appendix B When the velocity
92. yVector gt push back 0 else bendingEnergyVector push back tempEnergy else bendingEnergyVector gt push back 0 Creates the circumferential cracks distance to the impact point void CrackStarter radialCrackGenerator vector lt vector lt float gt gt amp radialCrackVector vector lt float gt amp safeDistance float minLast 0 34 float maxLast 0 int zeroRadials 0 vector lt float gt radialVector for int i 0 i lt numberOfCracks i if impactEnergyVector gt at i lt 0 0f if there is no energy radialCrackVector gt push_back NULL there will be no cracks zeroRadials else float radialEnergy impactEnergyVector gt at i RADIAL FACTOR int numberOfRadials int radialEnergy if numberOfRadials gt MAX RADIALS numberOfRadials MAX RADIALS float firstDistance DISTANCE FACTOR radialEnergy if firstDistance gt 2 5 firstDistance 2 5 radialVector new vector lt float gt if numberOfRadials gt 0 radialVector gt push back firstDistance if numberOfRadials gt 1 for int j 1 j lt numberOfRadials j radialVector gt push back radialVector gt at j 1 firstDistance pow 2 0 double j else radialVector NULL zeroRadials radialCrackVector gt push back radialVector if zeroRadials numberOfCracks radialCrackVector NULL else float thisLast float next
93. ze radialCrackVector gt at 0 gt size 36 graphics h File to handle all graphical parts except for the tesselation of the glass polygon done in tesselate cpp graphics h is included in splitter cpp and needs point h to run Authors Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg Copyright 2004 Jesper Carlsson Daniel Enetoft Anders Fjeldstad Kristofer G rdeborg This file is part of Splitter Splitter is free software you can redistribute it and or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License or at your option any later version Splitter is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Splitter if not write to the Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA EE XO XO XX XX XX XX XXX XX XX XX XX F F F F SE SE include lt windows h gt include lt GL glfw h gt include Point h using namespace std namespace splitter Data types for the bitmap fonts typedef struct GLuint base Display list number of first character int widths 256 Width of each character in pixels int he
Download Pdf Manuals
Related Search
Related Contents
T E L E F O N I A Osram LIGHTIFY Surface Light W 28 Rexel Document Folder - Premium Qual StarTech.com 15m Coax High Resolution Monitor VGA Video Extension Cable - HD15 M/F DMP-HV100/HV50 (5.87 MB/PDF) Taylor 522 User's Manual Samsung E848i 用户手册 Copyright © All rights reserved.
Failed to retrieve file