Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 00313 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337 00338 00339 00340 00341 00342 00343 00344 00345 00346 00347 00348 00349 00350 00351 00352 00353 00354 00355 00356 00357 00358 00359 00360 00361 00362 00363 00364 00365 00366 00367 00368 00369 00370 00371 00372 00373 00374 00375 00376 00377 00378 00379 00380 00381 00382 00383 00384 00385 00386 00387 00388 00389 00390 00391 00392 00393 00394 00395 00396 00397 00398 00399 00400 00401 00402 00403 00404 00405 00406 00407 00408 00409 00410 00411 00412 00413 00414 00415 00416 00417 00418 00419 00420 00421 00422 00423 00424 00425 00426 00427 00428 00429 00430 00431 00432 00433 00434 00435 00436 00437 00438 00439 00440 00441 00442 00443 00444 00445 00446 00447 00448 00449 00450 00451 |
//----------------------------------------------------------- // //----------------------------------------------------------- class TribesTVStudioSplineHandler extends object; var TribesTVStudioTestController controller; struct SplineNode { var Vector location; var float maxDistance; var float viewAngle; var float minZoomDist; var float maxZoomDist; var float Priority; }; struct SplinePath{ var array<SplineNode> nodes; var int lowCrossing; var int highCrossing; var int lastSearchId; }; struct SplineCrossing{ var array<int> connections; }; var array<SplinePath> splines; var array<SplineCrossing> crossings; var int lastSearch; //id that is increased for every search, just to keep us from searching the same spline several times var int curSpline; //the spline the camera currently resides on var float curPos,curSpeed; var Vector location; var int targetNode,targetSpline; //the spline/node closest to the target (on a spline neighbouring the current) var int otherSpline; //the spline we are about to cross over to or has crossovered (sp?) from var bool highCur,highOther; var Vector otherNode1,otherNode2; //the two nodes closest to the curSpline on the otherSpline var int activeCrossing; //the crossing that the above takes place on var int newSpline,newPos; //temp variables when selecting a new spline, to be able to keep the old if they are good enough function FillSplineList(int camSys) { local TribesTVStudioSplineNode mapsn; local SplineNode sn; local int a; //zero all splines.length=0; crossings.length=0; curSpline=-1; //add the splines foreach controller.AllActors(class'TribesTVStudioSplineNode', mapsn) { if(mapsn.SystemNum==camSys){ sn.location=mapsn.location; sn.maxDistance=mapsn.MaxDistance; sn.viewAngle=mapsn.viewAngle; sn.minZoomDist=mapsn.minZoomDist; sn.maxZoomDist=mapsn.maxZoomDist; sn.priority=mapsn.Priority; a=mapsn.splineId; if(a>=splines.length) splines.length=a+1; if(mapsn.nodeId>=splines[a].nodes.length){ splines[a].nodes.length=mapsn.nodeId+1; splines[a].highCrossing=mapsn.crossingId; } if(mapsn.nodeId==0){ splines[a].lowCrossing=mapsn.crossingId; } splines[a].nodes[mapsn.nodeId] = sn; } } //add the connected splines to the crossings for(a=0;a<splines.length;++a){ if(splines[a].lowCrossing!=-1){ if(splines[a].lowCrossing>=crossings.length) crossings.length=splines[a].lowCrossing+1; crossings[splines[a].lowCrossing].connections.length=crossings[splines[a].lowCrossing].connections.length+1; crossings[splines[a].lowCrossing].connections[crossings[splines[a].lowCrossing].connections.length-1]=a; } if(splines[a].highCrossing!=-1){ if(splines[a].highCrossing>=crossings.length) crossings.length=splines[a].highCrossing+1; crossings[splines[a].highCrossing].connections.length=crossings[splines[a].highCrossing].connections.length+1; crossings[splines[a].highCrossing].connections[crossings[splines[a].highCrossing].connections.length-1]=a; } } } //find the spline node closest to the target with los function bool FindBestSplineNode(out float bestdist,Vector targetPos) { local int s,n; bestDist=40000; ++lastSearch; newSpline=-1; for (s = 0; s < splines.length; s++){ if(FindBestNodeInSpline(s,lastSearch,n,bestDist)){ newSpline = s; newPos=n; } } if(newSpline!=-1){ return true; } return false; } function Move(float deltaTime) { local float wantedPos,wantedSpeed; local float dp; if(targetNode!=-1){ wantedPos=FindClosestPos(); wantedSpeed=FindDistance(targetSpline,wantedPos)*1.5; if(wantedSpeed>curSpeed){ curSpeed+=300*deltaTime; if(curSpeed<0) curSpeed/=1+deltaTime; } else { curSpeed-=300*deltaTime; if(curSpeed>0) curSpeed/=1+deltaTime; } //spline->(un)real space magnitude dp=VSize(location-CalcPos(curSpline,curPos+0.001))*1000; curPos+=curSpeed*deltaTime/dp; if(curPos<-1){ SwitchSpline(false,-1-curPos); } else if(curPos>splines[curSpline].nodes.length){ SwitchSpline(true,curPos-splines[curSpline].nodes.length); } location=CalcPos(curSpline,curPos); controller.SetPosition(location); } controller.SetRotation(controller.CameraTrack2(DeltaTime)); } //swtich from one spline to the next using the active crossing and other values function SwitchSpline(bool high,float newPos) { local int s; if(highOther){ curPos=splines[otherSpline].nodes.length-1-newPos; s=curSpline; curSpline=otherSpline; SetOther(s,activeCrossing); highCur=true; curSpeed=-abs(curSpeed); } else { curPos=newPos; s=curSpline; curSpline=otherSpline; SetOther(s,activeCrossing); highCur=false; curSpeed=abs(curSpeed); } } //finds the distance and direction from the current pos to a given pos function float FindDistance(int spline,float pos) { local float dist; dist=VSize(CalcPos(spline,pos)-location); if(spline==curSpline){ if(pos>curPos) return dist; else return -dist; } if(highCur) return dist; else return -dist; } //calculate the camera location from a position on a spline using cardianal splines function Vector CalcPos(int spline,float pos) { local Vector v_1,v0,v1,v2; local int node,maxNode; local float u; local Vector a,b,c,d; maxNode=splines[spline].nodes.length-1; if(pos>=0) node=int(pos); else node=int(pos)-1; u=pos-node; if(node>0){ v_1=splines[spline].nodes[node-1].location; }else{ if(node==0){ if(otherSpline==spline || activeCrossing!=splines[spline].lowCrossing){ v_1=splines[spline].nodes[0].location*2 - splines[spline].nodes[1].location; } else { v_1=otherNode1; } } else { if(otherSpline==spline || activeCrossing!=splines[spline].lowCrossing){ v_1=splines[spline].nodes[0].location*2 - splines[spline].nodes[1].location; } else { v_1=otherNode2; } } } if(node>=0){ v0=splines[spline].nodes[node].location; } else { if(otherSpline==spline || activeCrossing!=splines[spline].lowCrossing){ v0=splines[spline].nodes[0].location*2 - splines[spline].nodes[1].location; } else { v0=otherNode1; } } if(node<maxNode){ v1=splines[spline].nodes[node+1].location; } else { if(otherSpline==spline || activeCrossing!=splines[spline].highCrossing){ v1=splines[spline].nodes[maxNode].location*2 - splines[spline].nodes[maxNode-1].location; } else { v1=otherNode1; } } if(node<maxNode-1){ v2=splines[spline].nodes[node+2].location; } else { if(node==maxNode-1){ if(otherSpline==spline || activeCrossing!=splines[spline].highCrossing){ v2=splines[spline].nodes[maxNode].location*2 - splines[spline].nodes[maxNode-1].location; } else { v2=otherNode1; } } else { if(otherSpline==spline || activeCrossing!=splines[spline].highCrossing){ v2=splines[spline].nodes[maxNode].location*2 - splines[spline].nodes[maxNode-1].location; } else { v2=otherNode2; } } } a=-0.5*v_1 + 1.5*v0 - 1.5*v1 + 0.5*v2; b= 1*v_1 - 2.5*v0 + 2.0*v1 - 0.5*v2; c=-0.5*v_1 + 0.5*v1; d= v0; return u*u*u*a+u*u*b+u*c+d; } //find the position closest to the target between target node +-1 (linearly interpolating the spline) //todo: doesnt try finding nodes over crossings function float FindClosestPos() { local float bestDistSqr,bestPos; local Vector targVec,railVec; local float cDist,closeDistSqr; local Vector targPos; local Vector v0,v1; v0=splines[targetSpline].nodes[targetNode].location; targPos=controller.camTargetPos; targPos+=Normal(location-targPos)*controller.wantedDist; targVec=targPos-v0; bestDistSqr=targVec Dot targVec; bestPos=targetNode; if(!controller.inViewLastTimer){ return bestPos; } if(targetNode!=0){ v1=splines[targetSpline].nodes[targetNode-1].location; railVec=Normal(v1-v0); cDist=railVec Dot targVec; if(cDist>0){ closeDistSqr=targVec Dot targVec-cDist*cDist; if(closeDistSqr<bestDistSqr){ bestDistSqr=closeDistSqr; bestPos=targetNode-min(cDist/VSize(v0-v1),1); } } } if(targetNode!=splines[targetSpline].nodes.length-1){ v1=splines[targetSpline].nodes[targetNode+1].location; railVec=Normal(v1-v0); cDist=railVec Dot targVec; if(cDist>0){ closeDistSqr=targVec Dot targVec-cDist*cDist; if(closeDistSqr<bestDistSqr){ bestDistSqr=closeDistSqr; bestPos=targetNode+min(cDist/VSize(v0-v1),1); } } } return bestPos; } //recreates the view when splines has been selected //but leave it if we are already close enough to find a fast way to the new target //todo: define when to keep the old camera better function SplineSelected() { local float dist; UpdateGoalNode(); dist=VSize(splines[targetSpline].nodes[targetNode].location-location); if(targetNode==-1 || (!controller.targetLos(location) && dist>500) || dist>2000){ curPos=newPos; curSpline=newSpline; curSpeed=0; location=splines[curSpline].nodes[int(curPos)].location; controller.SetPosition(location,true); controller.FovAngle = splines[curSpline].nodes[int(curPos)].ViewAngle; controller.focuspoint = controller.camTargetPos; controller.SetRotation(controller.CameraTrack2(0)); } } //Sets a new goal node //The camera will aim for a position +-1 from this node on the spline //Only checks the current spline and its neighbours function UpdateGoalNode() { local float bestdist; local int n; local int a,c; targetNode=-1; bestDist=40000; ++lastSearch; if(curSpline==-1) return; if(FindBestNodeInSpline(curSpline,lastSearch,n,bestDist)){ targetNode=n; targetSpline=curSpline; } if(splines[curSpline].lowCrossing!=-1){ c=splines[curSpline].lowCrossing; for(a=0;a<crossings[c].connections.length;++a){ if(FindBestNodeInSpline(crossings[c].connections[a],lastSearch,n,bestDist)){ targetNode=n; targetSpline=crossings[c].connections[a]; highCur=false; SetOther(targetSpline,c); activeCrossing=c; } } } if(splines[curSpline].highCrossing!=-1){ c=splines[curSpline].highCrossing; for(a=0;a<crossings[c].connections.length;++a){ if(FindBestNodeInSpline(crossings[c].connections[a],lastSearch,n,bestDist)){ targetNode=n; targetSpline=crossings[c].connections[a]; highCur=true; SetOther(targetSpline,c); activeCrossing=c; } } } controller.curcam2=targetNode; } //Sets up the other variables function SetOther(int s,int c) { otherSpline=s; if(splines[s].lowCrossing==c){ highOther=false; otherNode1=splines[s].nodes[0].location; otherNode2=splines[s].nodes[1].location; } else { highOther=true; otherNode1=splines[s].nodes[splines[s].nodes.length-1].location; otherNode2=splines[s].nodes[splines[s].nodes.length-2].location; } } //find the spline node closest to the target with los in a specific spline function bool FindBestNodeInSpline(int spline,int searchId,out int bestNode,out float bestDist) { local float dist,modDist; local int n; local bool better; better=false; if(searchId==splines[spline].lastSearchId) return false; splines[spline].lastSearchId=searchId; for (n = 0; n < splines[spline].nodes.length; n++){ dist = VSize(controller.camTargetPos - splines[spline].nodes[n].location); modDist=dist/splines[spline].nodes[n].priority; if ((modDist < bestdist) && dist < splines[spline].nodes[n].maxDistance && controller.TargetLOS(splines[spline].nodes[n].location)){ bestNode=n; bestdist = modDist; better=true; } } if(better) return true; else return false; } function SetFovValues(out float minzoomdist,out float maxzoomdist,out float viewangle) { minzoomdist = splines[curSpline].nodes[int(curPos)].minzoomdist; maxzoomdist = splines[curSpline].nodes[int(curPos)].maxzoomdist; viewangle = splines[curSpline].nodes[int(curPos)].ViewAngle; } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |