|
@@ -646,7 +646,7 @@ int tnsEnableShader(int index){
|
|
|
tmsi = tKnlGetCurrentMatStackItem();
|
|
|
tnsShaderApplyProjection(tns, tmsi->projection);
|
|
|
tnsShaderApplyView(tns, tmsi->view);
|
|
|
- tnsShaderApplyModel(tns, tmsi->model);
|
|
|
+ tnsShaderApplyModel(tns, tmsi->model); tnsUseShader(tns);
|
|
|
return 1;
|
|
|
}
|
|
|
int tnsEnableShaderv(tnsShader *shader){
|
|
@@ -666,7 +666,7 @@ int tnsEnableShaderv(tnsShader *shader){
|
|
|
tnsShaderApplyProjection(tns, tmsi->projection);
|
|
|
tnsShaderApplyProjectionInverse(tns, tmsi->projection);
|
|
|
tnsShaderApplyView(tns, tmsi->view);
|
|
|
- tnsShaderApplyModel(tns, tmsi->model);
|
|
|
+ tnsShaderApplyModel(tns, tmsi->model); tnsUseShader(tns);
|
|
|
|
|
|
//if (tns->iVertex != -1) glEnableVertexAttribArray(tns->iVertex);
|
|
|
//if (tns->iColor != -1) glEnableVertexAttribArray(tns->iColor);
|
|
@@ -1329,6 +1329,16 @@ void tnsMakeViewportMatrix44d(tnsMatrix44d m, real w, real h, real Far, real Nea
|
|
|
//m[15] = 1;
|
|
|
}
|
|
|
|
|
|
+int tnsIntersectPlaneRay(tnsVector3d n, tnsVector3d p0, tnsVector3d l0, tnsVector3d l, real* t){
|
|
|
+ float denom = tnsDot3d(n, l, 0);
|
|
|
+ if (denom > 1e-6){
|
|
|
+ tnsVector3d p0l0; tnsVectorMinus3d(p0l0,p0 ,l0);
|
|
|
+ (*t) = tnsDot3d(p0l0, n, 0) / denom;
|
|
|
+ return ((*t) >= 0);
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
void tnsInitFirstLevel(tnsMatrixStack *tms){
|
|
|
tnsLoadIdentity44d(tms->level[0].model);
|
|
|
tnsLoadIdentity44d(tms->level[0].projection);
|
|
@@ -2132,7 +2142,7 @@ void tnsShadeMode(GLenum ShadeMode){
|
|
|
}
|
|
|
void tnsVertex3d(real x, real y, real z){
|
|
|
tnsCommand *c = &T->DrawingCommand[T->NextCommand];
|
|
|
- short vend = c->VertEnd;
|
|
|
+ int vend = c->VertEnd;
|
|
|
|
|
|
c->UseVert = 1;
|
|
|
|
|
@@ -2161,7 +2171,7 @@ void tnsVertex3d(real x, real y, real z){
|
|
|
}
|
|
|
void tnsVertex2d(real x, real y){
|
|
|
tnsCommand *c = &T->DrawingCommand[T->NextCommand];
|
|
|
- short vend = c->VertEnd;
|
|
|
+ int vend = c->VertEnd;
|
|
|
|
|
|
c->UseVert = 1;
|
|
|
|
|
@@ -2186,7 +2196,7 @@ void tnsVertex2d(real x, real y){
|
|
|
void tnsVertexArray2d(real *verts, int amount){
|
|
|
tnsCommand *c = &T->DrawingCommand[T->NextCommand];
|
|
|
int trans = 2 * amount;
|
|
|
- short vend = c->VertEnd;
|
|
|
+ int vend = c->VertEnd;
|
|
|
|
|
|
c->UseVert = 1;
|
|
|
|
|
@@ -2213,7 +2223,7 @@ void tnsVertexArray2d(real *verts, int amount){
|
|
|
void tnsVertexArray3d(real *verts, int amount){
|
|
|
tnsCommand *c = &T->DrawingCommand[T->NextCommand];
|
|
|
int trans = 3 * amount;
|
|
|
- short vend = c->VertEnd;
|
|
|
+ int vend = c->VertEnd;
|
|
|
|
|
|
c->UseVert = 1;
|
|
|
|
|
@@ -3556,6 +3566,10 @@ void tnsSelectObject(tnsObject* o, int Select, int Toggle){
|
|
|
elif(Select) o->Flags|=TNS_OBJECT_FLAGS_SELECTED; else o->Flags&=(~TNS_OBJECT_FLAGS_SELECTED);
|
|
|
}
|
|
|
|
|
|
+void tnsGetCameraProjection(tnsMatrix44d* mat, int w, int h, tnsCamera* Camera){
|
|
|
+ tnsMatrix44d inv, result;
|
|
|
+ tnsMakePerspectiveMatrix44d(mat, Camera->FOV, (real)w / (real)h, Camera->ZMin, Camera->ZMax);
|
|
|
+}
|
|
|
void tnsGetCameraViewProjection(tnsMatrix44d* mat, int w, int h, tnsCamera* Camera){
|
|
|
tnsMatrix44d inv, result;
|
|
|
tnsMakePerspectiveMatrix44d(mat, Camera->FOV, (real)w / (real)h, Camera->ZMin, Camera->ZMax);
|
|
@@ -3674,6 +3688,25 @@ void tnsDrawCamera(tnsObject *o){
|
|
|
tnsPackAs(GL_LINE_STRIP);
|
|
|
tnsFlush();
|
|
|
}
|
|
|
+void tnsDrawCross(real x,real y,real z,real x1,real x2,real y1,real y2,real z1,real z2){
|
|
|
+ tnsVertex3d(x+x1, y+0.0, z+0.0); tnsVertex3d(x+x2, y+0.0, z+0.0);
|
|
|
+ tnsVertex3d(x+0.0,y+ y1, z+0.0); tnsVertex3d(x+0.0,y+ y2, z+0.0);
|
|
|
+ tnsVertex3d(x+0.0,y+ 0.0,z+ z1); tnsVertex3d(x+0.0,y+ 0.0,z+ z2);
|
|
|
+}
|
|
|
+void tnsDrawPlaceholder(tnsObject* o, tnsObject *active, int DrawAsSelection){
|
|
|
+ if(T->BindedShader==T->SelectionShader){
|
|
|
+ int i=o->SelectID; real color[4]={0,0,0,1}; TNS_ID_TO_COLOR(color,i); tnsColor4dv(color);
|
|
|
+ }else{
|
|
|
+ if(DrawAsSelection && (!(o->Flags&TNS_OBJECT_FLAGS_SELECTED))) return;
|
|
|
+ if(!DrawAsSelection && (o->Flags&TNS_OBJECT_FLAGS_SELECTED)) return;
|
|
|
+ if(o==active){ tnsColor4dv(laAccentColor(LA_BT_TEXT_ACTIVE)); }
|
|
|
+ elif(o->Flags&TNS_OBJECT_FLAGS_SELECTED){ tnsColor4dv(laAccentColor(LA_BT_NORMAL)); }
|
|
|
+ else tnsColor4dv(laThemeColor(_LA_THEME_3D_VIEW,LA_BT_BORDER));
|
|
|
+ }
|
|
|
+ tnsDrawCross(0,0,0,-1,5,-1,5,-1,5);
|
|
|
+ tnsPackAs(GL_LINES);
|
|
|
+ tnsFlush();
|
|
|
+}
|
|
|
void tnsDrawThisObject(tnsObject *o,tnsObject *active, int DrawAsObjectSelection, int MeshSelectionMode){
|
|
|
if (!o->Show) return;
|
|
|
switch (o->Type){
|
|
@@ -3685,16 +3718,7 @@ void tnsDrawThisObject(tnsObject *o,tnsObject *active, int DrawAsObjectSelection
|
|
|
break;
|
|
|
case TNS_OBJECT_EMPTY:
|
|
|
default:
|
|
|
- ////if (T->CurrentShader != T->uiShader) tnsEnableShaderv(T->uiShader);
|
|
|
- //tnsVertex3d(-1.0, 0.0, 0.0);
|
|
|
- //tnsVertex3d(5.0, 0.0, 0.0);
|
|
|
- //tnsVertex3d(0.0, 5.0, 0.0);
|
|
|
- //tnsVertex3d(0.0, -1.0, 0.0);
|
|
|
- //tnsVertex3d(0.0, 0.0, -1.0);
|
|
|
- //tnsVertex3d(0.0, 0.0, 5.0);
|
|
|
- //tnsColor4d(1, 1, 1, 1);
|
|
|
- //tnsPackAs(GL_LINES);
|
|
|
- //tnsFlush();
|
|
|
+ tnsDrawPlaceholder(o,active,DrawAsObjectSelection);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -3710,6 +3734,33 @@ void tnsDrawObjectTree(tnsObject *from, tnsObject *active, int DrawAsObjectSelec
|
|
|
tnsPopMatrix();
|
|
|
}
|
|
|
}
|
|
|
+void tnsDrawObjectOrigins(tnsObject *from, tnsObject *active, int AllOrigins){
|
|
|
+ tnsObject *o; if(!from) return;
|
|
|
+ tnsVector4d pos;
|
|
|
+ for (laListItemPointer* lip=from->ChildObjects.pFirst;lip;lip=lip->pNext){
|
|
|
+ o=lip->p; if((!AllOrigins) && (o!=active) && (!(o->Flags&TNS_OBJECT_FLAGS_SELECTED))) continue;
|
|
|
+ if(o->Type==TNS_OBJECT_MESH && ((tnsMeshObject*)o)->Mode==TNS_MESH_EDIT_MODE){ continue; }
|
|
|
+ if(T->BindedShader==T->SelectionShader){ int i=o->SelectID; real color[4]={0,0,0,1}; TNS_ID_TO_COLOR(color,i); tnsColor4dv(color); }
|
|
|
+ else{
|
|
|
+ if(o==active){ tnsColor4dv(laAccentColor(LA_BT_TEXT_ACTIVE)); }
|
|
|
+ elif(o->Flags&TNS_OBJECT_FLAGS_SELECTED){ tnsColor4dv(laAccentColor(LA_BT_NORMAL)); }
|
|
|
+ else{ real* c=laThemeColor(_LA_THEME_3D_VIEW,LA_BT_BORDER); tnsColor4d(LA_COLOR3(c),0.5); }
|
|
|
+ }
|
|
|
+ tnsVertex3d(LA_COLOR3(o->GLocation)); tnsPackAs(GL_POINTS);
|
|
|
+ }
|
|
|
+}
|
|
|
+void tnsDrawCursor(tnsObject* root){
|
|
|
+ if(root->Type!=TNS_OBJECT_ROOT) return;
|
|
|
+ tnsMatrix44d vp; tnsVector4d t; tnsVector4d t1={0,0,0,1};
|
|
|
+ tnsMultiply44d(vp,tnsGetProjectionMatrix(),tnsGetViewMatrix());
|
|
|
+ tnsApplyTransform44d(t,vp,root->GLocation); real w=t[3]*0.05;
|
|
|
+ tnsDrawCross(LA_COLOR3(root->GLocation),-w,w,-w,w,-w,w); tnsColor4d(0,0,0,0.5);
|
|
|
+ tnsPackAs(GL_LINES); glLineWidth(5);
|
|
|
+ tnsFlush(); w*=0.9;
|
|
|
+ tnsDrawCross(LA_COLOR3(root->GLocation),-w,w,-w,w,-w,w); tnsColor4dv(laThemeColor(_LA_THEME_3D_VIEW,LA_BT_BORDER));
|
|
|
+ tnsPackAs(GL_LINES); glLineWidth(2);
|
|
|
+ tnsFlush(); glLineWidth(1);
|
|
|
+}
|
|
|
|
|
|
//===================================================================[Material]
|
|
|
|
|
@@ -4175,3 +4226,39 @@ void tnsDrawFloor(int Size, int Span, int *ShowAxis){
|
|
|
tnsPackAs(GL_LINES);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+void tnsDraw2DGrid10(real L, real R, real U, real B, real xmin, real xmax, real ymin, real ymax, real MostDenseW, real MostDenseH,
|
|
|
+ real* color4, real AlphaFactor, int ShowGrid, int TextAlign){
|
|
|
+ real span; real W=R-L, H=B-U, rangeX=xmax-xmin, rangeY=ymax-ymin, dW=rangeX/W, dH=rangeY/H;
|
|
|
+ real MinSpanW=fabs(MostDenseW*dW), MinSpanH=fabs(MostDenseH*dH);
|
|
|
+
|
|
|
+ for(int i=0;i<20;i++){ span=1e-5*pow(10,i); if(span>MinSpanW) break; }
|
|
|
+ real startx=((real)((int)(xmin/span)))*span; real x=startx;
|
|
|
+ while(x<xmax){
|
|
|
+ real lx=tnsInterpolate(L,R,tnsGetRatiod(xmin,xmax,x));
|
|
|
+ tnsVertex2d(lx,U);tnsVertex2d(lx,B); x+=span;
|
|
|
+ } tnsColor4d(LA_COLOR3(color4),color4[3]*AlphaFactor*AlphaFactor*AlphaFactor); tnsPackAs(GL_LINES);
|
|
|
+ x=startx; while(x<xmax){ if((((int)roundf64(x/span))%5)){ x+=span; continue; }
|
|
|
+ real lx=tnsInterpolate(L,R,tnsGetRatiod(xmin,xmax,x));
|
|
|
+ tnsVertex2d(lx,U);tnsVertex2d(lx,B); x+=span;
|
|
|
+ } tnsColor4d(LA_COLOR3(color4),color4[3]*AlphaFactor*AlphaFactor); tnsPackAs(GL_LINES);
|
|
|
+ x=startx; while(x<xmax){ if((((int)roundf64(x/span))%10)){ x+=span; continue; }
|
|
|
+ real lx=tnsInterpolate(L,R,tnsGetRatiod(xmin,xmax,x));
|
|
|
+ tnsVertex2d(lx,U);tnsVertex2d(lx,B); x+=span;
|
|
|
+ } tnsColor4d(LA_COLOR3(color4),color4[3]*AlphaFactor); tnsPackAs(GL_LINES);
|
|
|
+
|
|
|
+ for(int i=0;i<20;i++){ span=1e-5*pow(10,i); if(span>MinSpanH) break; }
|
|
|
+ real starty=((real)((int)(ymin/span)))*span; real y=starty;
|
|
|
+ while(y<ymax){
|
|
|
+ real ly=tnsInterpolate(B,U,tnsGetRatiod(ymin,ymax,y));
|
|
|
+ tnsVertex2d(L,ly);tnsVertex2d(R,ly); y+=span;
|
|
|
+ } tnsColor4d(LA_COLOR3(color4),color4[3]*AlphaFactor*AlphaFactor*AlphaFactor); tnsPackAs(GL_LINES);
|
|
|
+ y=starty; while(y<ymax){ if((((int)roundf64(y/span))%5)){ y+=span; continue; }
|
|
|
+ real ly=tnsInterpolate(B,U,tnsGetRatiod(ymin,ymax,y));
|
|
|
+ tnsVertex2d(L,ly);tnsVertex2d(R,ly); y+=span;
|
|
|
+ } tnsColor4d(LA_COLOR3(color4),color4[3]*AlphaFactor*AlphaFactor); tnsPackAs(GL_LINES);
|
|
|
+ y=starty; while(y<ymax){ if((((int)roundf64(y/span))%10)){ y+=span; continue; }
|
|
|
+ real ly=tnsInterpolate(B,U,tnsGetRatiod(ymin,ymax,y));
|
|
|
+ tnsVertex2d(L,ly);tnsVertex2d(R,ly); y+=span;
|
|
|
+ } tnsColor4d(LA_COLOR3(color4),color4[3]*AlphaFactor); tnsPackAs(GL_LINES);
|
|
|
+}
|