/** \brief Handle updates in time of our fish * * This is called before we draw and allows us to * move our fish. We add our speed times the amount * of time that has elapsed. * \param elapsed Time elapsed since the class call */ void CFish::Update(double elapsed) { SetLocation(GetX() + mSpeedX * elapsed, GetY() + mSpeedY * elapsed); // X movement if (mSpeedX > 0 && GetX() + GetWidth()/2 + flipOffset >= GetAquarium()->GetWidth()) { mSpeedX = -mSpeedX; SetMirror(mSpeedX < 0); } else if (mSpeedX < 0 && GetX() - GetWidth()/2 - flipOffset <= 0){ mSpeedX = -mSpeedX; SetMirror(mSpeedX < 0); } // Y movement if (mSpeedY > 0 && GetY() + GetHeight() / 2 + heightOffset >= GetAquarium()->GetHeight()) { mSpeedY = -mSpeedY; } else if (mSpeedY < 0 && GetY() - GetHeight() / 2 - heightOffset <= 0){ mSpeedY = -mSpeedY; } }
/** \brief Handle updates in time of our fish * * This is called before we draw and allows us to * move our fish. We add our speed times the amount * of time that has elapsed. * \param elapsed Time elapsed since the class call */ void CFish::Update(double elapsed) { SetLocation(GetX() + mSpeedX * elapsed, GetY() + mSpeedY * elapsed); int reverseAtXLocation = BackgroundWidth - EdgeTolerance - (GetImageWidth() / 2); int reverseAtStart = BackgroundWidth - reverseAtXLocation; int HitTopYLocation = BackgroundHeight - 2 * EdgeTolerance - (GetImageHeight() / 2); int HitBottomYLocation = BackgroundHeight - EdgeTolerance - HitTopYLocation; //Fish logic to stay inbounds if (mSpeedX > 0 && GetX() >= reverseAtXLocation) { mSpeedX = -mSpeedX; SetMirror(mSpeedX < 0); } else if (mSpeedX < 0 && GetX() <= reverseAtStart) { mSpeedX = abs(mSpeedX); SetMirror(false); } else if (mSpeedY > 0 && GetY() >= HitTopYLocation) { mSpeedY = -mSpeedY; } else if (mSpeedY < 0 && GetY() <= HitBottomYLocation) { mSpeedY = -mSpeedY; } BreedingUpdate(elapsed); AgeUpdate(elapsed); //increases the time used to track feeding for fish mTimeFeeding++; //adjusts the fishes condtion based on the time since they were fed if (mTimeFeeding < TimeTillHungry) { mIsHungry = false; mIsDead = false; this->SetNotHungryImage(); } else if (mTimeFeeding >= TimeTillHungry && mTimeFeeding < (TimeTillDead)) { mIsHungry = true; this->SetHungryImage(); } else if (mTimeFeeding >= TimeTillDead) { mIsDead = true; } }
XnStatus MockGenerator::SetIntProperty(const XnChar* strName, XnUInt64 nValue) { XnStatus nRetVal = XN_STATUS_OK; if (strcmp(strName, XN_PROP_IS_GENERATING) == 0) { SetGenerating((XnBool)nValue); } else if (strcmp(strName, XN_PROP_TIMESTAMP) == 0) { m_data[m_nNextDataIdx].nTimeStamp = nValue; } else if (strcmp(strName, XN_PROP_FRAME_ID) == 0) { m_data[m_nNextDataIdx].nFrameID = (XnUInt32)nValue; } else if (strcmp(strName, XN_CAPABILITY_MIRROR) == 0) { m_bMirrorCap = (XnBool)nValue; } else if (strcmp(strName, XN_PROP_MIRROR) == 0) { nRetVal = SetMirror((XnBool)nValue); XN_IS_STATUS_OK(nRetVal); } //TODO: Check for alternative view point cap, framesync cap else { return MockProductionNode::SetIntProperty(strName, nValue); } return XN_STATUS_OK; }
XnStatus LinkOniMapStream::Init() { XnStatus nRetVal = XN_STATUS_OK; nRetVal = LinkOniStream::Init(); XN_IS_STATUS_OK(nRetVal); nRetVal = FillSupportedVideoModes(); XN_IS_STATUS_OK(nRetVal); // read video mode XnChar videoModeSection[255]; sprintf(videoModeSection, "%s.VideoMode", m_configSection); OniVideoMode videoMode; GetVideoMode(&videoMode); // override with streams default values GetDefaultVideoMode(&videoMode); // override with INI config XnInt32 temp32; if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, videoModeSection, "XResolution", &temp32)) { videoMode.resolutionX = (int)temp32; } if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, videoModeSection, "YResolution", &temp32)) { videoMode.resolutionY = (int)temp32; } if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, videoModeSection, "FPS", &temp32)) { videoMode.fps = (int)temp32; } if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, videoModeSection, "PixelFormat", &temp32)) { videoMode.pixelFormat = (OniPixelFormat)temp32; } nRetVal = SetVideoMode(&videoMode); XN_IS_STATUS_OK(nRetVal); nRetVal = setIntPropertyFromINI("LinkPixelFormat", LINK_PROP_PIXEL_FORMAT); XN_IS_STATUS_OK(nRetVal); nRetVal = setIntPropertyFromINI("Compression", LINK_PROP_COMPRESSION); XN_IS_STATUS_OK(nRetVal); OniBool bMirror = TRUE; if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, m_configSection, "Mirror", &temp32)) { bMirror = (temp32 == 1); } nRetVal = SetMirror(bMirror); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
OniStatus LinkOniMapStream::setProperty(int propertyId, const void* data, int dataSize) { XnStatus nRetVal = XN_STATUS_ERROR; switch(propertyId) { case ONI_STREAM_PROPERTY_VIDEO_MODE: EXACT_PROP_SIZE(dataSize, OniVideoMode); nRetVal = SetVideoMode((OniVideoMode*)data); XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR); break; case ONI_STREAM_PROPERTY_MIRRORING: EXACT_PROP_SIZE(dataSize, OniBool); nRetVal = SetMirror(*(OniBool*)data); XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR); break; case ONI_STREAM_PROPERTY_CROPPING: EXACT_PROP_SIZE(dataSize, OniCropping); nRetVal = SetCropping(*(OniCropping*)data); XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR); break; case LINK_PROP_PIXEL_FORMAT: { ENSURE_PROP_SIZE(dataSize, XnLinkPixelFormat); XnFwStreamVideoMode mode = m_pInputStream->GetVideoMode(); mode.m_nPixelFormat = *(XnFwPixelFormat*)data; nRetVal = m_pInputStream->SetVideoMode(mode); XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR); break; } case LINK_PROP_COMPRESSION: { ENSURE_PROP_SIZE(dataSize, XnLinkCompressionType); XnFwStreamVideoMode mode = m_pInputStream->GetVideoMode(); mode.m_nCompression = *(XnFwCompressionType*)data; nRetVal = m_pInputStream->SetVideoMode(mode); XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR); break; } case PS_PROPERTY_GAIN: { ENSURE_PROP_SIZE(dataSize, XnUInt16); nRetVal = m_pInputStream->SetGain(*(XnUInt16*)data); XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR); break; } default: return LinkOniStream::setProperty(propertyId, data, dataSize); } return ONI_STATUS_OK; }
/** * brief Load the attributes for an fisg node. * * This is the class version that loads the attributes * common to all fishes. Override this to load custom attributes * for specific fish. * * \param node The Xml node we are loading the fish from */ void CFish::XmlLoad(const std::shared_ptr<xmlnode::CXmlNode> &node) { CItem::XmlLoad(node); mSpeedX = node->GetAttributeDoubleValue(L"speedX", 0); mSpeedY = node->GetAttributeDoubleValue(L"speedY", 0); mDaysSinceSex = node->GetAttributeIntValue(L"dayssincesex", 0); mPregnantDay = node->GetAttributeIntValue(L"pregnantday", 0); mFood = node->GetAttributeIntValue(L"food", 0); mDaysSinceFed = node->GetAttributeIntValue(L"dayssincefed", 0); SetMirror(mSpeedX < 0); }
void CFish::BreedingUpdate(double elapsed) { CAquarium *aquarium = GetAquarium(); //fish logic for breeding if (mCanBreed == true && mAge >= MaxAge) { if (mInterestTime >= InterestTimePreBreed) { mIsInterested = true; } else if (mIsGestating == false) mInterestTime++; if (mIsGestating == true) mGestatingTime++; if (mIsInterested == true) { CBreedVisitor visitor(mIsMale, GetType()); aquarium->Accept(&visitor); if (visitor.IsInterested()) { // Compute a vector from (x1,y1) to (x2,y2) double dx = visitor.GetX() - GetX(); double dy = visitor.GetY() - GetY(); // How long is that vector? double len = sqrt(dx * dx + dy * dy); if (len > 0) { // Normalize the vector dx /= len; dy /= len; } // Update the location if (GetType() == "beta") { mSpeedX = dx * (MaxSpeedX - BetaSpeed) * BreedMultuplier * elapsed; mSpeedY = dy * (MaxSpeedY - BetaSpeed) * BreedMultuplier * elapsed; } if (GetType() == "bubbles") { mSpeedX = dx * (MaxSpeedX - BubblesSpeed) * BreedMultuplier * elapsed; mSpeedY = dy * (MaxSpeedY - BubblesSpeed) * BreedMultuplier * elapsed; } if (GetType() == "dory") { mSpeedX = dx * (DorySpeed - MaxSpeedX) * BreedMultuplier * elapsed; mSpeedY = dy * (DorySpeed - MaxSpeedY) * BreedMultuplier * elapsed; } // check if the visited fish overlaps this one if (OverlapTest(visitor.GetX(), visitor.GetY())) { if (mIsMale == 0) { mIsGestating = true; } else { visitor.SetGestating(); } mIsInterested = false; mInterestTime = 0; visitor.SetUninterested(); if (GetType() == "beta") { mSpeedX = ((double)rand() / RAND_MAX) * (MaxSpeedX - BetaSpeed); mSpeedY = ((double)rand() / RAND_MAX) * (MaxSpeedY - BetaSpeed); } else if (GetType() == "bubbles") { mSpeedX = ((double)rand() / RAND_MAX) * (MaxSpeedX - BubblesSpeed); mSpeedY = ((double)rand() / RAND_MAX) * (MaxSpeedY - BubblesSpeed); } else if (GetType() == "dory") { mSpeedX = ((double)rand() / RAND_MAX) * (DorySpeed- MaxSpeedX); mSpeedY = ((double)rand() / RAND_MAX) * (DorySpeed- MaxSpeedY); } } } } if (mGestatingTime >= GestatingTime) { mIsGestating = false; mGestatingTime = 0; if (GetType() == "beta") { auto fish = make_shared<CFishBeta>(aquarium); fish->SetLocation(GetX(), GetY()); aquarium->AddTempItem(fish); } if (GetType() == "bubbles") { auto fish = make_shared<CFishBubbles>(aquarium); fish->SetLocation(GetX(), GetY()); aquarium->AddTempItem(fish); } if (GetType() == "dory") { auto fish = make_shared<CFishDory>(aquarium); fish->SetLocation(GetX(), GetY()); aquarium->AddTempItem(fish); } } if (mSpeedX < 0) SetMirror(true); if (mSpeedX > 0) SetMirror(false); } }