void bitset( const Delta& u, BitSet& bit ) { const uint n = u.rows(); bit.resize( n, false ); for( Delta::InnerIterator it( u, 0 ); it; ++it ) { uint i = it.row(); bit[i] = true; } }
const SUCCESS mouseMove(const Uint32 window, const Uint32 mouse, const Delta<Point<int> > &movement, const bitset<N_MOUSE_BUTTONS> &buttons) override { SUCCESS ret = SUCCEEDED; if(window == ren.getWin()->getID() && buttons[SDL_BUTTON_LEFT-1]) ret = ren.drawLine(Line<int>(movement.get(), prev)); prev = movement.get(); return ret; };
void delta( const Source& source, const uint size, Delta& u, const Scalar& default_value ) { u.resize( size, 1 ); u.setZero(); u.reserve( source.size() ); for( const auto& s: source ) { u.insert( s, 0 ) = default_value; } }
void consume(const IMC::Rpm* msg) { if (!isActive()) return; // Compute time delta. double timestep = m_last_rpm.getDelta(); // Check if we have a valid time delta. if (timestep < 0.0) return; switch (m_speed_units) { case IMC::SUNITS_PERCENTAGE: dispatchThrust(m_desired_speed / 100.0, timestep); // disable the meters per second controller m_u_active = false; break; case IMC::SUNITS_RPM: rpmToThrust(msg->value, m_desired_speed, timestep); m_previous_rpm = m_desired_speed; // disable the meters per second controller m_u_active = false; break; default: break; } if (m_u_active) rpmToThrust(msg->value, m_desired_rpm, timestep); }
//since we're only updating on component at a time, get the delta that //is at this vertex and stage, and just replace the exisitng delta component with the //new compnent in change. change will always have 2 zero components and 1 non-zero component void MeshManager::adjustVertex(int stage, int id, ofVec3f change){ Delta* d = getOrMakeVertexDelta(stage, id); ofVec3f existing = d->getChange(); if(change.x == 0) change.x = existing.x; if(change.y == 0) change.y = existing.y; if(change.z == 0) change.z = existing.z; d->setChange(change); //printChanges(); updateMeshes(stage); }
template<class Bdl, class Delta> void operator()(Bdl& ref, const Delta& refdelta) const { assert(ref.size()==refdelta.size()); for(auto i = ref.first() ; i < ref.size() ; ++i) { detail::internal_apply_increment(ref.reference(i),get_ptr(refdelta(i))); } }
void Timers() { UpdateTimer.Update(TimeDelta); //Lower timer times by time passed for (int i = 0; i < 4; i++) { HealthLossTimers[i].UpdateZero(TimeDelta); } }
const SUCCESS mouseMove(const Uint32 window, const Uint32 mouse, const Delta<Point<int> > &movement, const bitset<N_MOUSE_BUTTONS> &buttons) { if(current == NULL) return SUCCEEDED; current->setImage(new ScaledTexture(stamp, movement.get()-current->getPixelPosition())); return SUCCEEDED; }
// re-initialize all member variables; inline void reset(double __sr, int __vs) { __exception = 0; vectorsize = __vs; samplerate = __sr; m_y_1 = 0; m_history_2 = 0; m_history_3 = 0; m_history_4 = 0; m_history_5 = 0; m_history_6 = 0; m_history_7 = 0; m_history_8 = 0; m_history_9 = 0; m_y_10 = 0; m_delay_11.reset("m_delay_11", 96000); m_delay_12.reset("m_delay_12", 96000); m_resonance_13 = 0; m_cutoff_14 = 2250; m_window_15 = 100; m_mix_16 = 0.5; m_blur_17 = 0.25; m_ratio_18 = 0.5; m_window_19 = 100; m_ratio_20 = 2; samples_to_seconds = (1 / samplerate); m_phasor_21.reset(0); m_delta_22.reset(0); m_sah_23.reset(0); m_sah_24.reset(0); m_delta_25.reset(0); m_sah_26.reset(0); m_sah_27.reset(0); m_delta_28.reset(0); m_sah_29.reset(0); m_sah_30.reset(0); m_delta_31.reset(0); m_sah_32.reset(0); m_sah_33.reset(0); m_phasor_34.reset(0); m_delta_35.reset(0); m_sah_36.reset(0); m_sah_37.reset(0); m_delta_38.reset(0); m_sah_39.reset(0); m_sah_40.reset(0); m_delta_41.reset(0); m_sah_42.reset(0); m_sah_43.reset(0); m_delta_44.reset(0); m_sah_45.reset(0); m_sah_46.reset(0); genlib_reset_complete(this); };
void Model::countObservedFeatures() { for(vector<Feature*>::iterator f = features.begin(); f != features.end(); f++) { int i = (*f)->xListIndex(); int k = (*f)->yListIndex(); vector<int> xIndices = _Xindices[i]; vector<int> yIndices = _Yindices[k]; for(vector<int>::iterator xx = xIndices.begin(); xx != xIndices.end(); xx++) { cout << *xx << " "; } cout << endl; for(int d = 0; d < Xdata->rows(); d++) { vector<unsigned long> xrow = Xdata->row(d); vector<unsigned long> yrow = Ydata->row(d); bool found = false; for(vector<Delta*>::iterator d = (*f)->begin(); d != (*f)->end(); d++) { if((*d)->matchXY(xrow,yrow)) { (*d)->incObserved(); found = true; break; } } if(found == false) { Delta *d = new Delta(xrow, xIndices, yrow, yIndices); d->incObserved(); (*f)->push_back(d); deltas.push_back(d); } } } }
int main(void) { cout.precision(3); cout<<"Wheel spinning at 1 radian per iteration:"<<endl<<"Position"<<endl; Delta<Radians> rotationalVelocity; for(rotationalVelocity = Radians(1.0); rotationalVelocity.get() < 10.0; rotationalVelocity.increment()) cout<<double(rotationalVelocity.get())<<endl; cout<<"Now lets start trying to spin it the other way. Every 5 iterations we'll decrease the speed by one third of a radian per iteration"<<endl<<"Position\tVelocity"<<endl; for(int i = 0; i < 4; i++) { rotationalVelocity -= 2.0/3.0; for(int j = 0; j < 5; j++) { cout<<double(rotationalVelocity.get())<<'\t'<<'\t'<<double(rotationalVelocity)<<endl; rotationalVelocity.increment(); } } cout<<"Das p cool, but I want continuity. Let's increase the Delta every instant, using a delta"<<endl<<"Position\tVelocity\tAcceleration"<<endl; for(Delta<Delta<Radians> > rotationalAccel(Delta<Radians>(Radians(0.2)), rotationalVelocity); rotationalAccel.get() < 100.0; rotationalAccel.increment()) cout<<double(rotationalAccel.get(Delta<Radians>::N_DERIVATIVE))<<'\t'<<'\t'<< double(rotationalAccel.get(Delta<Delta<Radians> >::N_DERIVATIVE))<<'\t'<<'\t'<< double(rotationalAccel)<<endl; cout<<"Wowee. I wonder what else this thing can do..."<<endl; return 0; }
void consume(const IMC::EstimatedState* msg) { if (!isActive()) return; // Compute time delta. double timestep = m_last_mps.getDelta(); // Check if we have a valid time delta. if (timestep < 0.0) return; // If we're asked for m/s or if u controller is active if (m_speed_units == IMC::SUNITS_METERS_PS || m_u_active) { float abs_gvel = msg->u; mpsToRpm(abs_gvel, timestep); // Enable u controller m_u_active = true; } }
void apply_delta_and_capture(const Delta& dd, GameState *gs) { take_step_and_capture(dd.first(), gs); if (dd.size() == 2) take_step_and_capture(dd.second(), gs); }
void Network() { if (UpdateTimer.Check() <= 0 && UpdateTimer.Active == true) { UpdateTimer.Reset(1); int numconnected = 0; //Number of connected players //Find out the number of players connected for (int i = 0; i < 4; i++) { if (Players[i].Connected) { numconnected++; } } for (int i = 0; i < 4; i++) { if (Players[i].Connected) { RakNet::BitStream BSOut; BSOut.Write((RakNet::MessageID)SID_POS_UPDATE); //Send number of connected players BSOut.Write((int)numconnected); //Send own player's information BSOut.Write((float)Players[i].PosX); BSOut.Write((float)Players[i].PosZ); BSOut.Write((int)Players[i].Health); //Send other players' information for (int j = 0; j < 4; j++) { //If we haven't already sent this player's information and if he/she is connected.. if (j != i) { //Is the player connected? if (Players[j].Connected) { //Flag for client identification of other players BSOut.Write((int)Players[j].Flag); BSOut.Write((float)Players[j].PosX); BSOut.Write((float)Players[j].PosZ); } } } NetDevice->Send(&BSOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, PlayerAddresses[i], false); } } } for (Packet = NetDevice->Receive(); Packet; NetDevice->DeallocatePacket(Packet), Packet = NetDevice->Receive()) { switch (Packet->data[0]) { case CID_MOVE_MESSAGE : { for (int i = 0; i < 4; i++) { //Which player sent the message? Is he/she still connected? if (Packet->systemAddress == PlayerAddresses[i] && Players[i].Connected) { //Read messages into server player classes RakNet::BitStream BSIn(Packet->data, Packet->length, false); BSIn.IgnoreBytes(sizeof(RakNet::MessageID)); BSIn.Read(Players[i].DestinationX); BSIn.Read(Players[i].DestinationZ); std::cout << "Player " << i << " ordered a move to (" << Players[i].DestinationX << " , " << Players[i].DestinationZ << ")"; Skip(); //Send authentication packet to player who sent message RakNet::BitStream BSOut; BSOut.Write((RakNet::MessageID)SID_MOVE_AUTH); BSOut.Write((float)Players[i].DestinationX); BSOut.Write((float)Players[i].DestinationZ); NetDevice->Send(&BSOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, Packet->systemAddress, false); Players[i].NewDestination = true; //Send move messages to all other online players for (int j = 0; j < 4; j++) { if (j != i) { //Is the player connected? if (Players[j].Connected) { RakNet::BitStream BSOutOther; BSOutOther.Write((RakNet::MessageID)SID_MOVE_OTHER); BSOutOther.Write((int)Players[i].Flag); BSOutOther.Write((float)Players[i].DestinationX); BSOutOther.Write((float)Players[i].DestinationZ); NetDevice->Send(&BSOutOther, HIGH_PRIORITY, RELIABLE_ORDERED, 0, PlayerAddresses[j], false); } } } break; } } } break; case CID_POS_REQUEST : { int numconnected = 0; //Number of connected players //Find out the number of players connected for (int i = 0; i < 4; i++) { if (Players[i].Connected) { numconnected++; } } for (int i = 0; i < 4; i++) { //Who sent the packet? Is he/she still connected? if (Packet->systemAddress == PlayerAddresses[i] && Players[i].Connected) { std::cout << "Player " << i << " has requested an update."; Skip(); //Send current player situation RakNet::BitStream BSOut; BSOut.Write((RakNet::MessageID)SID_POS_INITIATE); BSOut.Write((float)Players[i].PosX); BSOut.Write((float)Players[i].PosZ); BSOut.Write((float)Players[i].MoveFactor); BSOut.Write((int)Players[i].Health); //Send the flag BSOut.Write((int)(i)); //Send the number of connected players BSOut.Write((int)numconnected); for (int j = 0; j < 4; j++) { //If we haven't already sent this player's information and if he/she is connected.. if (j != i) { //Is the player connected? if (Players[j].Connected) { //Flag for client identification of other players BSOut.Write((int)Players[j].Flag); BSOut.Write((float)Players[j].PosX); BSOut.Write((float)Players[j].PosZ); BSOut.Write((float)Players[j].MoveFactor); } } } NetDevice->Send(&BSOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, Packet->systemAddress, false); //Send initiation messages to all other online players for (int j = 0; j < 4; j++) { if (j != i) { //Is the player connected? if (Players[j].Connected) { RakNet::BitStream BSOutOther; BSOutOther.Write((RakNet::MessageID)SID_POS_OTHER); BSOutOther.Write((int)Players[i].Flag); BSOutOther.Write((float)Players[i].PosX); BSOutOther.Write((float)Players[i].PosZ); BSOutOther.Write((float)Players[i].MoveFactor); NetDevice->Send(&BSOutOther, HIGH_PRIORITY, RELIABLE_ORDERED, 0, PlayerAddresses[j], false); } } } break; } } } break; case ID_REMOTE_DISCONNECTION_NOTIFICATION: Print("Another client has disconnected."); Skip(); break; case ID_REMOTE_CONNECTION_LOST: Print("Another client has lost the connection."); Skip(); break; case ID_REMOTE_NEW_INCOMING_CONNECTION: Print("Another client has connected."); Skip(); break; case ID_NEW_INCOMING_CONNECTION: Print("A connection is incoming."); for (int i = 0; i < 4; i++) { //Allocate Player IP if (PlayerAddresses[i].port == 0) { PlayerAddresses[i] = Packet->systemAddress; Players[i].Connected = true; //Begin appropriate timer for (int i = 0; i < 4; i++) { HealthLossTimers[i].Activate(); } break; } } //Begin the timer(s) UpdateTimer.Activate(); if (UpdateTimer.Timer == 0) //Check if reset is nessasary (Only for initiation) { UpdateTimer.Reset(0); } break; case ID_NO_FREE_INCOMING_CONNECTIONS: Print("The server is full."); Skip(); break; case CID_DISCONNECT: for (int i = 0; i < 4; i++) { //Which player sent the message? if (Packet->systemAddress == PlayerAddresses[i]) { //Close the connection NetDevice->CloseConnection(PlayerAddresses[i], true, 1, IMMEDIATE_PRIORITY); //Reset the player's data Players[i] = resetplayers[i]; //Reset the port and address to allow reconnection PlayerAddresses[i] = EmptyAddress; PlayerAddresses[i].port = 0; std::cout << "Player " << i << " " << "has disconnected manually."; Skip(); //Send disconnect information to other players for (int j = 0; j < 4; j++) { if (j != i) { //Is the player connected? if (Players[j].Connected) { RakNet::BitStream BSOutOther; BSOutOther.Write((RakNet::MessageID)SID_DISCONNECT_OTHER); BSOutOther.Write((int)Players[i].Flag); NetDevice->Send(&BSOutOther, HIGH_PRIORITY, RELIABLE_ORDERED, 0, PlayerAddresses[j], false); } } } } } break; case ID_DISCONNECTION_NOTIFICATION: for (int i = 0; i < 4; i++) { //Which player sent the message? if (Packet->systemAddress == PlayerAddresses[i]) { //Reset the player's data Players[i] = resetplayers[i]; //Reset the port and address to allow reconnection PlayerAddresses[i] = EmptyAddress; PlayerAddresses[i].port = 0; std::cout << "Player " << i << " " << "has disconnected."; Skip(); } } break; case ID_CONNECTION_LOST: Print("A client lost the connection."); Skip(); break; default: printf("Message with identifier %i has arrived.\n\n", Packet->data[0]); break; } } }