≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
Randomize the positions of some scene nodes
Posted by:
(you are not logged in)
Enter the missing letter in: "In?ernational"
(you are not logged in)
Text:
[quote][b][/b] wrote: Updated behavior (objects now should be placed above terrain): [code] /* <behavior jsname="behavior_RandomizeNodesPositions" description="Randomize Nodes Positions"> <property name="RandomizeRotation" type="bool" default="false" /> <property name="MinimalDistance" type="int" default="0" /> </behavior> */ behavior_RandomizeNodesPositions = function() {}; behavior_RandomizeNodesPositions.prototype.onAnimate = function(_node) { this.onAnimate = function() {}; var self = this; var node = ccb.node.get(_node); var bbox = node.getWorldBBox(); var positions = []; function createPosition() { return new ccb.vector(ccb.core.randRange(bbox.min.x, bbox.max.x), node.getWorldPosition().y, ccb.core.randRange(bbox.min.z, bbox.max.z)); } function findPosition() { var position = createPosition(); if(self.MinimalDistance > 0) { _.every(positions, function(_position) { if(position.getDistanceTo(_position) < self.MinimalDistance) { position = findPosition(); return false; } return true; }); } return position; } _.each(node.getChildren(), function(child) { var position = findPosition(); var line = new ccb.line(position.clone().sub(new ccb.vector(0, 5000, 0)), position.clone().add(new ccb.vector(0, 10000, 0))); var intersection = node.getIntersectionWithLine(line); if(intersection) { position.y = intersection.y; } if(self.RandomizeRotation) { var rotation = child.getRotation().clone(); rotation.y = ccb.core.randRange(0, 360); child.setRotation(rotation); } position.y += child.getBBox().getSize().y / 2; child.setPosition(node.transformWorldPointToLocal(position)); positions.push(position); }); }; [/code] The minimal distance should work fine - keep in mind that it's the distance between center of objects, so if an object has size 10x10, the minimal distance must be set to > 10 to prevent objects from colliding. You can also again download newest version of the wrapper - I've removed the debug logs.[/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact