- Home /
Draw point with time function
I try to write a script to draw cloud-point. The script must draw a single point every second from an array (or or a time that I decide). I try to use Time (or delta.Time) function (I search inside forum without result) without result. I don't understand it'work... This is the script:
var dotMaterial : Material;
var PointsList : Array;
var Points : Array;
var PointsArray : Vector3[];
var dotSize = 1.0;
var dotsnumber = 1;
var dotstime = 1;
private var oldPosition : Vector3;
private var oldRotation : Quaternion;
private var cam : Transform;
private var dots : VectorPoints;
PointsList = [];
function Start() {
cam = Camera.main.transform;
oldPosition = cam.position;
oldRotation = cam.rotation;
Points = new Array();
for (i = 0; i < PointsList.length / 3; i++){
Points.Add(Vector3(-PointsList[i*3],PointsList[i*3+2],-PointsList[i*3+1]));
}
PointsArray = Points.ToBuiltin(Vector3);
dots = new VectorPoints("Dots", PointsArray, null, dotMaterial, dotSize);
dots.maxDrawIndex = dotsnumber; //this value say how many point of array drawing
Vector.DrawPoints(dots);
}
function Update() { // every second script must be draw one more point
dotstime = Time.deltaTime*1;
dotsnumber = dotsnumber + dotstime;
}
function LateUpdate () {
if (cam.position != oldPosition || cam.rotation != oldRotation) {
oldPosition = cam.position;
oldRotation = cam.rotation;
dots.maxDrawIndex = dotsnumber;
Vector.DrawPoints(dots);
}
}
Thanks. The script work, but I have a problem. The frame rate drops over time! Help... This is the new script:
var dot$$anonymous$$aterial : $$anonymous$$aterial;
var PointsList : Array;
var Points : Array;
var PointsArray : Vector3[];
var dotSize = 1.0;
private var oldPosition : Vector3;
private var oldRotation : Quaternion;
private var cam : Transform;
private var dots : VectorPoints;
PointsList = []; //15000 point coordinate max.
var dotsnumber = 1;
function Start() {
InvokeRepeating ("IncreaseDotsnumber", 0.01, 0.01);
Points = new Array();
for (i = 0; i < PointsList.length / 3; i++){
Points.Add(Vector3(-PointsList[i*3],PointsList[i*3+2],-PointsList[i*3+1]));
}
RandomizeArray.RandomizeArray (Points);
PointsArray = Points.ToBuiltin(Vector3);
dots = new VectorPoints("Dots", PointsArray, null, dot$$anonymous$$aterial, dotSize);
cam = Camera.main.transform;
oldPosition = cam.position;
oldRotation = cam.rotation;
}
function IncreaseDotsnumber(){
dotsnumber++;
}
function LateUpdate () {
if (cam.position == oldPosition || cam.rotation == oldRotation){
dots.maxDrawIndex = dotsnumber;
Vector.DrawPoints(dots);
}
else if (cam.position != oldPosition || cam.rotation != oldRotation) {
oldPosition = cam.position;
oldRotation = cam.rotation;
dots.maxDrawIndex = dotsnumber;
Vector.DrawPoints(dots);
}
}
Please don't post comments as answers. It's expected that the framerate would go down over time, since you're drawing more and more of the points over time.
Sorry. It was a question related to the first and I did not want to open another post. Any idea to solve the problem?
Answer by Eric5h5 · Jul 19, 2011 at 09:57 PM
"dotstime" is an int, so assigning Time.deltaTime to it will always result in 0. You're better off just using InvokeRepeating anyway.
function Start () {
InvokeRepeating ("IncreaseDotsnumber", 1.0, 1.0);
}
function IncreaseDotsnumber () {
dotsnumber++;
}
Your answer
Follow this Question
Related Questions
Timing problem in Guitar Hero style game 2 Answers
How to check if you draw/outline a symblol by its contour? 2 Answers
Draw single point 2 Answers