Party poker bonus Cheap fioricet Buy ultram Cheap viagra Football pool Nfl football predictions Nfl handicapping Nfl pool pick Ambien Betting Ultram online Tramadol cod Xanax online Viagra cialis Order phentermine Adalat Buy phentermine online Casino online gambling Buy online viagra Buying viagra online Purchase phentermine Debt consolidation program Propecia online Credit card debt help Generic nexium Online casino gambling site Wellbutrin sr Buy nolvadex Casino bonus Debt negotiation Allstate car insurance Amoxicillin rash Nolvadex Consolidate credit card Allegra Levaquin Pharmacies Cosmetologist Child care Get fioricet Caverta Adipex phentermine Auto insurances Rivotril Cheap hotel Ritalin Free porn Job Flowers Limewire Lortab Sex video County Youporn Service Forex broker Travelocity Buy adipex p Adware Ultram online from dreampharmaceuticals 


Physics in Papervision

Hi Everyone!

Today I've been experimenting with Verlet physics, and using Papervision to render the results. Here's what I've come up with:

It's a little bit buggy, but pretty good for a quick papervision project!

I had to modify the DisplayObject3D class a bit, It's a tiny modification which just allows you to store an acceleration and "previous position" in any object. I added the variables because it was the easiest and quickest way to store this information.. And my physics formula needs them.

If you want to play with it, you'll have to download my modified DisplayObject3D class by clicking here

Just replace your current file (located in Greatwhite/src/org/papervision3d/objects) with my one. It won't affect the performance or anything on projects which also use this class (I've only added two or three lines).

Here is the code (Uses the base class and modified DisplayObject3D):

