本文整理汇总了C++中DVector类的典型用法代码示例。如果您正苦于以下问题:C++ DVector类的具体用法?C++ DVector怎么用?C++ DVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_faces
Ref<Shape> Mesh::create_trimesh_shape() const {
DVector<Face3> faces = get_faces();
if (faces.size()==0)
return Ref<Shape>();
DVector<Vector3> face_points;
face_points.resize( faces.size()*3 );
for (int i=0;i<face_points.size();i++) {
Face3 f = faces.get( i/3 );
face_points.set(i, f.vertex[i%3] );
}
Ref<ConcavePolygonShape> shape = memnew( ConcavePolygonShape );
shape->set_faces(face_points);
return shape;
}
示例2: get_selected_tile
DVector<Vector2> TileMapEditor::_bucket_fill(const Point2i& p_start) {
if (node->get_cell(p_start.x, p_start.y) != TileMap::INVALID_CELL)
return DVector<Vector2>();
int id = get_selected_tile();
if (id == TileMap::INVALID_CELL)
return DVector<Vector2>();
Rect2 r = node->get_item_rect();
r.pos = r.pos/node->get_cell_size();
r.size = r.size/node->get_cell_size();
DVector<Vector2> points;
List<Point2i> queue;
queue.push_back(p_start);
while (queue.size()) {
Point2i n = queue.front()->get();
queue.pop_front();
if (!r.has_point(n))
continue;
if (node->get_cell(n.x, n.y) == TileMap::INVALID_CELL) {
node->set_cellv(n, id, flip_h, flip_v, transpose);
points.push_back(n);
queue.push_back(n + Point2i(0, 1));
queue.push_back(n + Point2i(0, -1));
queue.push_back(n + Point2i(1, 0));
queue.push_back(n + Point2i(-1, 0));
}
}
return points;
}
示例3: _handle_udp
/***
* Manage UDP packets
*/
void NetGameServer::_handle_udp() {
DVector<uint8_t> raw;
NetGameServerConnection *cd;
// Flush packets queue
while(udp_queue.size() > 0) {
// Only this thread removes from the queue
// it is safe to lock here
udp_mutex->lock();
QueuedPacket *qp = udp_queue.get(0);
udp_queue.remove(0);
udp_mutex->unlock();
NetGameServerConnection *cd = _get_client(qp->id);
if(cd != NULL) {
udp_server->set_send_address(cd->udp_host,
cd->udp_port);
udp_server->put_packet_buffer(cd->build_pkt(qp));
}
memdelete(qp);
}
// Handle incoming packets
if(udp_server->get_available_packet_count() > 0) {
udp_server->get_packet_buffer(raw);
if(raw.size() < 1) {
WARN_PRINT("Invalid UDP Packet!");
return;
}
cd = _get_client(raw.get(0));
if(cd == NULL) {
WARN_PRINT("Invalid UDP Auth!");
return;
}
cd->handle_udp(raw,
udp_server->get_packet_address(),
udp_server->get_packet_port());
}
}
示例4: main
/* >>> start tutorial code >>> */
int main( ){
USING_NAMESPACE_ACADO
// DEFINE VALRIABLES:
// ---------------------------
DMatrix A(3,3);
DVector b(3) ;
DifferentialState x("", 3, 1);
Function f ;
// DEFINE THE VECTOR AND MATRIX ENTRIES:
// -------------------------------------
A.setZero() ;
A(0,0) = 1.0; A(1,1) = 2.0; A(2,2) = 3.0;
b(0) = 1.0; b(1) = 1.0; b(2) = 1.0;
// DEFINE A TEST FUNCTION:
// -----------------------
f << A*x + b;
f << ( A*x(0) ).getRow( 1 );
f << ( A*x(0) ).getCol( 0 );
// TEST THE FUNCTION f:
// --------------------
EvaluationPoint zz(f);
DVector xx(3);
xx(0) = 1.0;
xx(1) = 2.0;
xx(2) = 3.0;
zz.setX( xx );
DVector result = f.evaluate( zz );
result.print(std::cout, "result");
return 0;
}
示例5: ERR_FAIL_COND
void SampleManagerMallocSW::sample_set_data(RID p_sample, const DVector<uint8_t>& p_buffer) {
Sample *s = sample_owner.get(p_sample);
ERR_FAIL_COND(!s);
int buff_size=p_buffer.size();
ERR_FAIL_COND(buff_size==0);
ERR_EXPLAIN("Sample buffer size does not match sample size.");
ERR_FAIL_COND(s->length_bytes!=buff_size);
DVector<uint8_t>::Read buffer_r=p_buffer.read();
const uint8_t *src = buffer_r.ptr();
uint8_t *dst = (uint8_t*)s->data;
for(int i=0;i<s->length_bytes;i++) {
dst[i]=src[i];
}
}
示例6: diffTransitionBackward
returnValue Integrator::diffTransitionBackward( DVector &DX,
DVector &DP,
DVector &DU,
DVector &DW,
int &order ){
ASSERT( transition != 0 );
if( order != 1 ) return ACADOERROR( RET_NOT_IMPLEMENTED_YET );
EvaluationPoint z( *transition, DX.getDim(), 0, DP.getDim(), DU.getDim(), DW.getDim() );
transition->AD_backward( DX, z );
DX = z.getX();
DP = z.getP();
DU = z.getU();
DW = z.getW();
return SUCCESSFUL_RETURN;
}
示例7: get_data
Array StreamPeer::_get_data(int p_bytes) {
Array ret;
DVector<uint8_t> data;
data.resize(p_bytes);
if (data.size() != p_bytes) {
ret.push_back(ERR_OUT_OF_MEMORY);
ret.push_back(DVector<uint8_t>());
return ret;
}
DVector<uint8_t>::Write w = data.write();
Error err = get_data(&w[0], p_bytes);
w = DVector<uint8_t>::Write();
ret.push_back(err);
ret.push_back(data);
return ret;
}
示例8:
DVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
DVector<Plane> planes;
for (int i = 0; i < p_sides; i++) {
Vector3 normal;
normal[(p_axis + 1) % 3] = Math::cos(i * (2.0 * Math_PI) / p_sides);
normal[(p_axis + 2) % 3] = Math::sin(i * (2.0 * Math_PI) / p_sides);
planes.push_back(Plane(normal, p_radius));
}
Vector3 axis;
axis[p_axis] = 1.0;
planes.push_back(Plane(axis, p_height * 0.5));
planes.push_back(Plane(-axis, p_height * 0.5));
return planes;
}
示例9: get_segments
Rect2 ConcavePolygonShape2D::get_rect() const {
DVector<Vector2> s = get_segments();
int len=s.size();
if (len==0)
return Rect2();
Rect2 rect;
DVector<Vector2>::Read r = s.read();
for(int i=0;i<len;i++) {
if (i==0)
rect.pos=r[i];
else
rect.expand_to(r[i]);
}
return rect;
}
示例10: dot
// FIXME parallellize
TVal dot(const DVector<TVal, TIdx>& rhs) const {
JWAssert(rhs.size() == size());
const auto& lhs = *this;
TVal sum = 0;
for (TIdx i = 0; i < this->size(); ++i) {
sum += lhs[i] * rhs[i];
}
return sum;
}
示例11: clear_polygons
void NavigationMesh::create_from_mesh(const Ref<Mesh>& p_mesh) {
vertices=DVector<Vector3>();
clear_polygons();
for(int i=0;i<p_mesh->get_surface_count();i++) {
if (p_mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES)
continue;
Array arr = p_mesh->surface_get_arrays(i);
DVector<Vector3> varr = arr[Mesh::ARRAY_VERTEX];
DVector<int> iarr = arr[Mesh::ARRAY_INDEX];
if (varr.size()==0 || iarr.size()==0)
continue;
int from = vertices.size();
vertices.append_array(varr);
int rlen = iarr.size();
DVector<int>::Read r = iarr.read();
for(int j=0;j<rlen;j+=3) {
Vector<int> vi;
vi.resize(3);
vi[0]=r[j+0]+from;
vi[1]=r[j+1]+from;
vi[2]=r[j+2]+from;
add_polygon(vi);
}
}
}
示例12: _gen_debug_mesh_lines
Ref<Mesh> Shape::get_debug_mesh() {
if (debug_mesh_cache.is_valid())
return debug_mesh_cache;
Vector<Vector3> lines = _gen_debug_mesh_lines();
debug_mesh_cache = Ref<Mesh>(memnew(Mesh));
if (!lines.empty()) {
//make mesh
DVector<Vector3> array;
array.resize(lines.size());
{
DVector<Vector3>::Write w=array.write();
for(int i=0;i<lines.size();i++) {
w[i]=lines[i];
}
}
Array arr;
arr.resize(Mesh::ARRAY_MAX);
arr[Mesh::ARRAY_VERTEX]=array;
SceneTree *st=OS::get_singleton()->get_main_loop()->cast_to<SceneTree>();
debug_mesh_cache->add_surface(Mesh::PRIMITIVE_LINES,arr);
if (st) {
debug_mesh_cache->surface_set_material(0,st->get_debug_collision_material());
}
}
return debug_mesh_cache;
}
示例13: read
bool D_bjmak::getHashesAndData(int fd, DVector& dataBuffer, DVector& hashBuffer, int blockCount){
string hash;
hash.reserve(26);
for(int i = 0; i < blockCount; ++i){
char buf[bsize_];
int l = read(fd, buf, bsize_);
//cout << " read " << l << " i = " << i << "blockCount = " << blockCount << endl;
if (l == -1){
cout << " read errror " << strerror(errno) << endl;
return false;
}
DVector hashstr;
hash = Hash::sha1(buf, l);
hashstr.push_back(hash.data(), hash.size());
hashstr.push_back(int64_to_byte(Hash::crc32(buf, l), 4));
hashstr.push_back(int64_to_byte(l, 2));
hashBuffer.push_back(hashstr);
dataBuffer.push_back(buf, l);
}
return true;
}
示例14: getDataBufferFromReply
DVector D_bjmak::getDataBufferFromReply(DVector& reply, DVector& hashBuffer, DVector& dataBuffer){
int dataPos = 0;
int blockCount = reply.size();
char* hashBufferPtr = hashBuffer.data();
char* dataBufferPtr = dataBuffer.data();
DVector res;
res.reserve(blockCount*bsize_);
for(int i = 0; i < blockCount; ++i){
int dataBlockSize = byte_to_int64((hashBufferPtr+i*(D_LENGTH_OF_HASH+2)+D_LENGTH_OF_HASH), 2);
if (reply[i] == 1){
//cout << " 1 " << dataBlockSize << endl;
res.push_back(dataBufferPtr+dataPos, dataBlockSize);
}else
//cout << " - " << (int)reply[i] << " " << dataBuffer.size() << " " << hashBuffer.size()<< " " << dataBlockSize << endl;
dataPos += dataBlockSize;
}
//cout << endl;
return move(res);
}
示例15: setForwardSeed
returnValue Integrator::setForwardSeed( const int &order,
const DVector &xSeed,
const DVector &pSeed,
const DVector &uSeed,
const DVector &wSeed ){
int run1;
if( rhs == 0 ) return ACADOERROR( RET_TRIVIAL_RHS );
DVector tmpX;
DVector components = rhs->getDifferentialStateComponents();
dP = pSeed;
dU = uSeed;
dW = wSeed;
if( xSeed.getDim() != 0 ){
tmpX.init( components.getDim() );
for( run1 = 0; run1 < (int) components.getDim(); run1++ )
tmpX(run1) = xSeed((int) components(run1));
}
return setProtectedForwardSeed( tmpX, pSeed, uSeed, wSeed, order );
}