void ParticleEmitterComponent::update(double time) { auto last_spawn_position = math::get_translation(WorldTransform()); TransformableComponent::update(time); Density.update(time); if (!ParticleSystem) { ParticleSystem = get_user()->get_component<ParticleSystemComponent>(ParticleSystemLabel()); } if (ParticleSystem) { particles_to_spawn_ += time * Density(); if (particles_to_spawn_ > 1.f) { auto pos(math::get_translation(WorldTransform())); auto rot(math::get_rotation(WorldTransform())); int count = particles_to_spawn_; particles_to_spawn_ = particles_to_spawn_ - count; for (int i(0); i<count; ++i) { auto p = pos + 1.f*i/count*(last_spawn_position-pos); ParticleSystem->spawn(p, rot, Velocity()); } } } }
//------------------------------ Render ---------------------------------- // //------------------------------------------------------------------------ void CGun::Render(HDC &surface, HPEN &GunPen) { WorldTransform(); HPEN OldPen = (HPEN)SelectObject(surface, GunPen); MoveToEx(surface, m_vecGunVBTrans[0].x, m_vecGunVBTrans[0].y, NULL); for (int vtx=0; vtx<m_vecGunVBTrans.size(); ++vtx) { LineTo(surface, m_vecGunVBTrans[vtx].x, m_vecGunVBTrans[vtx].y); } LineTo(surface, m_vecGunVBTrans[0].x, m_vecGunVBTrans[0].y); int BulletCounter = 0; //render any active bullets for (int blt=0; blt<m_vecBullets.size(); ++blt) { if (m_vecBullets[blt].Active()) { m_vecBullets[blt].Render(surface, GunPen); ++BulletCounter; } } SelectObject(surface, OldPen); }
//--------------------------- Render ------------------------------------- // //------------------------------------------------------------------------ void Raven_Bot::Render() { //when a bot is hit by a projectile this value is set to a constant user //defined value which dictates how long the bot should have a thick red //circle drawn around it (to indicate it's been hit) The circle is drawn //as long as this value is positive. (see Render) m_iNumUpdatesHitPersistant--; if (isDead() || isSpawning()) return; gdi->BluePen(); m_vecBotVBTrans = WorldTransform(m_vecBotVB, Pos(), Facing(), Facing().Perp(), Scale()); gdi->ClosedShape(m_vecBotVBTrans); //draw the head (gdi->*(m_pTeam->GetPen()))(); gdi->Circle(Pos(), 6.0 * Scale().x); //render the bot's weapon m_pWeaponSys->RenderCurrentWeapon(); //render a thick red circle if the bot gets hit by a weapon if (m_bHit) { gdi->ThickRedPen(); gdi->HollowBrush(); gdi->Circle(m_vPosition, BRadius()+1); if (m_iNumUpdatesHitPersistant <= 0) { m_bHit = false; } } gdi->TransparentText(); gdi->TextColor(0,255,0); if (UserOptions->m_bShowBotIDs) { gdi->TextAtPos(Pos().x -10, Pos().y-20, ttos(ID())); } if (UserOptions->m_bShowBotHealth) { gdi->TextAtPos(Pos().x-40, Pos().y-5, "H:"+ ttos(Health())); } if (UserOptions->m_bShowScore) { gdi->TextAtPos(Pos().x-40, Pos().y+10, "Scr:"+ ttos(Score())); } }
//--------------------------- Render ------------------------------------- // //------------------------------------------------------------------------ void GoalKeeper::Render() { if (Team()->Color() == SoccerTeam::blue) gdi->BluePen(); else gdi->RedPen(); m_vecPlayerVBTrans = WorldTransform(m_vecPlayerVB, Pos(), m_vLookAt, m_vLookAt.Perp(), Scale()); gdi->ClosedShape(m_vecPlayerVBTrans); //draw the head gdi->BrownBrush(); gdi->Circle(Pos(), 6); //draw the ID if (Prm.bIDs) { gdi->TextColor(0, 170, 0);; gdi->TextAtPos(Pos().x-20, Pos().y-20, ttos(ID())); } //draw the state if (Prm.bStates) { gdi->TextColor(0, 170, 0); gdi->TransparentText(); gdi->TextAtPos(m_vPosition.x, m_vPosition.y -20, std::string(m_pStateMachine->GetNameOfCurrentState())); } }
bool SpatialNode::LookAt(const Vector3& target, const Vector3& up, TransformSpace space) { SpatialNode* parentNode = SpatialParent(); Vector3 worldSpaceTarget; switch (space) { case TS_LOCAL: worldSpaceTarget = WorldTransform() * target; break; case TS_PARENT: worldSpaceTarget = !parentNode ? target : parentNode->WorldTransform() * target; break; case TS_WORLD: worldSpaceTarget = target; break; } Vector3 lookDir = worldSpaceTarget - WorldPosition(); // Check if target is very close, in that case can not reliably calculate lookat direction if (lookDir.Equals(Vector3::ZERO)) return false; Quaternion newRotation; // Do nothing if setting look rotation failed if (!newRotation.FromLookRotation(lookDir, up)) return false; SetWorldRotation(newRotation); return true; }
Frustum Light::WorldFrustum() const { const Matrix3x4& transform = WorldTransform(); Matrix3x4 frustumTransform(transform.Translation(), transform.Rotation(), 1.0f); Frustum ret; ret.Define(fov, 1.0f, 1.0f, 0.0f, range, frustumTransform); return ret; }
mathfu::vec3 TransformComponent::WorldPosition(corgi::EntityRef entity) { TransformData* transform_data = Data<TransformData>(entity); if (transform_data->parent) { return WorldTransform(transform_data->parent) * transform_data->position; } else { return transform_data->position; } }
mathfu::mat4 TransformComponent::WorldTransform(corgi::EntityRef entity) { TransformData* transform_data = Data<TransformData>(entity); if (transform_data->parent) { return WorldTransform(transform_data->parent) * transform_data->GetTransformMatrix(); } else { return transform_data->GetTransformMatrix(); } }
void PointLightComponent::serialize(SerializedScenePtr& scene) const { auto transform(math::make_translation(math::get_translation(WorldTransform()))); transform = transform * math::make_scale(math::get_scale(WorldTransform())); Serialized s; s.Depth = WorldDepth(); s.Transform = transform; s.Texture = Texture(); s.Color = Color().vec4(); scene->renderers().point_lights.add(std::move(s)); }
//-------------------------------- Render ------------------------------------- //----------------------------------------------------------------------------- void RocketLauncher::Render() { m_vecWeaponVBTrans = WorldTransform(m_vecWeaponVB, m_pOwner->Pos(), m_pOwner->Facing(), m_pOwner->Facing().Perp(), m_pOwner->Scale()); gdi->RedPen(); gdi->ClosedShape(m_vecWeaponVBTrans); }
//-------------------------------- Render ------------------------------------- //----------------------------------------------------------------------------- void RailGun::Render() { m_vecWeaponVBTrans = WorldTransform(m_vecWeaponVB, m_pOwner->Pos(), m_pOwner->Facing(), m_pOwner->Facing().Perp(), m_pOwner->Scale()); gdi->BluePen(); gdi->ClosedShape(m_vecWeaponVBTrans); }
//-------------------------------- Render ------------------------------------- //----------------------------------------------------------------------------- void ShotGun::Render() { m_vecWeaponVBTrans = WorldTransform(m_vecWeaponVB, m_pOwner->Pos(), m_pOwner->Facing(), m_pOwner->Facing().Perp(), m_pOwner->Scale()); gdi->BrownPen(); gdi->PolyLine(m_vecWeaponVBTrans); }
//----------------------------- RenderLandingPad ------------------------ // // Does exactly that //----------------------------------------------------------------------- void CController::RenderLandingPad(HDC &surface) { //create a temp buffer vector<SPoint> PadVB = m_vecPadVB; //transform the vertices WorldTransform(PadVB); //draw the lines MoveToEx(surface, (int)PadVB[0].x, (int)PadVB[0].y, NULL); for (int vert=1; vert<4; ++vert) { LineTo(surface, (int)PadVB[vert].x, (int)PadVB[vert].y); } LineTo(surface, (int)PadVB[0].x, (int)PadVB[0].y); }
//------------------------------ Render ---------------------------------- void CGun::Render(HDC &surface) { WorldTransform(); MoveToEx(surface, m_vecGunVBTrans[0].x, m_vecGunVBTrans[0].y, NULL); for (int vtx=0; vtx<m_vecGunVBTrans.size(); ++vtx) { LineTo(surface, m_vecGunVBTrans[vtx].x, m_vecGunVBTrans[vtx].y); } LineTo(surface, m_vecGunVBTrans[0].x, m_vecGunVBTrans[0].y); //now render object info string s = "Position(" + ftos(m_dPosX) + ", " + ftos(m_dPosY) + ")"; TextOut(surface, 5, 0, s.c_str(), s.size()); s = "Rotation: " + ftos(m_dRotation); TextOut(surface, 5, 20, s.c_str(), s.size()); s = "Scale: " + ftos(m_dScale); TextOut(surface, 5, 40, s.c_str(), s.size()); }
void ButtonReleaseAction(Graph *graph, XButtonReleasedEvent *buttonevent) { int button; int sx2, sy2; int sx1, sy1; float x1, y1, x2, y2; button = buttonevent->button; sx2 = buttonevent->x; sy2 = buttonevent->y; switch (ButtonMode()) { case DATAMODE: switch (button) { case 1: /* zoom box */ /* * mark the end of the drag and zoom */ graph->dragx2 = sx2; graph->dragy2 = sy2; WorldTransform(graph, graph->dragx1, graph->dragy1, &x1, &y1); WorldTransform(graph, graph->dragx2, graph->dragy2, &x2, &y2); /* * Don't perform a zero scale action. */ if (x2 == x1 || y2 == y1) return; if (x2 > x1) { graph->wxmin = x1; graph->wxmax = x2; } else { graph->wxmin = x2; graph->wxmax = x1; } if (y2 > y1) { graph->wymin = y1; graph->wymax = y2; } else { graph->wymin = y2; graph->wymax = y1; } ScaleAndRefreshGraph(graph); /* * set the drag coords back to the invalid state */ graph->dragx1 = -1; graph->dragx2 = -1; break; case 2: /* ruler line */ /* * get the world coordinates of the starting point */ x1 = graph->dragwx1; y1 = graph->dragwy1; if (sx2 != graph->dragx1 || sy2 != graph->dragy1) { if (snapmode) { /* * display the final coords */ Snap(graph, sx2, sy2, &x2, &y2); /* * compute the screen coordinate of the data point */ ScreenTransform(graph, x2, y2, &sx1, &sy1); ShowCoords((BasicWindow *)graph, sx1, sy1, x2, y2); } else { /* * display the final coords */ WorldTransform(graph, sx2, sy2, &x2, &y2); ShowCoords((BasicWindow *)graph, sx2, sy2, x2, y2); } ClearWindow((BasicWindow *)graph->frame->text); ShowSlope((BasicWindow *)graph->frame->text, 0, graph->fontheight, x1, y1, x2, y2); AddLabelLine((BasicWindow *)graph, 0, 0, 0, 0, x1, y1, x2, y2, WORLD_LBL, TEMPORARY_LBL); } /* * set the drag coords back to the invalid state */ graph->dragx1 = -1; graph->dragx2 = -1; break; case 3: /* drag line */ /* * erase the old line */ EraseSuperLine((BasicWindow *)graph, graph->dragx2, graph->dragy1, graph->dragx2, graph->dragy2); /* * get the coords */ Snap(graph, sx2, sy2, &x2, &y2); ShowCoords((BasicWindow *)graph, graph->dragx2, graph->dragy2, x2, y2); graph->dragx1 = -1; graph->dragx2 = -1; break; } break; case DRAWMODE: switch (button) { case 1: /* draw line */ /* * mark the end of the drag and zoom */ graph->dragx2 = sx2; graph->dragy2 = sy2; WorldTransform(graph, graph->dragx1, graph->dragy1, &x1, &y1); WorldTransform(graph, graph->dragx2, graph->dragy2, &x2, &y2); /* * draw a line between the points */ AddLabelLine((BasicWindow *)graph, 0, 0, 0, 0, x1, y1, x2, y2, WORLD_LBL, TEMPORARY_LBL); /* * set the drag coords back to the invalid state */ graph->dragx1 = -1; graph->dragx2 = -1; break; } break; } }
void Snap(Graph *graph, int sx, int sy, float *wx, float *wy) { float x, y; float wx2, wy2; int i; int npoints; Plot *p; Plot *plot; FCoord *data; /* * get the world coordinates of the cursor */ WorldTransform(graph, sx, sy, &x, &y); /* * get the currently selected plot * use the first plot as the default */ plot = graph->plot; for (p = graph->plot; p; p = p->next) { if (p->selected) { plot = p; } } /* * locate the data point with the closest x coord * from the currently selected plot */ data = plot->data; npoints = plot->npoints; /* * check the endpoints */ if (npoints > 0) { /* * get the first data point */ GetDataPoint(plot, data, wx, wy); /* * if there is only one point then just return * return with wx, wy set to the data point */ if (npoints < 2) return; /* * otherwise get the last data point */ GetDataPoint(plot, data + npoints - 1, &wx2, &wy2); /* * is it beyond the most positive data point? */ if (x >= *wx && x >= wx2) { /* * return with wx, wy set to the most positive data point */ if (wx2 > *wx) { *wx = wx2; *wy = wy2; } return; } /* * is it beyond the most negative data point? */ if (x <= *wx && x <= wx2) { /* * return with wx, wy set to the most positive data point */ if (wx2 < *wx) { *wx = wx2; *wy = wy2; } return; } GetDataPoint(plot, data, wx, wy); for (i = 1; i < plot->npoints; i++) { GetDataPoint(plot, data + i, &wx2, &wy2); /* * is x between this data point and the last? */ if (wx2 >= *wx) { if (x < wx2 && x >= *wx) { return; } } else { if (x < *wx && x >= wx2) { *wx = wx2; *wy = wy2; return; } } *wx = wx2; *wy = wy2; } } }
void ButtonPressAction(Graph *graph, XButtonPressedEvent *buttonevent) { float x, y; int sx1, sy1; int sx2, sy2; int button; sx1 = buttonevent->x; sy1 = buttonevent->y; button = buttonevent->button; switch (ButtonMode()) { case DATAMODE: switch (button) { case 1: /* * mark the start of the drag location */ graph->dragx1 = sx1; graph->dragy1 = sy1; break; case 2: ClearWindow((BasicWindow *)graph->frame->text); if (snapmode) { /* * world coord xy readout of data */ Snap(graph, sx1, sy1, &x, &y); /* * get the screen coords of the data point */ ScreenTransform(graph, x, y, &sx2, &sy2); ShowCoords((BasicWindow *)graph, sx2, sy2, x, y); /* * mark the start of the drag location */ graph->dragx1 = sx2; graph->dragy1 = sy2; } else { /* * world coord xy readout of cursor location */ WorldTransform(graph, sx1, sy1, &x, &y); ShowCoords((BasicWindow *)graph, sx1, sy1, x, y); /* * mark the start of the drag location */ graph->dragx1 = sx1; graph->dragy1 = sy1; } graph->dragwx1 = x; graph->dragwy1 = y; break; case 3: /* * world coord xy readout closest above point */ Snap(graph, sx1, sy1, &x, &y); /* * draw a line to the point on the plot (sx2, sy2) */ ScreenTransform(graph, x, y, &sx2, &sy2); /* avoid writing on the last pixel */ if (sy2 > sy1) { sy2 -= 1; } else { sy2 += 1; } graph->dragx1 = sx1; graph->dragy1 = sy1; graph->dragx2 = sx2; graph->dragy2 = sy2; DrawSuperLine((BasicWindow *)graph, sx2, sy1, sx2, sy2); ClearWindow((BasicWindow *)graph->frame->text); NBShowCoords((BasicWindow *)graph->frame->text, 0, graph->fontheight, x, y); } break; case DRAWMODE: switch (button) { case 1: /* * mark the start of the line */ graph->dragx1 = sx1; graph->dragy1 = sy1; WorldTransform(graph, sx1, sy1, &x, &y); graph->dragwx1 = x; graph->dragwy1 = y; break; } break; case ZAPMODE: switch (button) { case 1: /* * delete the label */ ZapLabel(graph, (XKeyEvent *)buttonevent); break; } break; case PINCHMODE: switch (button) { case 1: /* * offset the plots */ OffsetPlotGraphically(graph, buttonevent->x, buttonevent->y, 0); break; } break; } }
//----------------------UpdateShipFromAction--------------------------- // // this is the main workhorse. It reads the ships decoded string of // actions and performs them, updating the lander accordingly. It also // checks for impact and updates the fitness score. // //---------------------------------------------------------------------- bool CLander::UpdateShip() { //just return if ship has crashed or landed if (m_bCheckedIfLanded) { return false; } //this will be the current action action_type action; //check that we still have an action to perform. If not then //just let the lander drift til it hits the ground if (m_cTick >= m_vecActions.size()) { action = non; } else { action = m_vecActions[m_cTick++]; } //switch the jet graphic off m_bJetOn = false; switch (action) { case rotate_left: m_dRotation -= ROTATION_PER_TICK; if (m_dRotation < -PI) { m_dRotation += TWO_PI; } break; case rotate_right: m_dRotation += ROTATION_PER_TICK; if (m_dRotation > TWO_PI) { m_dRotation -= TWO_PI; } break; case thrust: { //the lander's acceleration per tick calculated from //the force the thruster exerts and the lander's mass double ShipAcceleration = THRUST_PER_TICK/m_dMass; //resolve the acceleration vector into its x, y components //and add to the lander's velocity vector m_vVelocity.x += ShipAcceleration * sin(m_dRotation); m_vVelocity.y += ShipAcceleration * cos(m_dRotation); //switch the jet graphic on m_bJetOn = true; } break; case non: break; }//end switch //now add in the gravity vector m_vVelocity.y += GRAVITY_PER_TICK; //update the lander's position m_vPos += m_vVelocity; //bounds checking if (m_vPos.x > WINDOW_WIDTH) { m_vPos.x = 0; } if (m_vPos.x < 0) { m_vPos.x = WINDOW_WIDTH; } //now we check to see if the lander has crashed or landed //create a copy of the landers verts before we transform them m_vecShipVBTrans = m_vecShipVB; //transform the vertices WorldTransform(m_vecShipVBTrans); //if we are lower than the ground then we have finished this run if (TestForImpact(m_vecShipVBTrans)) { //check if user has landed ship if (!m_bCheckedIfLanded) { //calculate fitness if we haven't already if (!m_dFitness) { CalculateFitness(); m_bCheckedIfLanded = true; } return false; } } return true; }
void Trigger_WeaponGiver::Render() { if (isActive()) { switch (EntityType()) { case type_rail_gun: { gdi->BluePen(); gdi->BlueBrush(); gdi->Circle(Pos(), 3); gdi->ThickBluePen(); gdi->Line(Pos(), Vector2D(Pos().x, Pos().y-9)); } break; case type_shotgun: { gdi->BlackBrush(); gdi->BrownPen(); const double sz = 3.0; gdi->Circle(Pos().x-sz,Pos().y, sz); gdi->Circle(Pos().x+sz,Pos().y, sz); } break; case type_smg: { gdi->RedBrush(); gdi->YellowPen(); const double sz = 3.0; gdi->Circle(Pos().x - sz, Pos().y, sz); gdi->Circle(Pos().x + sz, Pos().y, sz); } break; case type_revolver: { gdi->BlackBrush(); gdi->BlackPen(); const double sz = 2.0; gdi->Circle(Pos().x - sz, Pos().y, sz); gdi->Circle(Pos().x + sz, Pos().y, sz); gdi->Circle(Pos().x - sz / 2.0, Pos().y + sz / 2.0, sz); gdi->Circle(Pos().x + sz / 2.0, Pos().y + sz / 2.0, sz); gdi->Circle(Pos().x - sz / 2.0, Pos().y - sz / 2.0, sz); gdi->Circle(Pos().x + sz / 2.0, Pos().y - sz / 2.0, sz); } break; case type_minigun: { gdi->RedPen(); gdi->RedBrush(); gdi->Circle(Pos(), 2); gdi->ThickRedPen(); gdi->Line(Pos(), Vector2D(Pos().x, Pos().y - 9)); } break; case type_rocket_launcher: { Vector2D facing(-1,0); m_vecRLVBTrans = WorldTransform(m_vecRLVB, Pos(), facing, facing.Perp(), Vector2D(2.5,2.5)); gdi->RedPen(); gdi->ClosedShape(m_vecRLVBTrans); } break; }//end switch } }
//------------------------- Render --------------------------------------- // //------------------------------------------------------------------------ void CLander::Render(HDC surface) { //draw the vertices for the landers base MoveToEx(surface, (int)m_vecShipVBTrans[0].x, (int)m_vecShipVBTrans[0].y, NULL); for (int vert=1; vert<4; ++vert) { LineTo(surface, (int)m_vecShipVBTrans[vert].x, (int)m_vecShipVBTrans[vert].y); } LineTo(surface, (int)m_vecShipVBTrans[0].x, (int)m_vecShipVBTrans[0].y); //landers top MoveToEx(surface, (int)m_vecShipVBTrans[4].x, (int)m_vecShipVBTrans[4].y, NULL); for (vert=5; vert<12; ++vert) { LineTo(surface, (int)m_vecShipVBTrans[vert].x, (int)m_vecShipVBTrans[vert].y); } //left leg MoveToEx(surface, (int)m_vecShipVBTrans[12].x, (int)m_vecShipVBTrans[12].y, NULL); LineTo(surface, (int)m_vecShipVBTrans[13].x, (int)m_vecShipVBTrans[13].y); LineTo(surface, (int)m_vecShipVBTrans[14].x, (int)m_vecShipVBTrans[14].y); MoveToEx(surface, (int)m_vecShipVBTrans[15].x, (int)m_vecShipVBTrans[15].y, NULL); LineTo(surface, (int)m_vecShipVBTrans[16].x, (int)m_vecShipVBTrans[16].y); MoveToEx(surface, (int)m_vecShipVBTrans[17].x, (int)m_vecShipVBTrans[17].y, NULL); LineTo(surface, (int)m_vecShipVBTrans[18].x, (int)m_vecShipVBTrans[18].y); //right leg MoveToEx(surface, (int)m_vecShipVBTrans[19].x, (int)m_vecShipVBTrans[19].y, NULL); LineTo(surface, (int)m_vecShipVBTrans[20].x, (int)m_vecShipVBTrans[20].y); LineTo(surface, (int)m_vecShipVBTrans[21].x, (int)m_vecShipVBTrans[21].y); MoveToEx(surface, (int)m_vecShipVBTrans[22].x, (int)m_vecShipVBTrans[22].y, NULL); LineTo(surface, (int)m_vecShipVBTrans[23].x, (int)m_vecShipVBTrans[23].y); MoveToEx(surface, (int)m_vecShipVBTrans[24].x, (int)m_vecShipVBTrans[24].y, NULL); LineTo(surface, (int)m_vecShipVBTrans[25].x, (int)m_vecShipVBTrans[25].y); //the burner MoveToEx(surface, (int)m_vecShipVBTrans[26].x, (int)m_vecShipVBTrans[26].y, NULL); for (vert=27; vert<30; ++vert) { LineTo(surface, (int)m_vecShipVBTrans[vert].x, (int)m_vecShipVBTrans[vert].y); } //if the last action was thrust then we need to draw the jet from the burner if (m_bJetOn) { //first transform the verts m_vecJetVBTrans = m_vecJetVB; WorldTransform(m_vecJetVBTrans); MoveToEx(surface, m_vecJetVBTrans[0].x, m_vecJetVBTrans[0].y, NULL); for (int vert=1; vert<m_vecJetVBTrans.size(); ++vert) { LineTo(surface, m_vecJetVBTrans[vert].x, m_vecJetVBTrans[vert].y); } } }
void PointerMotionAction(Graph *graph, XPointerMovedEvent *motionevent) { int sx2, sy2; int sx1, sy1; int button; float x1, y1; float x2, y2; float x, y; /* * get the location of the cursor */ sx2 = motionevent->x; sy2 = motionevent->y; /* * get the button pressed */ button = (motionevent->state & 0xFF00) >> 8; switch (ButtonMode()) { case PINCHMODE: /* * pinch at the cursor location */ WorldTransform(graph, sx2, sy2, &x2, &y2); NBShowCoords((BasicWindow *)graph->frame->text, 0, graph->fontheight, x2, y2); break; case TEXTMODE: /* * if its in text mode then read out the cursor location */ ShowCursorCoords((BasicWindow *)graph->frame->text, 0, graph->fontheight, sx2, sy2); break; case DRAWMODE: /* * If it's in screen coord mode then read out the cursor location. */ switch (button) { case 1: /* draw line */ if (graph->dragx1 != -1) { if (graph->dragx2 != -1) { /* * erase the old drag line from the starting drag * coordinates drag->x1, y1 to the previous end * coordinates drag->x2, y2. */ EraseSuperLine((BasicWindow *)graph, graph->dragx1, graph->dragy1, graph->dragx2, graph->dragy2); } /* * get the world coordinates of the initial drag point */ x1 = graph->dragwx1; y1 = graph->dragwy1; /* * get the world coordinates of the current cursor * location */ WorldTransform(graph, sx2, sy2, &x2, &y2); /* * update the drag coordinates to the current location */ graph->dragx2 = sx2; graph->dragy2 = sy2; /* * display data about the line between the points in the * text window */ ShowSlopeCoords((BasicWindow *)graph->frame->text, 0, graph->fontheight, x1, y1, x2, y2); /* * draw the new drag line */ DrawSuperLine((BasicWindow *)graph, graph->dragx1, graph->dragy1, graph->dragx2, graph->dragy2); } break; } break; case DATAMODE: switch (button) { case 1: /* zoom box */ if (graph->dragx1 != -1) { if (graph->dragx2 != -1) { /* * erase the old drag rectangle */ EraseSuperBox((BasicWindow *)graph, graph->dragx1, graph->dragy1, graph->dragx2, graph->dragy2); } graph->dragx2 = sx2; graph->dragy2 = sy2; /* * draw the new drag rectangle */ DrawSuperBox((BasicWindow *)graph, graph->dragx1, graph->dragy1, graph->dragx2, graph->dragy2); } break; case 2: /* ruler line */ if (graph->dragx1 != -1) { if (graph->dragx2 != -1) { /* * erase the old drag line from the starting drag * coordinates drag->x1, y1 to the previous end * coordinates drag->x2, y2. */ EraseSuperLine((BasicWindow *)graph, graph->dragx1, graph->dragy1, graph->dragx2, graph->dragy2); } /* * get the world coordinates of the initial drag point */ x1 = graph->dragwx1; y1 = graph->dragwy1; if (snapmode) { /* * get the data coordinates closest to the current cursor * location */ Snap(graph, sx2, sy2, &x2, &y2); /* * compute the screen coordinate of the data point */ ScreenTransform(graph, x2, y2, &sx1, &sy1); /* * update the drag coordinates to the current location */ graph->dragx2 = sx1; graph->dragy2 = sy1; } else { /* * get the world coordinates of the current cursor * location */ WorldTransform(graph, sx2, sy2, &x2, &y2); /* * update the drag coordinates to the current location */ graph->dragx2 = sx2; graph->dragy2 = sy2; } /* * display data about the line between the points in the * text window */ ShowSlopeCoords((BasicWindow *)graph->frame->text, 0, graph->fontheight, x1, y1, x2, y2); /* * draw the new drag line */ DrawSuperLine((BasicWindow *)graph, graph->dragx1, graph->dragy1, graph->dragx2, graph->dragy2); } break; case 4: /* * get the data point whose screen x coordinate is closest to the * current cursor location */ Snap(graph, sx2, sy2, &x, &y); /* * compute the screen coordinate of the data point */ ScreenTransform(graph, x, y, &sx1, &sy1); /* * erase the previous line */ EraseSuperLine((BasicWindow *)graph, graph->dragx2, graph->dragy2, graph->dragx2, graph->dragy1); /* * and draw a new line using the x coordinate of the data point * and the y coordinates of the cursor and the data point */ graph->dragx1 = sx2; graph->dragy1 = sy2; graph->dragx2 = sx1; graph->dragy2 = sy1; DrawSuperLine((BasicWindow *)graph, sx1, sy1, sx1, sy2); /* * display the data coordinates in the text window */ NBShowCoords((BasicWindow *)graph->frame->text, 0, graph->fontheight, x, y); break; } break; } }
//------------------------------------Render()-------------------------------------- // //---------------------------------------------------------------------------------- void CController::Render(HDC surface) { if ( hasTrained) { //do not render if running at accelerated speed if (!m_bFastRender) { //keep a record of the old pen m_OldPen = (HPEN)SelectObject(surface, m_GreenPen); //render the mines for (int i=0; i<m_vecObjects.size(); ++i) { if ( m_vecObjects[i].getType() == CCollisionObject::Mine) { SelectObject(surface, m_BluePen); } else if ( m_vecObjects[i].getType() == CCollisionObject::SuperMine) { SelectObject(surface, m_RedPen); } //grab the vertices for the mine shape vector<SPoint> mineVB = m_MineVB; WorldTransform(mineVB, m_vecObjects[i].getPosition()); //draw the mines MoveToEx(surface, (int)mineVB[0].x, (int)mineVB[0].y, NULL); LineTo(surface, (int)mineVB[1].x, (int)mineVB[1].y); LineTo(surface, (int)mineVB[2].x, (int)mineVB[2].y); LineTo(surface, (int)mineVB[3].x, (int)mineVB[3].y); LineTo(surface, (int)mineVB[0].x, (int)mineVB[0].y); LineTo(surface, (int)mineVB[2].x, (int)mineVB[2].y); MoveToEx(surface, (int)mineVB[1].x, (int)mineVB[1].y, NULL); LineTo(surface, (int)mineVB[3].x, (int)mineVB[3].y); } //we want some sweepers displayed in red SelectObject(surface, m_RedPen); //render the sweepers for (int i=0; i<m_vecSweepers.size(); i++) { if(!m_vecSweepers[i].IsActive()) continue; if (i == CParams::iNumElite) { SelectObject(surface, m_OldPen); } //grab the sweeper vertices vector<SPoint> sweeperVB = m_SweeperVB; //transform the vertex buffer m_vecSweepers[i].WorldTransform(sweeperVB); //draw the sweeper left track MoveToEx(surface, (int)sweeperVB[0].x, (int)sweeperVB[0].y, NULL); for (int vert=1; vert<4; ++vert) { LineTo(surface, (int)sweeperVB[vert].x, (int)sweeperVB[vert].y); } LineTo(surface, (int)sweeperVB[0].x, (int)sweeperVB[0].y); //draw the sweeper right track MoveToEx(surface, (int)sweeperVB[4].x, (int)sweeperVB[4].y, NULL); for (int vert=5; vert<8; ++vert) { LineTo(surface, (int)sweeperVB[vert].x, (int)sweeperVB[vert].y); } LineTo(surface, (int)sweeperVB[4].x, (int)sweeperVB[4].y); MoveToEx(surface, (int)sweeperVB[8].x, (int)sweeperVB[8].y, NULL); LineTo(surface, (int)sweeperVB[9].x, (int)sweeperVB[9].y); MoveToEx(surface, (int)sweeperVB[10].x, (int)sweeperVB[10].y, NULL); for (int vert=11; vert<16; ++vert) { LineTo(surface, (int)sweeperVB[vert].x, (int)sweeperVB[vert].y); } } //put the old pen back SelectObject(surface, m_OldPen); } else { PlotStats(surface); } //render the stats string s = "Iteration: " + itos(m_iIterations); TextOut(surface, 5, 0, s.c_str(), s.size()); string s2 = "Progress: " + itos(m_iTicks) + "/" + itos(CParams::iNumTicks) + " ticks"; TextOut(surface, 5, 20, s2.c_str(), s2.size()); } else { string s = "Training..."; TextOut(surface, 5, 0, s.c_str(), s.size()); s = "This generally takes under 10 seconds."; TextOut(surface, 5, 20, s.c_str(), s.size()); hasRendered = true; } }
void WorldManager::init() { struct ModelLoadInfo { char* ModelPath; WCHAR* ShaderPath; WorldTransform transform; }; ModelLoadInfo ModelPath[] = { { "Resource/Model/CMC_MF_01.FBX",L"Resource/Shader/Common.hlsl",{ AS3DVECTOR3(2000.0f,0.0f,0.0f),AS3DVECTOR3(0.0f,0,1.0f),AS3DVECTOR3(0,1,0),AS3DVECTOR3(1.0f,1.0f,1.0f)}},//房子 { "Resource/Model/CMC_CM.FBX",L"Resource/Shader/Common.hlsl",{ AS3DVECTOR3(0.0f,0.0f,0.0f),AS3DVECTOR3(0.0f,0,1.0f),AS3DVECTOR3(0,1,0),AS3DVECTOR3(1.0f,1.0f,1.0f) }},//主要房子 { "Resource/Model/ChaSi.FBX",L"Resource/Shader/Common.hlsl",{ AS3DVECTOR3(-2000.0f,0.0f,0.0f),AS3DVECTOR3(0.0f,1,0.0f),AS3DVECTOR3(0,0,1),AS3DVECTOR3(1.0f,1.0f,1.0f) } },//茶肆 }; // models for (int i = 0; i < sizeof(ModelPath) / sizeof(ModelPath[0]); ++i) { Object* pObject = new Model(ModelPath[i].ModelPath, ModelPath[i].ShaderPath, ModelPath[i].transform); pObject->init(); Objects.push_back(pObject); } //sky { AS3DVECTOR3 scale(10.0f, 10.0f, 10.0f); AS3DVECTOR3 loc(0, 0.0f, 0); AS3DVECTOR3 dir(0.0f, 0.0f, 1.0f); AS3DVECTOR3 up(0.0f, 1.0f, 1.0f); Object* sky = new Sky(WorldTransform(loc, dir, up, scale)); sky->init(); Objects.push_back(sky); } //rain drop ModelLoadInfo RainDropModel[] = { //{ "Resource/Model/CMC_MF_01.FBX",L"Resource/Shader/Common.hlsl",{ XMFLOAT3(2000.0f,0.0f,0.0f),XMFLOAT3(0.0f,0,1.0f),XMFLOAT3(0,1,0),XMFLOAT3(1.0f,1.0f,1.0f)}},//房子 //{ "Resource/Model/CMC_CM.FBX",L"Resource/Shader/Common.hlsl",{ XMFLOAT3(0.0f,0.0f,0.0f),XMFLOAT3(0.0f,0,1.0f),XMFLOAT3(0,1,0),XMFLOAT3(1.0f,1.0f,1.0f) }},//主要房子 //{ "Resource/Model/ChaSi.FBX",L"Resource/Shader/Common.hlsl",{ XMFLOAT3(-2000.0f,0.0f,0.0f),XMFLOAT3(0.0f,1,0.0f),XMFLOAT3(0,0,1),XMFLOAT3(1.0f,1.0f,1.0f) } },//茶肆 { "Resource/Model/RainDrop0.FBX",L"Resource/Shader/RainDrop.hlsl",{ AS3DVECTOR3(0.0f,1000.0f,0.0f),AS3DVECTOR3(0.0f,1,0.0f),AS3DVECTOR3(0,0,1),AS3DVECTOR3(1.0f,1.0f,1.0f) } },//茶肆 }; for (int i = 0; i < sizeof(RainDropModel) / sizeof(RainDropModel[0]); ++i) { RainDrop* pObject = new RainDrop(RainDropModel[i].ModelPath, RainDropModel[i].ShaderPath, RainDropModel[i].transform); pObject->init(); Objects.push_back(pObject); pRainDrop = pObject; } //sphere for test /* for( int row = 1; row < 9; ++row) { AS3DVECTOR3 scale(10.0f, 10.0f, 10.0f); float x = 1500 + row * 300; float z = 2000; float roughness = (row + 1) * 0.1; { AS3DVECTOR3 loc(x, 0.0f, z + 800); AS3DVECTOR3 dir(0.0f, 1.0f, 0.0f); AS3DVECTOR3 up(0.0f, 0.0f, 1.0f); Object* sphereForIBL = new SphereForTest(WorldTransform(loc,dir,up,scale), roughness, AS3DVECTOR3(0.972, 0.960, 0.915));//银子 sphereForIBL->init(); Objects.push_back(sphereForIBL); } { AS3DVECTOR3 loc(x, 0.0f, z + 600); AS3DVECTOR3 dir(0.0f, 0.0f, 1.0f); AS3DVECTOR3 up(0.0f, 1.0f, 0.0f); Object* sphereForIBL = new SphereForTest(WorldTransform(loc, dir, up, scale), roughness, AS3DVECTOR3(1.022, 0.782, 0.344)); //金子 sphereForIBL->init(); Objects.push_back(sphereForIBL); } { AS3DVECTOR3 loc(x, 0.0f, z + 400); AS3DVECTOR3 dir(0.0f, 0.0f, 1.0f); AS3DVECTOR3 up(0.0f, 1.0f, 0.0f); Object* sphereForIBL = new SphereForTest(WorldTransform(loc, dir, up, scale), roughness, AS3DVECTOR3(0.04, 0.04, 0.04)); //非金属 sphereForIBL->init(); Objects.push_back(sphereForIBL); } { AS3DVECTOR3 loc(x, 0.0f, z + 200); AS3DVECTOR3 dir(0.0f, 0.0f, 1.0f); AS3DVECTOR3 up(0.0f, 1.0f, 0.0f); Object* sphereForIBL = new SphereForTest(WorldTransform(loc, dir, up, scale), roughness, AS3DVECTOR3(0.562, 0.565, 0.578)); //铁 sphereForIBL->init(); Objects.push_back(sphereForIBL); } } */ //conerain { AS3DVECTOR3 scale(100.0f, 100.0f, 500.0f); float x = 2000; float z = 2000; { AS3DVECTOR3 loc(x, 0.0f, z + 800); AS3DVECTOR3 dir(0.0f, 1.0f, 0.0f); AS3DVECTOR3 up(0.0f, 0.0f, 1.0f); Object* conerain = new ConeRain(WorldTransform(loc, dir, up, scale), 0); conerain->init(); pRain = static_cast<ConeRain*>(conerain); Objects.push_back(conerain); } } //init compute shader test module pComputeShaderTest = new ComputeShaderTestModule(); }
//----------------------- TestSensors ------------------------------------ // // This function checks for any intersections between the sweeper's // sensors and the objects in its environment //------------------------------------------------------------------------ void CMinesweeper::TestSensors(vector<SPoint> &objects) { m_bCollided = false; //first we transform the sensors into world coordinates m_tranSensors = m_Sensors; WorldTransform(m_tranSensors, 1); //scale is 1 //flush the sensors m_vecdSensors.clear(); m_vecFeelers.clear(); //now to check each sensor against the objects in the world for (int sr=0; sr<m_tranSensors.size(); ++sr) { bool bHit = false; double dist = 0; for (int seg=0; seg<objects.size(); seg+=2) { if (LineIntersection2D(SPoint(m_vPosition.x, m_vPosition.y), m_tranSensors[sr], objects[seg], objects[seg+1], dist)) { bHit = true; break; } } if (bHit) { m_vecdSensors.push_back(dist); //implement very simple collision detection if (dist < CParams::dCollisionDist) { m_bCollided = true; } } else { m_vecdSensors.push_back(-1); } //check how many times the minesweeper has visited the cell //at the current position int HowOften = m_MemoryMap.TicksLingered(m_tranSensors[sr].x, m_tranSensors[sr].y); //Update the memory info according to HowOften. The maximum //value is 1 (because we want all the inputs into the //ANN to be scaled between -1 < n < 1) if (HowOften == 0) { m_vecFeelers.push_back(-1); continue; } if (HowOften < 10) { m_vecFeelers.push_back(0); continue; } if (HowOften < 20) { m_vecFeelers.push_back(0.2); continue; } if (HowOften < 30) { m_vecFeelers.push_back(0.4); continue; } if (HowOften < 50) { m_vecFeelers.push_back(0.6); continue; } if (HowOften < 80) { m_vecFeelers.push_back(0.8); continue; } m_vecFeelers.push_back(1); }//next sensor }
//----------------------- TestSensors ------------------------------------ // // This function checks for any intersections between the sweeper's // sensors and the objects in its environment //------------------------------------------------------------------------ void CMinesweeper::TestSensors(vector<SPoint> &objects) { m_bCollided = false; //first we transform the sensors into world coordinates m_tranSensors = m_Sensors; WorldTransform(m_tranSensors, 1); //scale is 1 //flush the sensors m_vecdSensors.clear(); m_vecFeelers.clear(); //now to check each sensor against the objects in the world for (int sr=0; sr<m_tranSensors.size(); ++sr) { bool bHit = false; double dist = 0; for (int seg=0; seg<objects.size(); seg+=2) { if (LineIntersection2D(SPoint(m_vPosition.x, m_vPosition.y), m_tranSensors[sr], objects[seg], objects[seg+1], dist)) { bHit = true; break; } } if (bHit) { m_vecdSensors.push_back(dist); //implement very simple collision detection if (dist < CParams::dCollisionDist) { m_bCollided = true; } } else { m_vecdSensors.push_back(-1); } }//next sensor if (!m_bCollided) { if (m_vPosition.y < 15) { m_bCollided = true; return; } if (m_vPosition.y > 170) { m_bCollided = true; return; } if (m_vPosition.y < 100) { if (m_vPosition.x > 230) { m_bCollided = true; return; } if (m_vPosition.x < 150) { m_bCollided = true; return; } } } }