// drawPlayerStats //--------------------------------------------------------------------------- // Purpose: //--------------------------------------------------------------------------- void RankView::drawPlayerStats(const Surface &dest) { char statBuf[256]; iXY offset; iXY flagOffset; //int index; Stats::setSortOrder( _stats_sort_order_game_type ); Stats::Initialize(); char playerFlagIndex; short playerKills; short playerLosses; short playerTotalPoints; short playerObjectives; char *playerName; int playerStatsDisplayType; int numPlayers = Stats::getActivePlayers(); //int offsetRunner = getScrollBarTopItem() - numPlayers; // Scoot through the list to the first visible player, since we can't seek to an index yet. //while(offsetRunner > 0) //{ // offsetRunner--; // Stats::GetPlayerStats(playerFlagName, &playerKills, &playerLosses, &playerTotalPoints, &playerName); //} // //setScrollBarViewableCount(viewableMessageCount); //setScrollBarItemCount(numPlayers); // //int numToDraw = (viewableMessageCount < numPlayers) ? viewableMessageCount : numPlayers; // //if(numPlayers < viewableMessageCount) //{ // setScrollBarTopItem(numPlayers); //} else //{ // setScrollBarTopItem(numPlayers - viewableMessageCount); //} for (int i = 0; i < numPlayers; i++) { offset.x = 2; flagOffset.x = offset.x + 160; offset.y = 40 + i * (CHAR_YPIX + (UNIT_FLAGS_SURFACE.getPixY() - CHAR_YPIX) ); flagOffset.y = (40 - (UNIT_FLAGS_SURFACE.getPixY() - CHAR_YPIX)/2 ) + i * UNIT_FLAGS_SURFACE.getPixY(); //index = getScrollBarTopItem() + i; //assert(index < numPlayers); Stats::GetPlayerStats(&playerFlagIndex, &playerKills, &playerLosses, &playerTotalPoints, &playerObjectives, &playerName, &playerStatsDisplayType); // Add player flag name. sprintf(statBuf, "%-20s%10i%7i%6i%10i", playerName, playerKills, playerLosses, playerTotalPoints, playerObjectives ); if (statBuf != 0) { PIX color; switch( playerStatsDisplayType ) { case _stats_display_type_local_player : color = Color::blue; break; case _stats_display_type_ally : color = Color::orange; break; case _stats_display_type_default : color = Color::white; break; } // ** switch dest.bltString( offset.x, offset.y, statBuf, color ); } UNIT_FLAGS_SURFACE.setFrame( playerFlagIndex ); UNIT_FLAGS_SURFACE.blt( dest, flagOffset.x, flagOffset.y ); } } // end RankView::drawPlayerStats
/** * Draws the view of all the facilities in the base, connectors * between them and crafts landed in hangars. */ void BaseView::draw() { Surface::draw(); // Draw grid squares for (int x = 0; x < BASE_SIZE; ++x) { for (int y = 0; y < BASE_SIZE; ++y) { Surface *frame = _texture->getFrame(0); frame->setX(x * GRID_SIZE); frame->setY(y * GRID_SIZE); frame->blit(this); } } std::vector<Craft*>::iterator craft = _base->getCrafts()->begin(); for (std::vector<BaseFacility*>::iterator i = _base->getFacilities()->begin(); i != _base->getFacilities()->end(); ++i) { // Draw facility shape int num = 0; for (int y = (*i)->getY(); y < (*i)->getY() + (*i)->getRules()->getSize(); ++y) { for (int x = (*i)->getX(); x < (*i)->getX() + (*i)->getRules()->getSize(); ++x) { Surface *frame; int outline = std::max((*i)->getRules()->getSize() * (*i)->getRules()->getSize(), 3); if ((*i)->getBuildTime() == 0) frame = _texture->getFrame((*i)->getRules()->getSpriteShape() + num); else frame = _texture->getFrame((*i)->getRules()->getSpriteShape() + num + outline); frame->setX(x * GRID_SIZE); frame->setY(y * GRID_SIZE); frame->blit(this); num++; } } } for (std::vector<BaseFacility*>::iterator i = _base->getFacilities()->begin(); i != _base->getFacilities()->end(); ++i) { // Draw connectors if ((*i)->getBuildTime() == 0) { // Facilities to the right int x = (*i)->getX() + (*i)->getRules()->getSize(); if (x < BASE_SIZE) { for (int y = (*i)->getY(); y < (*i)->getY() + (*i)->getRules()->getSize(); ++y) { if (_facilities[x][y] != 0 && _facilities[x][y]->getBuildTime() == 0) { Surface *frame = _texture->getFrame(7); frame->setX(x * GRID_SIZE - GRID_SIZE / 2); frame->setY(y * GRID_SIZE); frame->blit(this); } } } // Facilities to the bottom int y = (*i)->getY() + (*i)->getRules()->getSize(); if (y < BASE_SIZE) { for (int subX = (*i)->getX(); subX < (*i)->getX() + (*i)->getRules()->getSize(); ++subX) { if (_facilities[subX][y] != 0 && _facilities[subX][y]->getBuildTime() == 0) { Surface *frame = _texture->getFrame(8); frame->setX(subX * GRID_SIZE); frame->setY(y * GRID_SIZE - GRID_SIZE / 2); frame->blit(this); } } } } } for (std::vector<BaseFacility*>::iterator i = _base->getFacilities()->begin(); i != _base->getFacilities()->end(); ++i) { // Draw facility graphic int num = 0; for (int y = (*i)->getY(); y < (*i)->getY() + (*i)->getRules()->getSize(); ++y) { for (int x = (*i)->getX(); x < (*i)->getX() + (*i)->getRules()->getSize(); ++x) { if ((*i)->getRules()->getSize() == 1) { Surface *frame = _texture->getFrame((*i)->getRules()->getSpriteFacility() + num); frame->setX(x * GRID_SIZE); frame->setY(y * GRID_SIZE); frame->blit(this); } num++; } } // Draw crafts (*i)->setCraft(0); if ((*i)->getBuildTime() == 0 && (*i)->getRules()->getCrafts() > 0) { if (craft != _base->getCrafts()->end()) { if ((*craft)->getStatus() != "STR_OUT") { Surface *frame = _texture->getFrame((*craft)->getRules()->getSprite() + 33); frame->setX((*i)->getX() * GRID_SIZE + ((*i)->getRules()->getSize() - 1) * GRID_SIZE / 2 + 2); frame->setY((*i)->getY() * GRID_SIZE + ((*i)->getRules()->getSize() - 1) * GRID_SIZE / 2 - 4); frame->blit(this); (*i)->setCraft(*craft); } ++craft; } } // Draw time remaining if ((*i)->getBuildTime() > 0) { Text *text = new Text(GRID_SIZE * (*i)->getRules()->getSize(), 16, 0, 0); text->setPalette(getPalette()); text->initText(_big, _small, _lang); text->setX((*i)->getX() * GRID_SIZE); text->setY((*i)->getY() * GRID_SIZE + (GRID_SIZE * (*i)->getRules()->getSize() - 16) / 2); text->setBig(); std::ostringstream ss; ss << (*i)->getBuildTime(); text->setAlign(ALIGN_CENTER); text->setColor(_cellColor); text->setText(ss.str()); text->blit(this); delete text; } } }
void bakersc3Starbucks::update(){ (*texture).update(*mySurface, mySurface->getBounds()); }
void HeightFieldSurfaceClipImageFilter::GenerateData() { const Image *inputImage = this->GetInput( 0 ); const Image *outputImage = this->GetOutput(); m_InputTimeSelector->SetInput( inputImage ); m_OutputTimeSelector->SetInput( outputImage ); Image::RegionType outputRegion = outputImage->GetRequestedRegion(); const TimeGeometry *outputTimeGeometry = outputImage->GetTimeGeometry(); const TimeGeometry *inputTimeGeometry = inputImage->GetTimeGeometry(); ScalarType timeInMS; int timestep = 0; int tstart = outputRegion.GetIndex( 3 ); int tmax = tstart + outputRegion.GetSize( 3 ); for (unsigned int i = 1; i < this->GetNumberOfInputs(); ++i) { Surface *inputSurface = const_cast< Surface * >( dynamic_cast< Surface * >( itk::ProcessObject::GetInput( i ) ) ); if ( !outputImage->IsInitialized() || inputSurface == NULL ) return; MITK_INFO<<"Plane: "<<i; MITK_INFO << "Clipping: Start\n"; //const Geometry2D *clippingGeometryOfCurrentTimeStep = NULL; int t; for( t = tstart; t < tmax; ++t ) { timeInMS = outputTimeGeometry->TimeStepToTimePoint( t ); timestep = inputTimeGeometry->TimePointToTimeStep( timeInMS ); m_InputTimeSelector->SetTimeNr( timestep ); m_InputTimeSelector->UpdateLargestPossibleRegion(); m_OutputTimeSelector->SetTimeNr( t ); m_OutputTimeSelector->UpdateLargestPossibleRegion(); // Compose IndexToWorld transform of image with WorldToIndexTransform of // clipping data for conversion from image index space to plane index space AffineTransform3D::Pointer planeWorldToIndexTransform = AffineTransform3D::New(); inputSurface->GetGeometry( t )->GetIndexToWorldTransform() ->GetInverse( planeWorldToIndexTransform ); AffineTransform3D::Pointer imageToPlaneTransform = AffineTransform3D::New(); imageToPlaneTransform->SetIdentity(); imageToPlaneTransform->Compose( inputTimeGeometry->GetGeometryForTimeStep( t )->GetIndexToWorldTransform() ); imageToPlaneTransform->Compose( planeWorldToIndexTransform ); MITK_INFO << "Accessing ITK function...\n"; if(i==1) { AccessByItk_3( m_InputTimeSelector->GetOutput(), _InternalComputeClippedImage, this, inputSurface->GetVtkPolyData( t ), imageToPlaneTransform ); } else { mitk::Image::Pointer extensionImage = m_OutputTimeSelector->GetOutput()->Clone(); AccessByItk_3( extensionImage, _InternalComputeClippedImage, this, inputSurface->GetVtkPolyData( t ), imageToPlaneTransform ); } if (m_ClippingMode == CLIPPING_MODE_MULTIPLANE) m_MultiPlaneValue = m_MultiPlaneValue*2; } } m_TimeOfHeaderInitialization.Modified(); }
bool loadSurfacetoVram(Surface & surface, GLuint & tex_id, Rect & tex_rect) { int neww = surface.w; int newh = surface.h; // Check that the image's width is a power of 2 if ( (surface.w & (surface.w - 1)) != 0 ) { neww = 1 << (int)ceil(log2(surface.w)); } // Also check if the height is a power of 2 if ( (surface.h & (surface.h - 1)) != 0 ) { newh = 1 << (int)ceil(log2(surface.h)); } tex_rect.w = neww; tex_rect.h = newh; /* Resize if needed */ if (neww !=surface.w || newh !=surface.h) { Surface q; q.set(new tRGBA [neww*newh], neww, newh); memset(q.pixels, 0, neww*newh*sizeof(tRGBA)); tRGBA * src = surface.pixels; tRGBA * dst = q.pixels; for (int y=0; y<surface.h; ++y) { for (int x=0; x<surface.w; ++x) { *dst = *src; ++dst; ++src; } dst+=neww - surface.w; } surface.clean(); surface = q; } // Have OpenGL generate a texture object handle for us glGenTextures( 1, &tex_id ); if (glGetError()) cout << "GL error" << glGetError() << endl; // Bind the texture object glActiveTexture(GL_TEXTURE0); glBindTexture( GL_TEXTURE_2D, tex_id ); // Set the texture's stretching properties glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); // Edit the texture object's image data using the information SDL_Surface gives us glTexImage2D( GL_TEXTURE_2D, 0, 4, surface.w, surface.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface.pixels ); return true; }
bool insideSurfaceClosest(const Point3D &pTest, const Surface &s, const SpacialHash &faceHash, ClosestPointInfo *inf, float stopBelow, bool allowQuickTest){ if (inf) inf->type = DIST_TYPE_INVALID; // quick bounding box test if (allowQuickTest){ if (pTest.x < s.pMin.x || pTest.x > s.pMax.x || pTest.y < s.pMin.y || pTest.y > s.pMax.y || pTest.z < s.pMin.z || pTest.z > s.pMax.z){ return false; } } ClosestPointInfo localClosestInf; if (!inf) inf = &localClosestInf; float dist = getClosestPoint(inf, pTest, s, faceHash, stopBelow); if (dist < stopBelow){ // optimise for dodec return true; } // vector to point on surface Vector3D v; v.difference(pTest, inf->pClose); v.norm(); if (inf->type == FACE){ // face test Vector3D n; s.getTriangleNormal(&n, inf->triangle); double dt = n.dot(v); return dt <= 0; } else if (inf->type == EDGE){ // edge test const Surface::Triangle *tri = &s.triangles.index(inf->triangle); // edge will be between vertices v[num] and v[(num+1)%3] int e[2]; e[0] = tri->v[inf->num]; e[1] = tri->v[(inf->num+1)%3]; int neigh = findNeighbour(s, *tri, e); if (neigh >= 0){ // make a plane for one of the triangles Vector3D n1; s.getTriangleNormal(&n1, inf->triangle); Point3D p1 = s.vertices.index(e[0]).p; Plane pl1; pl1.assign(n1, p1); // get the point from the other triangle which is not part of edge const Surface::Triangle *tri2 = &s.triangles.index(neigh); for (int i = 0; i < 3; i++){ if (tri2->v[i] != e[0] && tri2->v[i] != e[1]) break; } CHECK_DEBUG0(i != 3); Point3D p2 = s.vertices.index(e[1]).p; // get signed distance to plane float dist = pl1.dist(p2); // need normal for second triangle Vector3D n2; s.getTriangleNormal(&n2, neigh); if (dist <= 0.0f){ // faces form convex spike, back facing to both return v.dot(n1) <= 0 && v.dot(n2) <= 0; } else{ // faces form concavity, back facing to either return v.dot(n1) <= 0 || v.dot(n2) <= 0; } } else{ OUTPUTINFO("HHHHHMMMMMMM loose edge\n"); return false; // only one triangle on edge - use face ?? } } else{// if (minType == VERTEX) // chosen triangle const Surface::Triangle *tri = &s.triangles.index(inf->triangle); // chosen vertex int vI = tri->v[inf->num]; Vector3D n; s.getVertexNormal(&n, vI); return n.dot(v) <= 0; /* // get all faces Array<int> tris; s.findNeighbours(&tris, vI, inf->triangle); // behind test for all faces int numTri = tris.getSize(); for (int i = 0; i < numTri; i++){ Vector3D n; s.getTriangleNormal(&n, tris.index(i)); double dt = n.dot(v); if (dt > 0) return false; } // must be behind all return true;*/ } }
glm::vec3 Ray::trace(glm::vec3 rayOrig, glm::vec3 rayDir, float depth, int bounces) { // ---------------------------------------------- // Compare ray with every object in scene // Find the smallest distance to an object // ---------------------------------------------- float t0, t1, tNear = INF; Surface *s = nullptr; // Pointer to closest object for (auto &o : *scene->objects) { if (o->intersects(rayOrig, rayDir, t0, t1)) { if (t0 < tNear) { tNear = t0; s = o; } } } // ---------------------------------------------- // We have found an object // ---------------------------------------------- if (s != nullptr) { // If the closes object is a light, return light color if (s->isLight()) return s->color; // p is the point of intersection glm::vec3 directIllumination (0.0); glm::vec3 indirectIllumination (0.0); glm::vec3 p = rayOrig + rayDir * tNear; glm::vec3 normal = s->getNormal(p); glm::vec3 r = rayDir - 2 * glm::dot(rayDir, normal) * normal; // reflected direction // ---------------------------------------------- // Indirect illumination // If the object is reflective or refractive, calculate new ray(s) // ---------------------------------------------- if (s->isRefractive()) { // If the object is refractive, create refractive ray // Calculate new refractive ray // Need to do a flip if we are inside the object //glm::vec3 n = normal; //const float index = 1/1.5; //Sphere *temp = static_cast <Sphere*>(s); //if (glm::length(temp->getCenter() - p) < temp->getRadius()) n = -n; //glm::vec3 t = glm::normalize(glm::refract(rayDir, n, index)); Ray ray(scene); //indirectIllumination += ray.trace(p, t, depth, bounces); // Calculate reflective ray for both refracive and reflective materials // Trace reflective ray indirectIllumination += ray.trace(p, r, depth, bounces++); indirectIllumination /= (float)bounces; } // ---------------------------------------------- // Indirect illumination // Material is diffuse, do Monte Carlo stuff // ---------------------------------------------- else if(bounces < scene->maxBounces) { // Russian roulette float r1 = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); float r2 = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); float absorption = 0.5; // Ray is scattered if (static_cast <float> (rand()) / static_cast <float> (RAND_MAX) > absorption) { // New random direction over hemisphere float inclination = 2.0 * M_PI * r1; float azimuth = acos(2.0 * r2 - 1.0); float u = cos(azimuth); float x = sqrt(1 - u * u) * cos(inclination); float y = sqrt(1 - u * u) * sin(inclination); float z = u; // New direction. If it points the wrong way, change direction glm::vec3 newDir(x, y, z); if (glm::dot(normal, newDir) < 0) newDir = -newDir; // pdf - over hemisphere // cos - relationship between normal and the direction reflected light will come from // BRDF - Lambertian or Oren-Nayar float pdf = 1.0 / 2.0 * M_PI; float cos = glm::dot(normal, newDir); float BRDF = s->isOren() ? OrenNayarBRDF(newDir, glm::normalize(-scene->cameraDir), normal) : glm::dot(normal, newDir); Ray ray(scene); indirectIllumination = ray.trace(p, newDir, depth, bounces++) * cos * BRDF / pdf; indirectIllumination /= ((1 - absorption)); } } // ---------------------------------------------- // Direct illumination // Calculate shadow rays // ---------------------------------------------- int shadowRays = 4; for (int i = 0; i < scene->lights->size(); i++) { Sphere *l = scene->lights->at(i); // Pointer to current light glm::vec3 tempColor(0.0); // Total color per light float unobstructedRays = 0.0; for (int j = 0; j < shadowRays; j++) { bool shaded = false; glm::vec3 pDir = findRandomDirection(p, l); // Vector towards light float dist = glm::length(pDir); pDir = glm::normalize(pDir); // Shoot shadow ray(s) to random position on light (not random now though) for (auto &o : *scene->objects) if (o->intersects(p, pDir, t0, t1)) if (t0 < dist && !o->isLight()) shaded = true; if (!shaded) { unobstructedRays++; float lightIntensity = 2.2 * 1.0/255.0; float BRDF = s->isOren() ? OrenNayarBRDF(pDir, glm::normalize(-scene->cameraDir), normal) : glm::dot(normal, pDir); // TODO: N(light) must be calculated properly // radianceTransfer = dot(N(object), shadowRay) * dot(N(light), -shadowRay) float radianceTransfer = glm::dot(normal, pDir) * glm::dot(-pDir, -pDir); float pdfk = 2.0 * M_PI * l->getRadius() * l->getRadius(); // pdf over sphere (lights are halved spheres) float pdfyk = 0.5; // Chance to pick one of the light sources // Direct illumination = light * BRDF * radiance transfer / pdfk * pdfyk tempColor += l->color * lightIntensity * BRDF * radianceTransfer / (pdfk * pdfyk) * s->color; } } directIllumination += tempColor * (1.0f/(float)shadowRays); } // ---------------------------------------------- // Add direct and indirect light and return color // ---------------------------------------------- return (indirectIllumination * 2.0 + directIllumination / M_PI); } // Didn't find any object that intersects return glm::vec3(0.0, 0.0, 0.0); }
/** * Draws all the characters in the text with a really * nasty complex gritty text rendering algorithm logic stuff. */ void Text::draw() { Surface::draw(); if (_text.empty() || _font == 0) { return; } // Show text borders for debugging if (Options::getBool("debugUi")) { SDL_Rect r; r.w = getWidth(); r.h = getHeight(); r.x = 0; r.y = 0; this->drawRect(&r, 5); r.w-=2; r.h-=2; r.x++; r.y++; this->drawRect(&r, 0); } int x = 0, y = 0, line = 0, height = 0; Font *font = _font; int color = _color; std::wstring *s = &_text; for (std::vector<int>::iterator i = _lineHeight.begin(); i != _lineHeight.end(); ++i) { height += *i; } switch (_valign) { case ALIGN_TOP: y = 0; break; case ALIGN_MIDDLE: y = (int)ceil((getHeight() - height) / 2.0); break; case ALIGN_BOTTOM: y = getHeight() - height; break; } x = getLineX(line); if (_wrap) { s = &_wrappedText; } // Set up text color int mul = 1; if (_contrast) { mul = 3; } // Set up text direction int dir = 1; if (_lang->getTextDirection() == DIRECTION_RTL) { dir = -1; } // Invert text by inverting the font palette on index 3 (font palettes use indices 1-5) int mid = _invert ? 3 : 0; // Draw each letter one by one for (std::wstring::iterator c = s->begin(); c != s->end(); ++c) { if (Font::isSpace(*c)) { x += dir * font->getCharSize(*c).w; } else if (Font::isLinebreak(*c)) { line++; y += font->getCharSize(*c).h; x = getLineX(line); if (*c == L'\x02') { font = _small; } } else if (*c == L'\x01') { color = (color == _color ? _color2 : _color); } else { if (dir < 0) x += dir * font->getCharSize(*c).w; Surface* chr = font->getChar(*c); chr->setX(x); chr->setY(y); ShaderDraw<PaletteShift>(ShaderSurface(this, 0, 0), ShaderCrop(chr), ShaderScalar(color), ShaderScalar(mul), ShaderScalar(mid)); if (dir > 0) x += dir * font->getCharSize(*c).w; } } }
bool AffineInteractor3D ::ExecuteAction( Action *action, StateEvent const *stateEvent ) { bool ok = false; // Get data object BaseData *data = m_DataNode->GetData(); if ( data == NULL ) { MITK_ERROR << "No data object present!"; return ok; } // Get Event and extract renderer const Event *event = stateEvent->GetEvent(); BaseRenderer *renderer = NULL; vtkRenderWindow *renderWindow = NULL; vtkRenderWindowInteractor *renderWindowInteractor = NULL; vtkRenderer *currentVtkRenderer = NULL; vtkCamera *camera = NULL; if ( event != NULL ) { renderer = event->GetSender(); if ( renderer != NULL ) { renderWindow = renderer->GetRenderWindow(); if ( renderWindow != NULL ) { renderWindowInteractor = renderWindow->GetInteractor(); if ( renderWindowInteractor != NULL ) { currentVtkRenderer = renderWindowInteractor ->GetInteractorStyle()->GetCurrentRenderer(); if ( currentVtkRenderer != NULL ) { camera = currentVtkRenderer->GetActiveCamera(); } } } } } // Check if we have a DisplayPositionEvent const DisplayPositionEvent *dpe = dynamic_cast< const DisplayPositionEvent * >( stateEvent->GetEvent() ); if ( dpe != NULL ) { m_CurrentPickedPoint = dpe->GetWorldPosition(); m_CurrentPickedDisplayPoint = dpe->GetDisplayPosition(); } // Get the timestep to also support 3D+t int timeStep = 0; ScalarType timeInMS = 0.0; if ( renderer != NULL ) { timeStep = renderer->GetTimeStep( data ); timeInMS = renderer->GetTime(); } // If data is an mitk::Surface, extract it Surface *surface = dynamic_cast< Surface * >( data ); vtkPolyData *polyData = NULL; if ( surface != NULL ) { polyData = surface->GetVtkPolyData( timeStep ); // Extract surface normal from surface (if existent, otherwise use default) vtkPointData *pointData = polyData->GetPointData(); if ( pointData != NULL ) { vtkDataArray *normal = polyData->GetPointData()->GetVectors( "planeNormal" ); if ( normal != NULL ) { m_ObjectNormal[0] = normal->GetComponent( 0, 0 ); m_ObjectNormal[1] = normal->GetComponent( 0, 1 ); m_ObjectNormal[2] = normal->GetComponent( 0, 2 ); } } } // Get geometry object m_Geometry = data->GetGeometry( timeStep ); // Make sure that the data (if time-resolved) has enough entries; // if not, create the required extra ones (empty) data->Expand( timeStep+1 ); switch (action->GetActionId()) { case AcDONOTHING: ok = true; break; case AcCHECKOBJECT: { // Re-enable VTK interactor (may have been disabled previously) if ( renderWindowInteractor != NULL ) { renderWindowInteractor->Enable(); } // Check if we have a DisplayPositionEvent const DisplayPositionEvent *dpe = dynamic_cast< const DisplayPositionEvent * >( stateEvent->GetEvent() ); if ( dpe == NULL ) { ok = true; break; } // Check if an object is present at the current mouse position DataNode *pickedNode = dpe->GetPickedObjectNode(); StateEvent *newStateEvent; if ( pickedNode == m_DataNode ) { // Yes: object will be selected newStateEvent = new StateEvent( EIDYES ); } else { // No: back to start state newStateEvent = new StateEvent( EIDNO ); } this->HandleEvent( newStateEvent ); ok = true; break; } case AcDESELECTOBJECT: { // Color object white m_DataNode->SetColor( 1.0, 1.0, 1.0 ); RenderingManager::GetInstance()->RequestUpdateAll(); // Colorize surface / wireframe as inactive this->ColorizeSurface( polyData, m_CurrentPickedPoint, -1.0 ); ok = true; break; } case AcSELECTPICKEDOBJECT: { // Color object red m_DataNode->SetColor( 1.0, 0.0, 0.0 ); RenderingManager::GetInstance()->RequestUpdateAll(); // Colorize surface / wireframe dependend on distance from picked point this->ColorizeSurface( polyData, m_CurrentPickedPoint, 0.0 ); ok = true; break; } case AcINITMOVE: { // Disable VTK interactor until MITK interaction has been completed if ( renderWindowInteractor != NULL ) { renderWindowInteractor->Disable(); } // Check if we have a DisplayPositionEvent const DisplayPositionEvent *dpe = dynamic_cast< const DisplayPositionEvent * >( stateEvent->GetEvent() ); if ( dpe == NULL ) { ok = true; break; } //DataNode *pickedNode = dpe->GetPickedObjectNode(); m_InitialPickedPoint = m_CurrentPickedPoint; m_InitialPickedDisplayPoint = m_CurrentPickedDisplayPoint; if ( currentVtkRenderer != NULL ) { vtkInteractorObserver::ComputeDisplayToWorld( currentVtkRenderer, m_InitialPickedDisplayPoint[0], m_InitialPickedDisplayPoint[1], 0.0, //m_InitialInteractionPickedPoint[2], m_InitialPickedPointWorld ); } // Make deep copy of current Geometry3D of the plane data->UpdateOutputInformation(); // make sure that the Geometry is up-to-date m_OriginalGeometry = static_cast< Geometry3D * >( data->GetGeometry( timeStep )->Clone().GetPointer() ); ok = true; break; } case AcMOVE: { // Check if we have a DisplayPositionEvent const DisplayPositionEvent *dpe = dynamic_cast< const DisplayPositionEvent * >( stateEvent->GetEvent() ); if ( dpe == NULL ) { ok = true; break; } if ( currentVtkRenderer != NULL ) { vtkInteractorObserver::ComputeDisplayToWorld( currentVtkRenderer, m_CurrentPickedDisplayPoint[0], m_CurrentPickedDisplayPoint[1], 0.0, //m_InitialInteractionPickedPoint[2], m_CurrentPickedPointWorld ); } Vector3D interactionMove; interactionMove[0] = m_CurrentPickedPointWorld[0] - m_InitialPickedPointWorld[0]; interactionMove[1] = m_CurrentPickedPointWorld[1] - m_InitialPickedPointWorld[1]; interactionMove[2] = m_CurrentPickedPointWorld[2] - m_InitialPickedPointWorld[2]; if ( m_InteractionMode == INTERACTION_MODE_TRANSLATION ) { Point3D origin = m_OriginalGeometry->GetOrigin(); Vector3D transformedObjectNormal; data->GetGeometry( timeStep )->IndexToWorld( m_ObjectNormal, transformedObjectNormal ); data->GetGeometry( timeStep )->SetOrigin( origin + transformedObjectNormal * (interactionMove * transformedObjectNormal) ); } else if ( m_InteractionMode == INTERACTION_MODE_ROTATION ) { if ( camera ) { vtkFloatingPointType vpn[3]; camera->GetViewPlaneNormal( vpn ); Vector3D viewPlaneNormal; viewPlaneNormal[0] = vpn[0]; viewPlaneNormal[1] = vpn[1]; viewPlaneNormal[2] = vpn[2]; Vector3D rotationAxis = itk::CrossProduct( viewPlaneNormal, interactionMove ); rotationAxis.Normalize(); int *size = currentVtkRenderer->GetSize(); double l2 = (m_CurrentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) * (m_CurrentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) + (m_CurrentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]) * (m_CurrentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]); double rotationAngle = 360.0 * sqrt(l2/(size[0]*size[0]+size[1]*size[1])); // Use center of data bounding box as center of rotation Point3D rotationCenter = m_OriginalGeometry->GetCenter();; // Reset current Geometry3D to original state (pre-interaction) and // apply rotation RotationOperation op( OpROTATE, rotationCenter, rotationAxis, rotationAngle ); Geometry3D::Pointer newGeometry = static_cast< Geometry3D * >( m_OriginalGeometry->Clone().GetPointer() ); newGeometry->ExecuteOperation( &op ); mitk::TimeSlicedGeometry::Pointer timeSlicedGeometry = data->GetTimeSlicedGeometry(); if (timeSlicedGeometry.IsNotNull()) { timeSlicedGeometry->SetGeometry3D( newGeometry, timeStep ); } } } RenderingManager::GetInstance()->RequestUpdateAll(); ok = true; break; } default: return Superclass::ExecuteAction( action, stateEvent ); } return ok; }
//------------------------------------------------------------------------------ //-------------------------------------- // Object proper... //-------------------------------------- // Surface* Surface::create(HWND io_clientWnd, const Int32 in_width, const Int32 in_height) { // Must return a new OpenGL::Surface* of resolution closest to in_w/h. // Should also activate the device. // AssertFatal(io_clientWnd != NULL, "No client window handle"); Surface* pRetSurf = new Surface; #ifndef DEBUG BOOL test = TRUE; bool found = false; UInt32 modeNum = 0; DEVMODE devMode; while (test == TRUE) { memset(&devMode, 0, sizeof(devMode)); devMode.dmSize = sizeof(devMode); test = EnumDisplaySettings(NULL, modeNum, &devMode); if (devMode.dmPelsWidth == (UInt32)in_width && devMode.dmPelsHeight == (UInt32)in_height) { found = true; } modeNum++; } if (found == false) { delete pRetSurf; return NULL; } // Change the window position AssertMessage(false, avar("Changing window style (%d, %d)", in_width, in_height)); GetWindowRect(io_clientWnd, &pRetSurf->m_oldWindowRect); LONG style = GetWindowLong(io_clientWnd, GWL_STYLE); style &= ~(WS_CAPTION | WS_SYSMENU | WS_THICKFRAME); SetWindowLong(io_clientWnd, GWL_STYLE, style); LONG exStyle = GetWindowLong(io_clientWnd, GWL_EXSTYLE); exStyle |= WS_EX_TOPMOST; SetWindowLong(io_clientWnd, GWL_EXSTYLE, exStyle); BOOL posSuccess = SetWindowPos(io_clientWnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); AssertFatal(posSuccess == TRUE, "Error setting pos"); // Annnnd, set the new display mode. Desktop icons? // memset(&devMode, 0, sizeof(devMode)); devMode.dmSize = sizeof(devMode); devMode.dmPelsWidth = in_width; devMode.dmPelsHeight = in_height; devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; #if 1 AssertMessage(false, avar("Changing display settings: (%d, %d)", devMode.dmPelsWidth, devMode.dmPelsHeight)); ChangeDisplaySettings(&devMode, CDS_FULLSCREEN); VidModeChecker::sm_theInstance.changedDisplaySettings(); #endif SetForegroundWindow(io_clientWnd); posSuccess = SetWindowPos(io_clientWnd, HWND_TOPMOST, 0, 0, in_width, in_height, SWP_FRAMECHANGED); AssertFatal(posSuccess == TRUE, "Error setting pos"); pRetSurf->m_windowStyleChanged = true; #endif pRetSurf->m_hWnd = io_clientWnd; pRetSurf->m_hDC = GetDC(pRetSurf->m_hWnd); if (pRetSurf->m_hDC == NULL) { AssertWarn(0, "Unable to get a DC for the window"); delete pRetSurf; return NULL; } // Set the Pixel format, first retrieving the old format // pRetSurf->m_oldPixelFormat = GetPixelFormat(pRetSurf->m_hDC); DescribePixelFormat(pRetSurf->m_hDC, pRetSurf->m_oldPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pRetSurf->m_oldPixelFormatDescriptor); int chosenPixelFormat; PIXELFORMATDESCRIPTOR chosenPFD; if (pRetSurf->choosePixelFormat(chosenPixelFormat, chosenPFD, pRetSurf->m_hWnd, pRetSurf->m_hDC) == false) { AssertWarn(0, "Unable to choose a pixel format"); delete pRetSurf; return NULL; } BOOL spSuccess = SetPixelFormat(pRetSurf->m_hDC, chosenPixelFormat, &chosenPFD); if (spSuccess != TRUE) { AssertWarn(0, "Unable to set the pixel format"); delete pRetSurf; return NULL; } // Create the HGLRC // pRetSurf->m_hGLRC = wglCreateContext(pRetSurf->m_hDC); if (pRetSurf->m_hGLRC == NULL) { AssertWarn(0, "Unable to create a GL Render context"); delete pRetSurf; return NULL; } BOOL mcSuccess = wglMakeCurrent(pRetSurf->m_hDC, pRetSurf->m_hGLRC); if (mcSuccess != TRUE) { AssertWarn(0, "Unable to make the GL Render context current"); delete pRetSurf; return NULL; } pRetSurf->m_glrcMadeCurrent = true; // Retreive the strings associated with this driver, they are useful // for debugging and such... // const char* pVendor = (const char*)glGetString(GL_VENDOR); const char* pRenderer = (const char*)glGetString(GL_RENDERER); const char* pVersion = (const char*)glGetString(GL_VERSION); const char* pExtensions = (const char*)glGetString(GL_EXTENSIONS); if (pVendor != NULL) { pRetSurf->m_pVendorString = new char[strlen(pVendor) + 1]; strcpy(pRetSurf->m_pVendorString, pVendor); } if (pRenderer != NULL) { pRetSurf->m_pRendererString = new char[strlen(pRenderer) + 1]; strcpy(pRetSurf->m_pRendererString, pRenderer); } if (pVersion != NULL) { pRetSurf->m_pVersionString = new char[strlen(pVersion) + 1]; strcpy(pRetSurf->m_pVersionString, pVersion); } if (pExtensions != NULL) { pRetSurf->m_pExtensionsString = new char[strlen(pExtensions) + 1]; strcpy(pRetSurf->m_pExtensionsString, pExtensions); } // Allocate our vertex arrays... // pRetSurf->m_pVertexArray = new DGLVertex4F[sm_maxNumVertices]; pRetSurf->m_pColorArray = new DGLColor4F[sm_maxNumVertices]; pRetSurf->m_pTexCoord0Array = new DGLTexCoord4F[sm_maxNumVertices]; pRetSurf->m_pHazeStoreArray = new DGLHazeCoordF[sm_maxNumVertices]; pRetSurf->surfaceWidth = in_width; pRetSurf->surfaceHeight = in_height; // Create the texture/handle cache... // pRetSurf->m_pTextureCache = new TextureCache(pRetSurf); pRetSurf->m_pHandleCache = new HandleCache(2048, 2153); // Set up our default state... // pRetSurf->setFillMode(GFX_FILL_CONSTANT); pRetSurf->setFillColor(&ColorF(0, 0, 0)); pRetSurf->setAlphaSource(GFX_ALPHA_NONE); pRetSurf->setShadeSource(GFX_SHADE_NONE); pRetSurf->setHazeSource(GFX_HAZE_NONE); pRetSurf->setTextureWrap(true); pRetSurf->setTransparency(false); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // We're ready to go... // return pRetSurf; }
void Renderer::Blit(Surface &surf, SDL_Rect *src, SDL_Rect *dest) { SDL_RenderCopy(Get(), surf.GetTexture(), src, dest); }
char Video_v2::spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight, int16 x, int16 y, int16 transp, Surface &destDesc) { byte *memBuffer; byte *srcPtr; byte temp; uint32 sourceLeft; uint16 cmdVar; int16 curWidth, curHeight; int16 offset; int16 counter2; int16 bufPos; int16 strLen; int16 lenCmd; //_vm->validateVideoMode(destDesc._vidMode); if (sprBuf[0] != 1) return 0; if (sprBuf[1] != 2) return 0; if (sprBuf[2] == 2) { Surface sourceDesc(srcWidth, srcHeight, 1, sprBuf + 3); destDesc.blit(sourceDesc, 0, 0, srcWidth - 1, srcHeight - 1, x, y, (transp == 0) ? -1 : 0); return 1; } else if (sprBuf[2] == 1) { memBuffer = new byte[4370]; assert(memBuffer); memset(memBuffer, 0, 4370); srcPtr = sprBuf + 3; sourceLeft = READ_LE_UINT32(srcPtr); Pixel destPtr = destDesc.get(x, y); curWidth = 0; curHeight = 0; Pixel linePtr = destPtr; srcPtr += 4; if ((READ_LE_UINT16(srcPtr) == 0x1234) && (READ_LE_UINT16(srcPtr + 2) == 0x5678)) { srcPtr += 4; bufPos = 273; lenCmd = 18; } else { lenCmd = 100; bufPos = 4078; } memset(memBuffer, 32, bufPos); cmdVar = 0; while (1) { cmdVar >>= 1; if ((cmdVar & 0x100) == 0) cmdVar = *srcPtr++ | 0xFF00; if ((cmdVar & 1) != 0) { temp = *srcPtr++; if ((temp != 0) || (transp == 0)) destPtr.set(temp); destPtr++; curWidth++; if (curWidth >= srcWidth) { curWidth = 0; linePtr += destDesc.getWidth(); destPtr = linePtr; if (++curHeight >= srcHeight) break; } memBuffer[bufPos] = temp; bufPos = (bufPos + 1) % 4096; if (--sourceLeft == 0) break; } else { offset = *srcPtr++; temp = *srcPtr++; offset |= (temp & 0xF0) << 4; strLen = (temp & 0x0F) + 3; if (strLen == lenCmd) strLen = *srcPtr++ + 18; for (counter2 = 0; counter2 < strLen; counter2++) { temp = memBuffer[(offset + counter2) % 4096]; if ((temp != 0) || (transp == 0)) destPtr.set(temp); destPtr++; curWidth++; if (curWidth >= srcWidth) { curWidth = 0; linePtr += destDesc.getWidth(); destPtr = linePtr; if (++curHeight >= srcHeight) { delete[] memBuffer; return 1; } } memBuffer[bufPos] = temp; bufPos = (bufPos + 1) % 4096; } if (strLen >= ((int32) sourceLeft)) { delete[] memBuffer; return 1; } else sourceLeft--; } } } else