void HudTrail::Render(Graphics::Renderer *r) { PROFILE_SCOPED(); //render trail if (m_trailPoints.size() > 1) { const vector3d vpos = m_transform * m_body->GetInterpPosition(); m_transform[12] = vpos.x; m_transform[13] = vpos.y; m_transform[14] = vpos.z; m_transform[15] = 1.0; static std::vector<vector3f> tvts; static std::vector<Color> colors; tvts.clear(); colors.clear(); const vector3d curpos = m_body->GetInterpPosition(); tvts.reserve(MAX_POINTS); colors.reserve(MAX_POINTS); tvts.push_back(vector3f(0.f)); colors.push_back(Color::BLANK); float alpha = 1.f; const float decrement = 1.f / m_trailPoints.size(); const Color tcolor = m_color; for (size_t i = m_trailPoints.size()-1; i > 0; i--) { tvts.push_back(-vector3f(curpos - m_trailPoints[i])); alpha -= decrement; colors.push_back(tcolor); colors.back().a = Uint8(alpha * 255); } r->SetTransform(m_transform); m_lines.SetData(tvts.size(), &tvts[0], &colors[0]); m_lines.Draw(r, m_renderState, Graphics::LINE_STRIP); } }
void BallsView::Init(){ camera.Init(); camera.SwitchCamMode(true); camera.MoveA(vector3f(0,0,0)); camera.RotateA(vector3f(0,M_PI/4,0)); camera.ZoomR(-3); }
/* when ship is on rails it returns true and fills outPosOrient. * when ship has been released (or docked) it returns false. * Note station animations may continue for any number of stages after * ship has been released and is under player control again */ bool SpaceStationType::GetDockAnimPositionOrient(int port, int stage, double t, const vector3d &from, positionOrient_t &outPosOrient, const Ship *ship) const { if ((stage < 0) && ((-stage) > numUndockStages)) return false; if ((stage > 0) && (stage > numDockingStages)) return false; lua_State *L = LmrGetLuaState(); LUA_DEBUG_START(L); lua_pushcfunction(L, pi_lua_panic); // It's a function of form function(stage, t, from) model->PushAttributeToLuaStack("ship_dock_anim"); if (!lua_isfunction(L, -1)) { Error("Spacestation model %s needs ship_dock_anim method", model->GetName()); } lua_pushinteger(L, port+1); lua_pushinteger(L, stage); lua_pushnumber(L, double(t)); vector3f *_from = MyLuaVec::pushVec(L); *_from = vector3f(from); // push model aabb as lua table: { min: vec3, max: vec3 } { Aabb aabb; ship->GetAabb(aabb); lua_createtable (L, 0, 2); vector3f *v = MyLuaVec::pushVec(L); *v = vector3f(aabb.max); lua_setfield(L, -2, "max"); v = MyLuaVec::pushVec(L); *v = vector3f(aabb.min); lua_setfield(L, -2, "min"); } lua_pcall(L, 5, 1, -7); bool gotOrient; if (lua_istable(L, -1)) { gotOrient = true; lua_pushinteger(L, 1); lua_gettable(L, -2); outPosOrient.pos = vector3d(*MyLuaVec::checkVec(L, -1)); lua_pop(L, 1); lua_pushinteger(L, 2); lua_gettable(L, -2); outPosOrient.xaxis = vector3d(*MyLuaVec::checkVec(L, -1)); lua_pop(L, 1); lua_pushinteger(L, 3); lua_gettable(L, -2); outPosOrient.yaxis = vector3d(*MyLuaVec::checkVec(L, -1)); lua_pop(L, 1); } else { gotOrient = false; } lua_pop(L, 2); LUA_DEBUG_END(L, 0); return gotOrient; }
void Face::Draw() { const Point &offset = GetActiveOffset(); const Point &area = GetActiveArea(); const float x = offset.x; const float y = offset.y; const float sx = area.x; const float sy = area.y; const vector2f texSize = m_texture->GetDescriptor().texSize; Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0); va.Add(vector3f(x, y, 0.0f), vector2f(0.0f, 0.0f)); va.Add(vector3f(x, y+sy, 0.0f), vector2f(0.0f, texSize.y)); va.Add(vector3f(x+sx, y, 0.0f), vector2f(texSize.x, 0.0f)); va.Add(vector3f(x+sx, y+sy, 0.0f), vector2f(texSize.x, texSize.y)); Graphics::Renderer *r = GetContext()->GetRenderer(); s_material->texture0 = m_texture.get(); auto state = GetContext()->GetSkin().GetAlphaBlendState(); r->DrawTriangles(&va, state, s_material.Get(), Graphics::TRIANGLE_STRIP); Single::Draw(); }
void ObjectViewerView::Draw3D() { m_renderer->ClearScreen(); float znear, zfar; m_renderer->GetNearFarRange(znear, zfar); m_renderer->SetPerspectiveProjection(75.f, Pi::GetScrAspect(), znear, zfar); m_renderer->SetTransform(matrix4x4f::Identity()); Graphics::Light light; light.SetType(Graphics::Light::LIGHT_DIRECTIONAL); if (Pi::MouseButtonState(SDL_BUTTON_RIGHT)) { int m[2]; Pi::GetMouseMotion(m); m_camRot = matrix4x4d::RotateXMatrix(-0.002*m[1]) * matrix4x4d::RotateYMatrix(-0.002*m[0]) * m_camRot; } Body *body = Pi::player->GetNavTarget(); if (body) { if (body->IsType(Object::STAR)) light.SetPosition(vector3f(0.f)); else { light.SetPosition(vector3f(0.577f)); } m_renderer->SetLights(1, &light); body->Render(m_renderer, 0, vector3d(0,0,-viewingDist), m_camRot); } }
void Face::Draw() { Graphics::Renderer *r = GetContext()->GetRenderer(); if (!m_quad) { const Point &offset = GetActiveOffset(); const Point &area = GetActiveArea(); const float x = offset.x; const float y = offset.y; const float sx = area.x; const float sy = area.y; const vector2f texSize = m_texture->GetDescriptor().texSize; Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0); va.Add(vector3f(x, y, 0.0f), vector2f(0.0f, 0.0f)); va.Add(vector3f(x, y + sy, 0.0f), vector2f(0.0f, texSize.y)); va.Add(vector3f(x + sx, y, 0.0f), vector2f(texSize.x, 0.0f)); va.Add(vector3f(x + sx, y + sy, 0.0f), vector2f(texSize.x, texSize.y)); Graphics::Renderer *r = GetContext()->GetRenderer(); s_material->texture0 = m_texture.get(); auto state = GetContext()->GetSkin().GetAlphaBlendState(); m_quad.reset(new Graphics::Drawables::TexturedQuad(r, s_material, va, state)); } m_quad->Draw(r); Single::Draw(); }
void DrawRoundEdgedRect(const float size[2], float rad, const Color &color, Graphics::RenderState *state) { static Graphics::VertexArray vts(Graphics::ATTRIB_POSITION); vts.Clear(); const int STEPS = 6; if (rad > 0.5f*std::min(size[0], size[1])) rad = 0.5f*std::min(size[0], size[1]); // top left // bottom left for (int i=0; i<=STEPS; i++) { float ang = M_PI*0.5f*i/float(STEPS); vts.Add(vector3f(rad - rad*cos(ang), (size[1] - rad) + rad*sin(ang), 0.f)); } // bottom right for (int i=0; i<=STEPS; i++) { float ang = M_PI*0.5 + M_PI*0.5f*i/float(STEPS); vts.Add(vector3f(size[0] - rad - rad*cos(ang), (size[1] - rad) + rad*sin(ang), 0.f)); } // top right for (int i=0; i<=STEPS; i++) { float ang = M_PI + M_PI*0.5f*i/float(STEPS); vts.Add(vector3f((size[0] - rad) - rad*cos(ang), rad + rad*sin(ang), 0.f)); } // top right for (int i=0; i<=STEPS; i++) { float ang = M_PI*1.5 + M_PI*0.5f*i/float(STEPS); vts.Add(vector3f(rad - rad*cos(ang), rad + rad*sin(ang), 0.f)); } Screen::flatColorMaterial->diffuse = color; Screen::GetRenderer()->DrawTriangles(&vts, state, Screen::flatColorMaterial, Graphics::TRIANGLE_FAN); }
void moon::display(const vector3 &moon_pos, const vector3 &sun_pos, double max_view_dist) const { vector3 moon_dir = moon_pos.normal(); double moon_size = max_view_dist/20; float moon_azimuth = atan2(-moon_dir.y, moon_dir.x); float moon_elevation = asin(moon_dir.z); glsl_moon->use(); glsl_moon->set_gl_texture(*map_diffuse, loc_diffcol, 0); glsl_moon->set_gl_texture(*map_normal, loc_nrml, 1); // transform light into object space matrix4 roth = matrix4::rot_z(-RAD_TO_DEG(moon_azimuth)); matrix4 rotv = matrix4::rot_y(-RAD_TO_DEG(moon_elevation)); matrix4 model_mat = roth*rotv; vector3 l = model_mat.inverse() * sun_pos; vector3 nl = vector3(-l.y, l.z, -l.x).normal(); // OpenGL coordinates glsl_moon->set_uniform(loc_lightdir, nl); // render moon glPushMatrix(); model_mat.multiply_gl(); glTranslated(0.95*max_view_dist, 0, 0); primitives::textured_quad(vector3f( 0, moon_size, moon_size), vector3f( 0, -moon_size, moon_size), vector3f( 0, -moon_size, -moon_size), vector3f( 0, moon_size, -moon_size), *map_diffuse).render_plain(); glPopMatrix(); }
void Billboard::Render(const matrix4x4f &trans, const RenderData *rd) { Graphics::Renderer *r = GetRenderer(); Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0, 6); const matrix3x3f rot = trans.GetOrient().Transpose(); //some hand-tweaked scaling, to make the lights seem larger from distance const float size = m_size * Graphics::GetFovFactor() * Clamp(trans.GetTranslate().Length() / 500.f, 0.25f, 15.f); const vector3f rotv1 = rot * vector3f(size/2.f, -size/2.f, 0.0f); const vector3f rotv2 = rot * vector3f(size/2.f, size/2.f, 0.0f); va.Add(m_offset-rotv1, vector2f(0.f, 0.f)); //top left va.Add(m_offset-rotv2, vector2f(0.f, 1.f)); //bottom left va.Add(m_offset+rotv2, vector2f(1.f, 0.f)); //top right va.Add(m_offset+rotv2, vector2f(1.f, 0.f)); //top right va.Add(m_offset-rotv2, vector2f(0.f, 1.f)); //bottom left va.Add(m_offset+rotv1, vector2f(1.f, 1.f)); //bottom right r->SetTransform(trans); r->DrawTriangles(&va, m_renderState, m_material.Get()); }
//------------------------------------------------------------------------------------------------------ RotatingRing::RotatingRing() :LocatableObject( this ), m_isMaked(false), m_pRingBuffer(NULL), m_fRadius(0) { float bs = 1.5 * 1; m_BindBox = aabbox3df( vector3f( -bs, -bs, -bs ), vector3f( bs, bs, bs ) ); m_isMaked = true; m_fRadius = 1; ASSERT( 3 == RC_AXIS ); VertexColor LineVertex[ RC_AXIS * RC_POINT ]; static ushort Indies[RC_AXIS*RC_POINT*2]; for ( int i = 0 ; i < RC_AXIS*RC_POINT*2; i += 2 ) { Indies[i] = i/2; //Indies[i+1] = (i/2)%RC_POINT==0&&0!=i ? i-RC_POINT*2 : i/2+1 ; if ( i/2 == RC_POINT-1 || i/2 == RC_POINT*2-1 || i/2 == RC_POINT*3-1 ) { Indies[i+1] = i/2-RC_POINT+1; } else { Indies[i+1] = i/2+1; } } m_pRingBuffer = NEW RendBuffer( Device::RM_LINES ); m_pVertexBuffer = NEW VertexBuffer( Device::MU_DYNAMIC ); m_pIndicesBuffer = NEW IndicesBuffer( Device::MU_STATIC ); m_pRingBuffer->SetVertexBuffer( m_pVertexBuffer ); m_pRingBuffer->SetIndicesBuffer( m_pIndicesBuffer ); m_pIndicesBuffer->FlushIndiesBuffer( RC_AXIS*RC_POINT*2, Indies ); }
//------------------------------------------------------------------------------------------------------ void RotatingRing::CreateRing( const float& r ) { float bs = 1.5 * r; m_BindBox = aabbox3df( vector3f( -bs, -bs, -bs ), vector3f( bs, bs, bs ) ); m_isMaked = true; m_fRadius = r; ASSERT( 3 == RC_AXIS ); VertexColor LineVertex[ RC_AXIS * RC_POINT ]; for ( int i = 0; i < RC_POINT; i ++ ) { Matrix22f m; m.FromRadian( (PI / 180) * i ); vector2f v( r, 0 ); v *= m; LineVertex[i].SetVertex( vector4f( v.m_x, 0, v.m_y, 1 ) );//ΧÈÆyÖá LineVertex[i].SetColor( Color( 1, 0, 0, 1) ); LineVertex[i+RC_POINT].SetVertex( vector4f( 0, v.m_x, v.m_y, 1 ) );//ΧÈÆxÖá LineVertex[i+RC_POINT].SetColor( Color( 0, 1, 0, 1) ); LineVertex[i+2*RC_POINT].SetVertex( vector4f( v.m_x, v.m_y, 0, 1 ) );//ΧÈÆxÖá LineVertex[i+2*RC_POINT].SetColor( Color( 0, 0, 1, 1) ); } m_pVertexBuffer->FlushVertexBuffer( RC_AXIS * RC_POINT, LineVertex ); }
void Camera::rotate() { n = to - at; n.normalize(); // n_aux is in the plane defined by n and v vector3f n_aux(n.x, n.y-1, n.z); u = vector3f::crossProduct(n_aux,n); u.normalize(); v = vector3f::crossProduct(u,n); v.normalize(); //rotation in x matrix4x4f rx; rx.rotate(pitch, vector3f(1,0,0)); rx.transformVector(&n); rx.transformVector(&v); //rotation in y matrix4x4f ry; ry.rotate(yaw, vector3f(0,1,0)); // ry.rotate(yaw, v); ry.transformVector(&n); ry.transformVector(&u); //rotation in z matrix4x4f rz; rz.rotate(roll, vector3f(0,0,1)); rz.transformVector(&v); rz.transformVector(&u); }
void Gradient::Draw() { Graphics::Renderer *r = GetContext()->GetRenderer(); if (!m_quad) { const Point &offset = GetActiveOffset(); const Point &area = GetActiveArea(); const float x = offset.x; const float y = offset.y; const float sx = area.x; const float sy = area.y; Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_DIFFUSE); va.Add(vector3f(x, y, 0.0f), m_beginColor); va.Add(vector3f(x, y + sy, 0.0f), m_direction == HORIZONTAL ? m_beginColor : m_endColor); va.Add(vector3f(x + sx, y, 0.0f), m_direction == HORIZONTAL ? m_endColor : m_beginColor); va.Add(vector3f(x + sx, y + sy, 0.0f), m_endColor); auto renderState = GetContext()->GetSkin().GetAlphaBlendState(); m_quad.reset(new Graphics::Drawables::TexturedQuad(r, m_material, va, renderState)); } m_quad->Draw(r, Color(Color::WHITE.r, Color::WHITE.g, Color::WHITE.b, GetContext()->GetOpacity()*Color::WHITE.a)); Container::Draw(); }
//-------------------------------------------------------------------------------------------------------------------------------------- void EditCamera::Rotate( float xd, float yd ) { Quaternionf q; q.RotateAxis( m_VerticalAixs,yd * m_RotateSpeed ); Matrix44f mat = Math::Transformation<float>(NULL, NULL, NULL, &m_Target, &q, NULL); vector3f pos = Math::Transform_coord(this->GetPosition(), mat); q.RotateAxis( vector3f(0.0f, GetUp().Dot( vector3f(0, 1, 0)) < 0 ? -1.0f : 1.0f, 0.0f), xd * m_RotateSpeed ); mat = Math::Transformation<float>(NULL, NULL, NULL, &m_Target, &q, NULL); pos = Math::Transform_coord(pos, mat); m_VerticalAixs = Math::Transform_Quat(m_VerticalAixs, q); vector3f dir; if (m_isReverse) { dir = pos - m_Target; } else { dir = m_Target - pos; } dir.NormalizeSelf(); vector3f up = dir.Cross(m_VerticalAixs); this->_LookAt(pos, pos + dir, up); }
SpeedLines::SpeedLines(Ship *s) : m_ship(s) , m_visible(false) , m_dir(0.f) { PROFILE_SCOPED(); // init the static data SpeedLines::Init(); m_points.reserve(DEPTH * DEPTH * DEPTH); for (int x = -DEPTH/2; x < DEPTH/2; x++) { for (int y = -DEPTH/2; y < DEPTH/2; y++) { for (int z = -DEPTH/2; z < DEPTH/2; z++) { m_points.push_back(vector3f(x * SPACING, y * SPACING, z * SPACING)); } } } const Uint32 doubleNumPoints = static_cast<Uint32>(m_points.size()) * 2; m_varray.reset(new Graphics::VertexArray(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_DIFFUSE, doubleNumPoints)); for( Uint32 i = 0; i < doubleNumPoints; i++ ) m_varray->Add(vector3f(0.0f), Color::BLACK); Graphics::RenderStateDesc rsd; rsd.blendMode = Graphics::BLEND_ALPHA_ONE; rsd.depthWrite = false; m_renderState = Pi::renderer->CreateRenderState(rsd); CreateVertexBuffer( Pi::renderer, doubleNumPoints ); }
Projectile::Projectile(): Body() { m_orient = matrix4x4d::Identity(); m_type = 1; m_age = 0; m_parent = 0; m_radius = 0; m_flags |= FLAG_DRAW_LAST; m_prog = new Render::Shader("flat", "#define TEXTURE0 1\n"); m_sideTex = Pi::textureCache->GetBillboardTexture(PIONEER_DATA_DIR "/textures/projectile_l.png"); m_glowTex = Pi::textureCache->GetBillboardTexture(PIONEER_DATA_DIR "/textures/projectile_w.png"); //zero at projectile position //+x down //+y right //+z forwards (or projectile direction) const float w = 0.5f; vector3f one(0.f, -w, 0.f); //top left vector3f two(0.f, w, 0.f); //top right vector3f three(0.f, w, -1.f); //bottom right vector3f four(0.f, -w, -1.f); //bottom left //add four intersecting planes to create a volumetric effect for (int i=0; i < 4; i++) { m_verts.push_back(Vertex(one, 0.f, 1.f)); m_verts.push_back(Vertex(two, 1.f, 1.f)); m_verts.push_back(Vertex(three, 1.f, 0.f)); m_verts.push_back(Vertex(three, 1.f, 0.f)); m_verts.push_back(Vertex(four, 0.f, 0.f)); m_verts.push_back(Vertex(one, 0.f, 1.f)); one.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f)); two.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f)); three.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f)); four.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f)); } //create quads for viewing on end //these are added in the same vertex array to avoid a //vertex pointer change float gw = 0.5f; float gz = -0.1f; for (int i=0; i < 4; i++) { m_verts.push_back(Vertex(vector3f(-gw, -gw, gz), 0.f, 1.f)); m_verts.push_back(Vertex(vector3f(-gw, gw, gz), 1.f, 1.f)); m_verts.push_back(Vertex(vector3f(gw, gw, gz),1.f, 0.f)); m_verts.push_back(Vertex(vector3f(gw, gw, gz), 1.f, 0.f)); m_verts.push_back(Vertex(vector3f(gw, -gw, gz), 0.f, 0.f)); m_verts.push_back(Vertex(vector3f(-gw, -gw, gz), 0.f, 1.f)); gw -= 0.1f; // they get smaller gz -= 0.2; // as they move back } }
void UpdateVBOs() { PROFILE_SCOPED() //create buffer and upload data Graphics::VertexBufferDesc vbd; vbd.attrib[0].semantic = Graphics::ATTRIB_POSITION; vbd.attrib[0].format = Graphics::ATTRIB_FORMAT_FLOAT3; vbd.attrib[1].semantic = Graphics::ATTRIB_NORMAL; vbd.attrib[1].format = Graphics::ATTRIB_FORMAT_FLOAT3; vbd.numVertices = ctx->NUMVERTICES(); vbd.usage = Graphics::BUFFER_USAGE_STATIC; m_vertexBuffer.reset(Pi::renderer->CreateVertexBuffer(vbd)); GasPatchContext::VBOVertex* vtxPtr = m_vertexBuffer->Map<GasPatchContext::VBOVertex>(Graphics::BUFFER_MAP_WRITE); assert(m_vertexBuffer->GetDesc().stride == sizeof(GasPatchContext::VBOVertex)); const Sint32 edgeLen = ctx->edgeLen; const double frac = ctx->frac; for (Sint32 y=0; y<edgeLen; y++) { for (Sint32 x=0; x<edgeLen; x++) { const vector3d p = GetSpherePoint(x*frac, y*frac); const vector3d pSubCentroid = p - clipCentroid; clipRadius = std::max(clipRadius, p.Length()); vtxPtr->pos = vector3f(pSubCentroid); vtxPtr->norm = vector3f(p); ++vtxPtr; // next vertex } } m_vertexBuffer->Unmap(); }
//------------------------------------------------------------------------------------- void BillboardNode::SetBillBorad( const vector3f& pos, const vector2f& rectsize ) { Billboard::SetBillBorad( pos, rectsize ); m_pVertexBuffer->FlushVertexBuffer( COUNT_OF_VERTEX, m_VertexArray ); m_BindBox.Reset(); m_BindBox.Contains( vector3f(pos.m_x - rectsize.m_x, pos.m_y - rectsize.m_y, pos.m_z) ); m_BindBox.Contains( vector3f(pos.m_x + rectsize.m_x, pos.m_y + rectsize.m_y, pos.m_z) ); }
Line3D::Line3D() : m_refreshVertexBuffer(true), m_width(2.0f), m_va( new Graphics::VertexArray(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_DIFFUSE, 2) ) { PROFILE_SCOPED() assert(m_va.get()); // XXX bug in Radeon drivers will cause crash in glLineWidth if width >= 3 m_va->Add(vector3f(0.f), Color(0)); m_va->Add(vector3f(0.f), Color(255)); }
void ScatterBiasArea(int roi, float scan_width, int steps, int samples, int qi_it, float angstep) { std::vector<float> u=linspace(roi/2-scan_width/2,roi/2+scan_width/2, steps); QTrkComputedConfig cfg; cfg.width=cfg.height=roi; cfg.qi_angstep_factor = angstep; cfg.qi_iterations = qi_it; cfg.qi_angular_coverage = 0.7f; cfg.qi_roi_coverage = 1; cfg.qi_radial_coverage = 1.5f; cfg.qi_minradius=0; cfg.zlut_minradius=0; cfg.zlut_angular_coverage = 0.7f; cfg.zlut_roi_coverage = 1; cfg.zlut_radial_coverage = 1.5f; cfg.zlut_minradius = 0; cfg.qi_minradius = 0; cfg.com_bgcorrection = 0; cfg.xc1_profileLength = roi*0.8f; cfg.xc1_profileWidth = roi*0.2f; cfg.xc1_iterations = 1; cfg.Update(); ImageData lut,orglut = ReadLUTFile("10x.radialzlut#4"); vector3f ct(roi/2,roi/2,lut.h/2 + 0.123f); float dx = scan_width/steps; QueuedCPUTracker trk(cfg); ResampleLUT(&trk, &orglut, orglut.h, &lut); int maxval = 10000; ImageData tmp=ImageData::alloc(roi,roi); GenerateImageFromLUT(&tmp, &lut, 0, cfg.zlut_maxradius, vector3f(roi/2,roi/2,lut.h/2)); ApplyPoissonNoise(tmp, maxval); std::string fn = SPrintf( "sb_area_roi%d_scan%d_steps%d_qit%d_N%d", roi, (int)scan_width, steps, qi_it, samples); WriteJPEGFile( (fn + ".jpg").c_str(), tmp); tmp.free(); fn += ".txt"; for (int y=0;y<steps;y++) { for (int x=0;x<steps;x++) { vector3f cpos( (x+0.5f-steps/2) * dx, (y+0.5f-steps/2) * dx, 0 ); cfg.qi_iterations = qi_it; auto r= AccBiasTest(orglut, &trk, samples, cpos+ct, vector3f(), 0, maxval, qi_it < 0 ? LT_XCor1D : 0); float row[] = { r.acc.x, r.acc.y, r.acc.z, r.bias.x, r.bias.y, r.bias.z, r.crlb.x, r.crlb.z, samples }; WriteArrayAsCSVRow(fn.c_str(), row, 9, x+y>0); dbgprintf("X=%d,Y=%d\n", x,y); } } orglut.free(); lut.free(); }
//------------------------------------------------------------------------------------------------------ void LineNode::SetLine( const vector4f& b, const vector4f& e ) { m_BindBox.Reset(); m_BindBox.Contains( vector3f(b) ); m_BindBox.Contains( vector3f(e) ); m_pVertexArray[0].SetVertex( b ); m_pVertexArray[1].SetVertex( e ); m_pVertexBuffer->FlushVertexBuffer( COUNT_OF_VERTEX, m_pVertexArray ); }
void Billboard::Render(const matrix4x4f &trans, const RenderData *rd) { PROFILE_SCOPED() //some hand-tweaked scaling, to make the lights seem larger from distance (final size is in pixels) const float pixrad = Clamp(Graphics::GetScreenHeight() / trans.GetTranslate().Length(), 1.0f, 15.0f); const float size = (m_size * Graphics::GetFovFactor()) * pixrad; m_bbVA.Add(trans * vector3f(0.0f), vector3f(m_colorUVoffset, size)); }
void Ship::Render(Graphics::Renderer *renderer, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform) { if (IsDead()) return; m_shipFlavour.ApplyTo(GetModel()); //angthrust negated, for some reason GetModel()->SetThrust(vector3f(m_thrusters), -vector3f(m_angThrusters)); if (m_landingGearAnimation) m_landingGearAnimation->SetProgress(m_wheelState); //strncpy(params.pText[0], GetLabel().c_str(), sizeof(params.pText)); RenderModel(renderer, viewCoords, viewTransform); // draw shield recharge bubble if (m_stats.shield_mass_left < m_stats.shield_mass) { const float shield = 0.01f*GetPercentShields(); renderer->SetBlendMode(Graphics::BLEND_ADDITIVE); glPushMatrix(); matrix4x4f trans = matrix4x4f::Identity(); trans.Translate(viewCoords.x, viewCoords.y, viewCoords.z); trans.Scale(GetPhysRadius()); renderer->SetTransform(trans); //fade based on strength Sfx::shieldEffect->GetMaterial()->diffuse = Color((1.0f-shield),shield,0.0,0.33f*(1.0f-shield)); Sfx::shieldEffect->Draw(renderer); glPopMatrix(); renderer->SetBlendMode(Graphics::BLEND_SOLID); } if (m_ecmRecharge > 0.0f) { // ECM effect: a cloud of particles for a sparkly effect vector3f v[100]; for (int i=0; i<100; i++) { const double r1 = Pi::rng.Double()-0.5; const double r2 = Pi::rng.Double()-0.5; const double r3 = Pi::rng.Double()-0.5; v[i] = vector3f(viewTransform * ( GetPosition() + GetPhysRadius() * vector3d(r1, r2, r3).Normalized() )); } Color c(0.5,0.5,1.0,1.0); float totalRechargeTime = GetECMRechargeTime(); if (totalRechargeTime >= 0.0f) { c.a = m_ecmRecharge / totalRechargeTime; } Sfx::ecmParticle->diffuse = c; renderer->SetBlendMode(Graphics::BLEND_ALPHA_ONE); renderer->DrawPointSprites(100, v, Sfx::ecmParticle, 50.f); } }
void DrawRect(const vector2f &pos, const vector2f &size, const Color &c, Graphics::RenderState *state) { Graphics::VertexArray bgArr(Graphics::ATTRIB_POSITION, 4); bgArr.Add(vector3f(pos.x,size.y,0)); bgArr.Add(vector3f(size.x,size.y,0)); bgArr.Add(vector3f(size.x,pos.y,0)); bgArr.Add(vector3f(pos.x,pos.y,0)); Screen::flatColorMaterial->diffuse = c; Screen::GetRenderer()->DrawTriangles(&bgArr, state, Screen::flatColorMaterial, Graphics::TRIANGLE_FAN); }
void Skin::DrawRectElement(const RectElement &element, const Point &pos, const Point &size, Graphics::BlendMode blendMode) const { Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0); va.Add(vector3f(pos.x, pos.y, 0.0f), scaled(vector2f(element.pos.x, element.pos.y))); va.Add(vector3f(pos.x, pos.y+size.y, 0.0f), scaled(vector2f(element.pos.x, element.pos.y+element.size.y))); va.Add(vector3f(pos.x+size.x, pos.y, 0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y))); va.Add(vector3f(pos.x+size.x, pos.y+size.y, 0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y+element.size.y))); m_renderer->DrawTriangles(&va, GetRenderState(blendMode), m_textureMaterial.Get(), Graphics::TRIANGLE_STRIP); }
void Skin::DrawRectColor(const Color &col, const Point &pos, const Point &size) const { Graphics::VertexArray va(Graphics::ATTRIB_POSITION); va.Add(vector3f(pos.x, pos.y, 0.0f)); va.Add(vector3f(pos.x, pos.y+size.y, 0.0f)); va.Add(vector3f(pos.x+size.x, pos.y, 0.0f)); va.Add(vector3f(pos.x+size.x, pos.y+size.y, 0.0f)); m_colorMaterial->diffuse = col; m_renderer->DrawTriangles(&va, GetAlphaBlendState(), m_colorMaterial.Get(), Graphics::TRIANGLE_STRIP); }
// Looks at a given point void Camera::lookat(vector3f target) { target = target - pos; theta = getAngle(vector3f(-1, 0, 0), target); if( target.z > 0 ) theta = -theta; phi = -getAngle(vector3f(0, 1, 0), target); setViewMatrix(); }
//-------------------------------------------------------------------------------------------------------------------------------------- void FPSCamera::Rotate( float xd, float yd ) { Quaternionf q; q.RotateAxis( m_VerticalAixs ,yd * m_RotateSpeed ); vector3f dir = Math::Transform_Quat( this->GetForward() , q); q.RotateAxis( vector3f(0.0f, GetUp().Dot( vector3f(0, 1, 0)) < 0 ? -1.0f : 1.0f, 0.0f) , xd * m_RotateSpeed ); m_VerticalAixs = Math::Transform_Quat(m_VerticalAixs, q); dir = Math::Transform_Quat( dir , q); vector3f up = dir.Cross( m_VerticalAixs ); this->_LookAt(this->GetPosition(), this->GetPosition() + dir, up); }
static void DrawAtmosphereSurface(Graphics::Renderer *renderer, const matrix4x4d &modelView, const vector3d &campos, float rad, Graphics::Material *mat) { const int LAT_SEGS = 20; const int LONG_SEGS = 20; vector3d yaxis = campos.Normalized(); vector3d zaxis = vector3d(1.0,0.0,0.0).Cross(yaxis).Normalized(); vector3d xaxis = yaxis.Cross(zaxis); const matrix4x4d invrot = matrix4x4d::MakeRotMatrix(xaxis, yaxis, zaxis).InverseOf(); renderer->SetTransform(modelView * matrix4x4d::ScaleMatrix(rad, rad, rad) * invrot); // what is this? Well, angle to the horizon is: // acos(planetRadius/viewerDistFromSphereCentre) // and angle from this tangent on to atmosphere is: // acos(planetRadius/atmosphereRadius) ie acos(1.0/1.01244blah) double endAng = acos(1.0/campos.Length())+acos(1.0/rad); double latDiff = endAng / double(LAT_SEGS); double rot = 0.0; float sinCosTable[LONG_SEGS+1][2]; for (int i=0; i<=LONG_SEGS; i++, rot += 2.0*M_PI/double(LONG_SEGS)) { sinCosTable[i][0] = float(sin(rot)); sinCosTable[i][1] = float(cos(rot)); } /* Tri-fan above viewer */ Graphics::VertexArray va(Graphics::ATTRIB_POSITION); va.Add(vector3f(0.f, 1.f, 0.f)); for (int i=0; i<=LONG_SEGS; i++) { va.Add(vector3f( sin(latDiff)*sinCosTable[i][0], cos(latDiff), -sin(latDiff)*sinCosTable[i][1])); } renderer->DrawTriangles(&va, mat, Graphics::TRIANGLE_FAN); /* and wound latitudinal strips */ double lat = latDiff; for (int j=1; j<LAT_SEGS; j++, lat += latDiff) { Graphics::VertexArray v(Graphics::ATTRIB_POSITION); float cosLat = cos(lat); float sinLat = sin(lat); float cosLat2 = cos(lat+latDiff); float sinLat2 = sin(lat+latDiff); for (int i=0; i<=LONG_SEGS; i++) { v.Add(vector3f(sinLat*sinCosTable[i][0], cosLat, -sinLat*sinCosTable[i][1])); v.Add(vector3f(sinLat2*sinCosTable[i][0], cosLat2, -sinLat2*sinCosTable[i][1])); } renderer->DrawTriangles(&v, mat, Graphics::TRIANGLE_STRIP); } }
void Projectile::Render(Graphics::Renderer *renderer, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform) { vector3d _from = viewTransform * GetInterpPosition(); vector3d _to = viewTransform * (GetInterpPosition() + m_dirVel); vector3d _dir = _to - _from; vector3f from(&_from.x); vector3f dir = vector3f(_dir).Normalized(); vector3f v1, v2; matrix4x4f m = matrix4x4f::Identity(); v1.x = dir.y; v1.y = dir.z; v1.z = dir.x; v2 = v1.Cross(dir).Normalized(); v1 = v2.Cross(dir); m[0] = v1.x; m[4] = v2.x; m[8] = dir.x; m[1] = v1.y; m[5] = v2.y; m[9] = dir.y; m[2] = v1.z; m[6] = v2.z; m[10] = dir.z; m[12] = from.x; m[13] = from.y; m[14] = from.z; // increase visible size based on distance from camera, z is always negative // allows them to be smaller while maintaining visibility for game play const float dist_scale = float(viewCoords.z / -500); const float length = Equip::lasers[m_type].length + dist_scale; const float width = Equip::lasers[m_type].width + dist_scale; renderer->SetTransform(m * matrix4x4f::ScaleMatrix(width, width, length)); Color color = Equip::lasers[m_type].color; // fade them out as they age so they don't suddenly disappear // this matches the damage fall-off calculation const float base_alpha = sqrt(1.0f - m_age/Equip::lasers[m_type].lifespan); // fade out side quads when viewing nearly edge on vector3f view_dir = vector3f(viewCoords).Normalized(); color.a = (base_alpha * (1.f - powf(fabs(dir.Dot(view_dir)), length))) * 255; if (color.a > 3) { s_sideMat->diffuse = color; renderer->DrawTriangles(s_sideVerts.get(), s_renderState, s_sideMat.get()); } // fade out glow quads when viewing nearly edge on // these and the side quads fade at different rates // so that they aren't both at the same alpha as that looks strange color.a = (base_alpha * powf(fabs(dir.Dot(view_dir)), width)) * 255; if (color.a > 3) { s_glowMat->diffuse = color; renderer->DrawTriangles(s_glowVerts.get(), s_renderState, s_glowMat.get()); } }