void GLWidget::AddSlice() { this->_slice++; CreateCurve(); BuildCurveVertexData(); }
void GLWidget::RemoveSlice() { this->_slice--; if(this->_slice < 3) { this->_slice = 3; } CreateCurve(); BuildCurveVertexData(); }
std::vector<std::shared_ptr<Shape>> CreateCurveShape(const Transform *o2w, const Transform *w2o, bool reverseOrientation, const ParamSet ¶ms) { Float width = params.FindOneFloat("width", 1.f); Float width0 = params.FindOneFloat("width0", width); Float width1 = params.FindOneFloat("width1", width); int ncp; const Point3f *cp = params.FindPoint3f("P", &ncp); if (ncp != 4) { Error( "Must provide 4 control points for \"curve\" primitive. " "(Provided %d).", ncp); return std::vector<std::shared_ptr<Shape>>(); } CurveType type; std::string curveType = params.FindOneString("type", "flat"); if (curveType == "flat") type = CurveType::Flat; else if (curveType == "ribbon") type = CurveType::Ribbon; else if (curveType == "cylinder") type = CurveType::Cylinder; else { Error("Unknown curve type \"%s\". Using \"flat\".", curveType.c_str()); type = CurveType::Cylinder; } int nnorm; const Normal3f *n = params.FindNormal3f("N", &nnorm); if (n != nullptr) { if (type != CurveType::Ribbon) { Warning("Curve normals are only used with \"ribbon\" type curves."); n = nullptr; } else if (nnorm != 2) { Error( "Must provide two normals with \"N\" parameter for ribbon " "curves. " "(Provided %d).", nnorm); return std::vector<std::shared_ptr<Shape>>(); } } int sd = params.FindOneFloat("splitdepth", 2); if (type == CurveType::Ribbon && n == nullptr) { Error( "Must provide normals \"N\" at curve endpoints with ribbon " "curves."); return std::vector<std::shared_ptr<Shape>>(); } else return CreateCurve(o2w, w2o, reverseOrientation, cp, width0, width1, type, n, sd); }
//---------------------------------------------------------------------------- void HelixTubeSurface::CreateScene () { mScene = new0 Node(); mWireState = new0 WireState(); mRenderer->SetOverrideWireState(mWireState); VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0); mCurve = CreateCurve(); Float2 tcoordMin(0.0f, 0.0f), tcoordMax(1.0f, 32.0f); TubeSurface* tube = new TubeSurface(mCurve, Radial, false, Vector3f::UNIT_Z, 256, 32, false, true, &tcoordMin, &tcoordMax, vformat); std::string path = Environment::GetPathR("Grating.wmtf"); Texture2D* texture = Texture2D::LoadWMTF(path); tube->SetEffectInstance(Texture2DEffect::CreateUniqueInstance(texture, Shader::SF_LINEAR, Shader::SC_REPEAT, Shader::SC_REPEAT)); mScene->AttachChild(tube); }
static STATUS_T CmdCurve( wAction_t action, coOrd pos ) { track_p t; DIST_T d; static int segCnt; STATUS_T rc = C_CONTINUE; switch (action) { case C_START: curveMode = (long)commandContext; Da.state = -1; tempSegs_da.cnt = 0; return CreateCurve( action, pos, TRUE, wDrawColorBlack, 0, curveMode, InfoMessage ); case C_TEXT: if ( Da.state == 0 ) return CreateCurve( action, pos, TRUE, wDrawColorBlack, 0, curveMode, InfoMessage ); else return C_CONTINUE; case C_DOWN: if ( Da.state == -1 ) { SnapPos( &pos ); Da.pos0 = pos; Da.state = 0; return CreateCurve( action, pos, TRUE, wDrawColorBlack, 0, curveMode, InfoMessage ); } else { tempSegs_da.cnt = segCnt; return C_CONTINUE; } case C_MOVE: mainD.funcs->options = wDrawOptTemp; DrawSegs( &mainD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); if ( Da.state == 0 ) { SnapPos( &pos ); Da.pos1 = pos; rc = CreateCurve( action, pos, TRUE, wDrawColorBlack, 0, curveMode, InfoMessage ); } else { SnapPos( &pos ); PlotCurve( curveMode, Da.pos0, Da.pos1, pos, &Da.curveData, TRUE ); if (Da.curveData.type == curveTypeStraight) { tempSegs(0).type = SEG_STRTRK; tempSegs(0).u.l.pos[0] = Da.pos0; tempSegs(0).u.l.pos[1] = Da.curveData.pos1; tempSegs_da.cnt = 1; InfoMessage( _("Straight Track: Length=%s Angle=%0.3f"), FormatDistance(FindDistance( Da.pos0, Da.curveData.pos1 )), PutAngle(FindAngle( Da.pos0, Da.curveData.pos1 )) ); } else if (Da.curveData.type == curveTypeNone) { tempSegs_da.cnt = 0; InfoMessage( _("Back") ); } else if (Da.curveData.type == curveTypeCurve) { tempSegs(0).type = SEG_CRVTRK; tempSegs(0).u.c.center = Da.curveData.curvePos; tempSegs(0).u.c.radius = Da.curveData.curveRadius; tempSegs(0).u.c.a0 = Da.curveData.a0; tempSegs(0).u.c.a1 = Da.curveData.a1; tempSegs_da.cnt = 1; d = D2R(Da.curveData.a1); if (d < 0.0) d = 2*M_PI+d; if ( d*Da.curveData.curveRadius > mapD.size.x+mapD.size.y ) { ErrorMessage( MSG_CURVE_TOO_LARGE ); tempSegs_da.cnt = 0; Da.curveData.type = curveTypeNone; mainD.funcs->options = 0; return C_CONTINUE; } InfoMessage( _("Curved Track: Radius=%s Angle=%0.3f Length=%s"), FormatDistance(Da.curveData.curveRadius), Da.curveData.a1, FormatDistance(Da.curveData.curveRadius*d) ); } } DrawSegs( &mainD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); mainD.funcs->options = 0; return rc; case C_UP: mainD.funcs->options = wDrawOptTemp; DrawSegs( &mainD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); if (Da.state == 0) { SnapPos( &pos ); Da.pos1 = pos; Da.state = 1; CreateCurve( action, pos, TRUE, wDrawColorBlack, 0, curveMode, InfoMessage ); DrawSegs( &mainD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); mainD.funcs->options = 0; segCnt = tempSegs_da.cnt; InfoMessage( _("Drag on Red arrows to adjust curve") ); return C_CONTINUE; } else { mainD.funcs->options = 0; tempSegs_da.cnt = 0; Da.state = -1; if (Da.curveData.type == curveTypeStraight) { if ((d=FindDistance( Da.pos0, Da.curveData.pos1 )) <= minLength) { ErrorMessage( MSG_TRK_TOO_SHORT, "Curved ", PutDim(fabs(minLength-d)) ); return C_TERMINATE; } UndoStart( _("Create Straight Track"), "newCurve - straight" ); t = NewStraightTrack( Da.pos0, Da.curveData.pos1 ); UndoEnd(); } else if (Da.curveData.type == curveTypeCurve) { if ((d= Da.curveData.curveRadius * Da.curveData.a1 *2.0*M_PI/360.0) <= minLength) { ErrorMessage( MSG_TRK_TOO_SHORT, "Curved ", PutDim(fabs(minLength-d)) ); return C_TERMINATE; } UndoStart( _("Create Curved Track"), "newCurve - curve" ); t = NewCurvedTrack( Da.curveData.curvePos, Da.curveData.curveRadius, Da.curveData.a0, Da.curveData.a1, 0 ); UndoEnd(); } else { return C_ERROR; } DrawNewTrack( t ); return C_TERMINATE; } case C_REDRAW: if ( Da.state >= 0 ) { mainD.funcs->options = wDrawOptTemp; DrawSegs( &mainD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); mainD.funcs->options = 0; } return C_CONTINUE; case C_CANCEL: if (Da.state == 1) { mainD.funcs->options = wDrawOptTemp; DrawSegs( &mainD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); mainD.funcs->options = 0; tempSegs_da.cnt = 0; } Da.state = -1; return C_CONTINUE; } return C_CONTINUE; }