Actionscript:
  1. package  {
  2.    
  3.     import flash.display.StageQuality;
  4.     import org.papervision3d.core.geom.renderables.Vertex3D;
  5.     import org.papervision3d.lights.PointLight3D;
  6.     import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
  7.     import org.papervision3d.materials.shadematerials.PhongMaterial;
  8.     import org.papervision3d.objects.DisplayObject3D;
  9.     import org.papervision3d.objects.primitives.Plane;
  10.     import org.papervision3d.objects.primitives.Sphere;
  11.  
  12.     public class Main extends PaperBase {
  13.        
  14.         public var light:PointLight3D = new PointLight3D(true);
  15.         public var physBox:DisplayObject3D = new DisplayObject3D(); //We'll keep all of the physical objects in here..
  16.         public var sidemat:FlatShadeMaterial = new FlatShadeMaterial(light, 0xBBBBBB, 0x000000);
  17.         public var floor:Plane = new Plane(sidemat, 1100, 1100, 10, 10);
  18.        
  19.         public function Main() {
  20.             stage.quality = StageQuality.LOW; //Set the stage quality to low (for speed)
  21.             init();
  22.         }
  23.        
  24.         override protected function init3d():void {
  25.             //Position the floor
  26.             floor.y = -100;
  27.             floor.pitch(90);
  28.             default_scene.addChild(floor);
  29.            
  30.             //Position the camera
  31.             default_camera.y = 300;
  32.             default_camera.z = 1500;
  33.             default_camera.lookAt(floor);
  34.            
  35.             //Position the light
  36.             light.x = 0;
  37.             light.y = 300;
  38.             light.z = 500;
  39.            
  40.             //Create 10 Spheres, and put them in our Physics Box (Anything you add to physbox will be simulated, only spheres look right)
  41.             for (var x:Number = 0; x <10; x++) {
  42.                 var sph:Sphere = new Sphere(new PhongMaterial(light, 0xBBBBBB, Math.round(Math.random() * 10000), 20), 100, 10, 8);
  43.                 sph.x = (Math.random() * 40) - 20; // Position it slightly randomly
  44.                 sph.z = (Math.random() * 40) - 20;
  45.                 sph.y = (300 * x); // Put it 300 px above the previous one
  46.                 sph.PreviousPosition = new Vertex3D(sph.x, sph.y, sph.z); // This stops the verlet from going crazy
  47.                 physBox.addChild(sph); // Add it to the physbox
  48.             }
  49.             default_scene.addChild(physBox); // Add the physbox to the scene
  50.         }
  51.        
  52.         override protected function processFrame():void {
  53.        
  54.             default_camera.moveLeft(20); //This will rotate our camera around the scene,
  55.             default_camera.lookAt(floor);//whilst keeping it looking at the middle.
  56.            
  57.             for (var item:String in physBox.children) { // This loop is run for every sphere in our physBox.
  58.                 var citem:DisplayObject3D = physBox.getChildByName(item); // Get the sphere.
  59.                 var lastposTmp:Vertex3D = getPos(citem); // Temporarily store it's position.
  60.                 // This line of code is known as "Verlet". Wikipedia it for more info.
  61.                 setPos(citem, vertexAdd(getPos(citem), vertexAdd(vertexSubtract(lastposTmp, citem.PreviousPosition), citem.Acceleration)));
  62.                 citem.PreviousPosition = lastposTmp; // Update the previous position..
  63.                 citem.Acceleration = new Vertex3D(0, -8.3, 0); // Apply Gravity
  64.                 constrain(citem); // This code checks if the sphere has collided with the environment.
  65.                
  66.                 for (var item2:String in physBox.children) { //Check to see if it's hit any other spheres.
  67.                     if (item != item2) {
  68.                         var pitem:DisplayObject3D = physBox.getChildByName(item2);
  69.                         dohittest(pitem, citem); // Check
  70.                     }
  71.                 }
  72.             }
  73.         }
  74.        
  75.         private function dohittest(o1:DisplayObject3D, o2:DisplayObject3D):void {
  76.             if (o1.hitTestObject(o2)) { // IF the two objects have collided, then
  77.                 var xmag:Number = (o1.x - o2.x)/2.1; // Get the distance
  78.                 var ymag:Number = (o1.y - o2.y)/2.1;
  79.                 var zmag:Number = (o1.z - o2.z)/2.1;
  80.                 // Move the objects away from eachother
  81.                 setPos(o1, vertexAdd(new Vertex3D(xmag, ymag, zmag), getPos(o1)));
  82.                 setPos(o2, vertexSubtract(getPos(o2),new Vertex3D(xmag, ymag, zmag)));
  83.             }
  84.         }
  85.        
  86.         private function constrain(obj:DisplayObject3D):void {
  87.             if (obj.x <500 && obj.x> -500 && obj.z <500 && obj.z> -500){ // If the object is over the floor
  88.                 if (obj.y <0) { // If it's hit the floor
  89.                     // Move it out of the floor.
  90.                     if((obj.y - obj.PreviousPosition.y) <-10){
  91.                         obj.y = (obj.PreviousPosition.y * 1.2);
  92.                         if (obj.y <0) {
  93.                             obj.y = 0;
  94.                         }
  95.                     }else {
  96.                         obj.y = 0;
  97.                     }
  98.                 }
  99.             }
  100.             // If the object is way off the screen, put it back at the top.
  101.             if (obj.y <-10000) {
  102.                 obj.y = 300 + (Math.random() * 5000);
  103.                 obj.x = (Math.random() * 20) - 40;
  104.                 obj.z = (Math.random() * 20) - 40;
  105.                 obj.PreviousPosition = new Vertex3D(obj.x, obj.y, obj.z);
  106.             }
  107.         }
  108.        
  109.         // --- These functions are used to do general addition and stuff ---
  110.        
  111.         private function vertexSubtract(v1:Vertex3D, v2:Vertex3D):Vertex3D {
  112.             return new Vertex3D(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
  113.         }
  114.        
  115.         private function vertexAdd(v1:Vertex3D, v2:Vertex3D):Vertex3D {
  116.             return new Vertex3D(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
  117.         }
  118.        
  119.         private function getPos(object:DisplayObject3D):Vertex3D {
  120.             return new Vertex3D(object.x, object.y, object.z);
  121.         }
  122.        
  123.         private function setPos(object:DisplayObject3D, point:Vertex3D):void {
  124.             object.x = point.x;
  125.             object.y = point.y;
  126.             object.z = point.z;
  127.         }
  128.         // --- ---
  129.     }   
  130. }

I hope it's commented enough :D

Have fun!

16 Responses to “Physics in Papervision”


Leave a Reply


Tell a Friend

RSS Feed

adipex p phentermine vs Phentermine Web Page purchase phentermine online using mastercard! No prescription needed adipex phentermine no processing fees 995. Diet Page Phentermine Pill Yellow diet ingredient phentermine pill phentermine ssri Cheap Fastin "generic adipex no prescription" "generic adipex no prescription" Buy Phentermine Fedex Overnight diet no phentermine pill prescription phentermine 37.5 mg tablets No Prescription Adipex P
no rx adipex? phentermine mexico Buy Phentermine Us Pharmacy phentermine wordwide shipping online cheapest adipex contraindications Canada Online Prescriptions Adipex phentermine 180 count buy duromine online Order Phentermine From Middle East Pharmacy phentermine on sale picture of phentermine Phentermine Order No Prescription International Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. phentermine online consultation order Adipex Dangers phentermine cheep is adipex safe Phentermine Online No Credit Card phentermine heart murmur generic for ionamin Phentermine Tolerance phentermine hcl prescription diet pills information break phentermine Phentermine Online Ordering adipex p? online prescription for phentermine? Shelf Life Of Phentermine 37.5mg adipex pharmacy phentermine Duromine Pharmacy buy fastin in florida? phentermine cod us only Bulk Order Of Phentermine phentermine 37.5 without a prescription does bontril work better than adipex Phentermine Cheap Online Pharmacy Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. adipex same day shipping Cheap Adipex Without A Prescription phentermine 37.5 mgs search viagra edinburgh phentermine find Online Pharmacies Selling Phentermine cheap phentermine guaranteed best prices lowest cost phentermine overnight delivery Phentermine Obesity order phentermine pills "phentermine 6 pm order" Cheap Adipex Online

overseas phentermine,

purchase adipex from pharmacies usa? Phentermine 15 Mg phentermine for weight loss No prescription needed adipex phentermine no processing fees 995. Phentermine Capsules diet ingredient phentermine pill phentermine with no rx Yellow Adipex "generic adipex no prescription" "generic adipex no prescription" Order Phentermine Online Without Prescription diet no phentermine pill prescription phentermine 37.5 mg tablets Np Prescription Adipex no rx adipex? canadian pharmacy phentermine Buy Phentermine Overnight Delivery phentermine wordwide shipping online cheapest buy adipex no rx Better Phentermine Or Adipex phentermine 180 count buy duromine online Phentermine Online Us Pharmacy phentermine on sale picture of phentermine Buy Phentermine On Line Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. buy phentermine hcl

Phentermine Generic

phentermine cheep online prescription phentermine Prescription For Adipex phentermine heart murmur generic for ionamin Phentermine Wikipedia phentermine hcl prescription diet pills information break phentermine Where Can I Buy Prescription Phentermine adipex p? online prescription for phentermine? Extra Cheap Phentermine 37.5mg adipex pharmacy phentermine Phentermine Cod No Prior Rx Cheap buy fastin in florida? "overnight phentermine brand no script" Phentermine Online Buy phentermine 37.5 without a prescription does bontril work better than adipex Phentermine 37.5 180 Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. adipex same day shipping Buy Duromine phentermine 37.5 mgs search viagra edinburgh phentermine find Legit Phentermine Sites cheap phentermine guaranteed best prices lowest cost phentermine overnight delivery Buy Phentermine Online order phentermine pills "phentermine 6 pm order" Adipex Sale Best Online Pharmacy overseas phentermine, neurotoxicity phentermine Buy Cheap Phentermine No Rx phentermine for weight loss pharmacies that sell phentermine, Phentermine At Discount Prices diet ingredient phentermine pill phentermine ssri Phentermine Online No Prescription "generic adipex no prescription" "generic adipex no prescription" Phentermine No Prescri diet no phentermine pill prescription phentermine 37.5 mg tablets
Diet Inexpensive Phentermine Pill no rx adipex? phentermine mexico Buy Phentermine Online Cod phentermine wordwide shipping online cheapest buy adipex no rx Phentermine Vs Meridia phentermine 180 count buy duromine online Phentermine Diet Tablets phentermine on sale picture of phentermine Order Adipex No Prescription Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. phentermine online consultation order Adipex On Line phentermine cheep is adipex safe Phentermine Canadian Pharmacy phentermine heart murmur generic for ionamin Adipex From Us Online Pharmacy phentermine hcl prescription diet pills information break phentermine Cheapest Phentermine 37.5 adipex p? online prescription for phentermine? Ordering Phentermine By International Pharmacy 37.5mg adipex pharmacy phentermine Phentermine 37.5 Without Prescription buy fastin in florida? "overnight phentermine brand no script" Phentermine Blue phentermine 37.5 without a prescription does bontril work better than adipex Phentermine Diet Pills Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. adipex same day shipping Buy Cheap Adipex Capsules phentermine 37.5 mgs search viagra edinburgh phentermine find Cheap 37.5 Phentermine cheap phentermine guaranteed best prices
lowest cost phentermine overnight delivery
Pharma 4 Phentermines order phentermine pills phentermine china Phentermine 30 Mg 90 Capsules overseas phentermine, neurotoxicity phentermine Adipex Same Day Shipping phentermine for weight loss pharmacies that sell phentermine, Atipex Phentermine diet ingredient phentermine pill phentermine ssri Cheap Phentermine Tablet "generic adipex no prescription" "generic adipex no prescription" Generic Phentermine diet no phentermine pill prescription phentermine 37.5 mg tablets Phentermine Hydrochloride Pdr no rx adipex? canadian pharmacy phentermine Pharmacies That Sell Phentermine phentermine wordwide shipping online cheapest

buy adipex no rx

Phentermine 37.5 Fast Shipping phentermine 180 count discount phentermine without dr approval Phentermine Cheapest Overnight Cod phentermine on sale picture of phentermine Adipex P Home Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. buy phentermine hcl

Phentermine Prescription Online

phentermine cheep online prescription phentermine Phentermine 37 Mg phentermine heart murmur generic for ionamin Phentermine Discounts phentermine hcl prescription diet pills information break phentermine Fake And Phentermine adipex p? online prescription for phentermine? Purchasing Adipex Without A Prescription 37.5mg adipex phentermine with no perscription Buy Adipex From Us Pharmacy buy fastin in florida? "overnight phentermine brand no script" Canada Adipex Diet Pills phentermine 37.5 without a prescription does bontril work better than adipex Where Can I Purchase Phentermine Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. adipex appetite suppressant Phentermine Diet Pills Diet Pills phentermine 37.5 mgs search viagra edinburgh phentermine find No Persciption Phentermine cheap phentermine guaranteed best prices buy ionamin cheap medication be studied Adipex No Prescription Overnight Delivery order phentermine pills "phentermine 6 pm order" Cheap Phentermine 32 overseas phentermine, neurotoxicity phentermine Order Phentermine Online Uk phentermine for weight loss No prescription needed adipex phentermine no processing fees 995. Phentermine W O Rx diet ingredient phentermine pill phentermine ssri Purchase Phentermine Overnight "generic adipex no prescription" "generic adipex no prescription" Difference Between Adipex And Phentermine diet no phentermine pill prescription phentermine 37.5 mg tablets Is Phentermine Hcl Safe To Take no rx adipex? canadian pharmacy phentermine Phentermine Fed Ex phentermine wordwide shipping online cheapest buy adipex no rx Phentermine American Express phentermine 180 count buy duromine online Buy Phentermine With Mastercard phentermine on sale picture of phentermine Generic Fastin Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. buy phentermine hcl Adipex Or Similar Metabolism Increasing Drugs

phentermine cheep

online prescription phentermine Adipex Pills Pharmacy Online phentermine heart murmur generic for ionamin Phentermine Without phentermine hcl prescription diet pills information break phentermine Get Phentermine Delivered Overnight adipex p? online prescription for phentermine? Cheap Phentermine Diet Pil L 37.5mg adipex pharmacy phentermine No Membership Phentermine buy fastin in florida? "overnight phentermine brand no script" Phentermine Without Perscription phentermine 37.5 without a prescription does bontril work better than adipex Where Can I Order Phentermine Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. adipex appetite suppressant Search Results Buy Phentermine phentermine 37.5 mgs search viagra edinburgh phentermine find Phentermine Over Night cheap phentermine guaranteed best prices lowest cost phentermine overnight delivery Phentermine No Presciption order phentermine pills "phentermine 6 pm order" Phentermine Sales overseas phentermine, neurotoxicity phentermine After Taking Ionamin phentermine for weight loss No prescription needed adipex phentermine no processing fees 995. Phentermine No Prior Script diet ingredient phentermine pill phentermine ssri Adipex P In The Yahoo Directory "generic adipex no prescription" phentermine and side? Phentermine Pharmacy diet no phentermine pill prescription phentermine 37.5 mg tablets What Is Adipex no rx adipex? canadian pharmacy phentermine Buy Phentermine No Script phentermine wordwide shipping online cheapest buy adipex no rx Difference Between Adipex phentermine 180 count buy duromine online Phentermine On Line Without A Prescription phentermine on sale picture of phentermine Phentermine Without A Prescription Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. buy phentermine hcl Phentermine Buy Phentermine Online phentermine cheep is adipex safe Phentermine Hydrochloride phentermine heart murmur generic for ionamin Adipex No Prescription Needed phentermine hcl prescription diet pills information "taking phentermine in menopause" Cheap 37 5 Phentermine adipex p? online prescription for phentermine? Phentermine 37.5 Mgs 37.5mg adipex phentermine with no perscription Overnight Delivery Phentermine buy fastin in florida? "overnight phentermine brand no script" Internet Prescriptions Phentermine phentermine 37.5 without a prescription does bontril work better than adipex Phentermine Warnings Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. adipex appetite suppressant Buy Phentermine Online Without A Prescrition phentermine 37.5 mgs search viagra edinburgh phentermine find Phentermine No Prescriptions cheap phentermine guaranteed best prices lowest cost phentermine overnight delivery Phentermine Hcl Prescription Diet Pills Information order phentermine pills "phentermine 6 pm order" Phentermine Online Without Prescription Physician Consult overseas phentermine, neurotoxicity phentermine Phentermine Withdrawl phentermine for weight loss No prescription needed adipex phentermine no processing fees 995. Phentermine On Line Consultation And Prescription diet ingredient phentermine pill phentermine ssri Adipex Buy 35565 Buy "generic adipex no prescription" "generic adipex no prescription" Best Online Deal For Phentermine diet no phentermine pill prescription Genertic phentermine phentermine by fedex 602.
Phentermine And Dextrin no rx adipex? phentermine mexico Adipex P phentermine wordwide shipping online cheapest buy adipex no rx Buy Fastin phentermine 180 count buy duromine online Where Can I Find Phentermine phentermine on sale picture of phentermine Adipex Overnight 24 Hr Delivery Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. buy phentermine hcl Real Phentermine Diet Pills phentermine cheep is adipex safe
Cheapest Phentermine Hlc 37.5 37.5
phentermine heart murmur duromine 30 mg; Buy Fastin Without Perscription phentermine hcl prescription diet pills information break phentermine Adipex Fed Ex adipex p? online prescription for phentermine? Phentermine Yellow 37.5mg adipex pharmacy phentermine Detox Hgh Phentermine Quit Smoking Xenical buy fastin in florida? "overnight phentermine brand no script" Buy Phentermine On Line Cheap phentermine 37.5 without a prescription does bontril work better than adipex Phentermine Without Physician Consultation Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. adipex same day shipping Prescription Diet Pills Purchase Phentermine phentermine 37.5 mgs search viagra edinburgh phentermine find Buy Generic Phentermine cheap phentermine guaranteed best prices buy ionamin cheap medication be studied Phentermine Overnight order phentermine pills "phentermine 6 pm order" C O D Phentermine

overseas phentermine,

purchase adipex from pharmacies usa? Phentermine Guaranteed Cheapest Uk Shipping phentermine for weight loss pharmacies that sell phentermine, Phentermine Hcl Symtoms diet ingredient phentermine pill phentermine ssri Buy Phentermine Online Cheap "generic adipex no prescription" "generic adipex no prescription" Adipex No Rx Needed diet no phentermine pill prescription phentermine 37.5 mg tablets Adipex Side Affects no rx adipex? canadian pharmacy phentermine Phentermine And Online Prescriptions phentermine wordwide shipping online cheapest buy adipex no rx Phentermine Cod Next Day phentermine 180 count buy duromine online Fastin 30mg phentermine on sale picture of phentermine Adipex Retard Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. phentermine online consultation order Find Phentermine phentermine cheep is adipex safe Adipex Fastin Facts phentermine heart murmur generic for ionamin Buy Phentermine From China Mexico phentermine hcl prescription diet pills information break phentermine Buy Discount Phentermine No Prescription adipex p? online prescription for phentermine? Phentermine 30mg Axcion 37.5mg adipex pharmacy phentermine Phentermine No Prescription Online buy fastin in florida? "overnight phentermine brand no script" Sinpet phentermine 37.5 without a prescription does bontril work better than adipex Np Prescription Adipex 30 Day Supply Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. adipex same day shipping Phentermine On Sale In Th phentermine 37.5 mgs search viagra edinburgh phentermine find Buying Phentermine Online cheap phentermine guaranteed best prices lowest cost phentermine overnight delivery Phentermine No Scirpt Required order phentermine pills "phentermine 6 pm order" Phentermine 37.5 No Prescription Fast Ship overseas phentermine, neurotoxicity phentermine Most Reliable Site To Order Phentermine phentermine for weight loss pharmacies that sell phentermine, Adipex Without A Prescription diet ingredient phentermine pill phentermine ssri Adipex D "generic adipex no prescription" "generic adipex no prescription" Legit Phentermine Website diet no phentermine pill prescription phentermine 37.5 mg tablets Authentic Phentermine Without Prescription no rx adipex? canadian pharmacy phentermine Fastin Without A Prescription phentermine wordwide shipping online cheapest buy adipex no rx Buy Ionamin Without Prescription phentermine 180 count buy duromine online Buy Phentermine Cod phentermine on sale picture of phentermine Phentermine Buy On Line Overnight Phentermine worldwide shipping cheapest buy adipex overnight no prescription mastercard 19. buy phentermine hcl Adipex P With No Prescription phentermine cheep is adipex safe Ionamin Complete Prescribing Information phentermine heart murmur