user3699912
user3699912

Reputation: 159

Vector3 subVector error in Dart

I get the following error when I try to use the SubVectors property on Dart (with three.dart and vector_math).

The method 'subVector' is not defined for the class 'Vector3'

for(var x=0;x<width-1;x++){
          for(var y=0;y<height-1;y++){
              Vector3 vec0; Vector3 vec1;  Vector3 n_vec;
              // one of two triangle polygons in one rectangle
              vec0.subVectors(geometry.vertices[offset(x,y)],geometry.vertices[offset(x+1,y)]);
              vec1.subVectors(geometry.vertices[offset(x,y)],geometry.vertices[offset(x,y+1)]); 

Upvotes: 0

Views: 264

Answers (1)

Fox32
Fox32

Reputation: 13560

The vector_math package doesn't have a subVectors method on the Vector3 class. You can archive the same by writing the first value into vec0 and then substracting the other one:

vec0.setFrom(geometry.vertices[offset(x,y)]);
vec0.sub(geometry.vertices[offset(x+1,y)]);
vec1.setFrom(geometry.vertices[offset(x,y)]); 
vec1.sub(geometry.vertices[offset(x,y+1)]); 

This would require that vec0 and vec1 are already initialized with an Vector3 instance. As an alternative you could use the minus operator to substract the two values, but this would create a new instance:

vec0 = geometry.vertices[offset(x,y)] - geometry.vertices[offset(x+1,y)];
vec1 = geometry.vertices[offset(x,y)] - geometry.vertices[offset(x,y+1)];

You can check out the current vector_math documentation here.

Upvotes: 2

Related Questions