Handle<Value> SCRIntersect(const Arguments& args) { if(args.Length() < 2 || !IsVec3(args[0]) || ! IsVec3(args[1])) { return ThrowError("usage: intersect(float[3] from, float[3] to, [int32 nodemask])"); } unsigned int nodemask = dtEntity::NodeMasks::PICKABLE | dtEntity::NodeMasks::TERRAIN; if(args.Length() >= 3) { nodemask = args[2]->Uint32Value(); } dtEntity::Vec3d from = UnwrapVec3(args[0]); dtEntity::Vec3d to = UnwrapVec3(args[1]); dtEntity::SystemInterface::Intersections isects; bool found = dtEntity::GetSystemInterface()->GetIntersections(from, to, isects, nodemask); HandleScope scope; Handle<Array> ret = Array::New(); if(!found) { return scope.Close(ret); } Handle<String> entityid = String::New("EntityId"); Handle<String> normal = String::New("Normal"); Handle<String> position = String::New("Position"); unsigned int count = 0; for(dtEntity::SystemInterface::Intersections::const_iterator i = isects.begin(); i != isects.end(); ++i) { dtEntity::SystemInterface::Intersection isect = *i; Handle<Object> obj = Object::New(); obj->Set(entityid, Uint32::New(isect.mEntityId)); obj->Set(normal, WrapVec3(isect.mNormal)); obj->Set(position, WrapVec3(isect.mPosition)); ret->Set(count++, obj); } return scope.Close(ret); }
Handle<Value> SCRGetPickRay(const Arguments& args) { if(args.Length() < 3) { return ThrowError("getPickRay expects three arguments!"); } if(!args[0]->IsInt32()) { return ThrowError("Usage: getPickRay(contextid, x, y[, bool usePixels])"); } unsigned int contextid = args[0]->Uint32Value(); float x = (float)args[1]->NumberValue(); float y = (float)args[2]->NumberValue(); bool usePixels = true; if(args.Length() > 3) { usePixels = args[4]->BooleanValue(); } dtEntity::Vec3f pr = dtEntity::GetWindowInterface()->GetPickRay(contextid, x, y, usePixels); return WrapVec3(pr); }
Handle<Value> SCRConvertWorldToScreenCoords(const Arguments& args) { dtEntity::Vec3d screenXYZ(args[0]->NumberValue(), args[1]->NumberValue(), args[2]->NumberValue()); dtEntity::Vec3d c = dtEntity::GetWindowInterface()->ConvertWorldToScreenCoords(0, screenXYZ); return WrapVec3(c); }
Handle<Value> SCRGetPickRay(const Arguments& args) { dtEntity::Vec3f pr = dtEntity::GetWindowInterface()->GetPickRay("defaultView", args[0]->NumberValue(), args[1]->NumberValue()); return WrapVec3(pr); }