~Helfer~
Math_Max/Min ( Value, Max/Min )
->Dasselbe wie If Value < Min then Value = Min ElseIf Value > Max Then Value = Max
Math_MaxMin ( Value, Max, Min )
->Kombination aus Math_Max und Math_Min.
Math_Clip ( Value, Low, High )
->Begrenzt einen Wert, so dass er nie über {High} und unter {Low} sein kann.
Math_RGBHSV ( R, G, B )
->Wandelt R G B in H S V um. Array HSV#[2], S und V sind von 0 bis 1
Math_HSVRGB ( H, S, V )
->Wandelt H S V in R G B um. Array RGB#[2].
EntityRenderToImage ( iCam, iEnt, iImg )
->Rendert ein Entity in ein Bild. ERTPos#[2] setzt die Renderposition(um der Welt aus dem Weg zu gehen), ERTRot#[2] die Rotation. iEnt darf nur per ScaleEntity skaliert werden. iCam muss eine Min-Range von 0.005 haben.
EntityRenderToTexture ( iCam, iEnt, iImg )
->Rendert ein Entity in eine Textur. Siehe EntityRenderToImage
EntityScale (Entity, Axis )
->Wird von EntityRenderTo* benötigt um die Distanz zu errechnen.
SplitString(String$, Splitter$)
->Splitted einen String an dem Zeichen Splitter$(Standard "|"). Mit SplitCount und SplittedString habt ihr Zugriff auf das was rauskommt.
SafeText(String$)
->Ersetzt nicht darstellbare Zeichen mit [ASCII-Code].
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN] Global ERTPos#[2], ERTRot#[2] Const ES_AxisX = 0, ES_AxisY = 1, ES_AxisZ = 2
Function EntityRenderToImage(iCam, iEnt, iImg) Local CP#[2], EP#[2], CR#[2], Buffer = GraphicsBuffer(), SX#, SY#, SZ#, Dist#, IW = ImageWidth(iImg), IH = ImageHeight(iImg), IB = ImageBuffer(iImg) CP[0] = EntityX(iCam):CP[1] = EntityY(iCam):CP[2] = EntityZ(iCam) CR[0] = EntityPitch(iCam):CR[1] = EntityYaw(iCam):CR[2] = EntityRoll(iCam) EP[0] = EntityX(iEnt):EP[1] = EntityY(iEnt):EP[2] = EntityZ(iEnt) SX = EntityScale(iEnt,ES_AxisX):SY = EntityScale(iEnt,ES_AxisY):SZ = EntityScale(iEnt,ES_AxisZ) Dist# = Sqr((SX*SX)+(SY*SY)+(SZ*SZ)) PositionEntity iCam, ERTPos[0], ERTPos[1], ERTPos[2] PositionEntity iEnt, ERTPos[0], ERTPos[1], ERTPos[2]+Dist RotateEntity iCam, 0, 0, 0 EntityParent iEnt, iCam RotateEntity iCam, ERTRot[0], ERTRot[1], ERTRot[2] CameraViewport iCam, 0, 0, IW, IH RenderWorld CopyRect 0,0,IW,IH,0,0,Buffer,IB CameraViewport iCam, 0, 0, GraphicsWidth(), GraphicsHeight() RotateEntity iCam, 0, 0, 0 EntityParent iEnt, 0 PositionEntity iCam, CP[0],CP[1],CP[2] PositionEntity iEnt, EP[0],EP[1],EP[2] RotateEntity iCam, CR[0],CR[1],CR[2] End Function Function EntityRenderToTexture(iCam, iEnt, iTex) Local CP#[2], EP#[2], CR#[2], Buffer = GraphicsBuffer(), SX#, SY#, SZ#, Dist#, IW = TextureWidth(iTex), IH = TextureHeight(iTex), IB = TextureBuffer(iTex) CP[0] = EntityX(iCam):CP[1] = EntityY(iCam):CP[2] = EntityZ(iCam) CR[0] = EntityPitch(iCam):CR[1] = EntityYaw(iCam):CR[2] = EntityRoll(iCam) EP[0] = EntityX(iEnt):EP[1] = EntityY(iEnt):EP[2] = EntityZ(iEnt) SX = EntityScale(iEnt,ES_AxisX):SY = EntityScale(iEnt,ES_AxisY):SZ = EntityScale(iEnt,ES_AxisZ) Dist# = Sqr((SX*SX)+(SY*SY)+(SZ*SZ))*0.25 + Sqr(Sqr((SX*SX)+(SY*SY)+(SZ*SZ)))*0.75 PositionEntity iCam, ERTPos[0], ERTPos[1], ERTPos[2] PositionEntity iEnt, ERTPos[0], ERTPos[1], ERTPos[2]+Dist RotateEntity iCam, 0, 0, 0 EntityParent iEnt, iCam RotateEntity iCam, ERTRot[0], ERTRot[1], ERTRot[2] CameraViewport iCam, 0, 0, IW, IH RenderWorld CopyRect 0,0,IW,IH,0,0,Buffer,IB CameraViewport iCam, 0, 0, GraphicsWidth(), GraphicsHeight() RotateEntity iCam, 0, 0, 0 EntityParent iEnt, 0 PositionEntity iCam, CP[0],CP[1],CP[2] PositionEntity iEnt, EP[0],EP[1],EP[2] RotateEntity iCam, CR[0],CR[1],CR[2] End Function Function EntityScale#( Entity, Axis ) VX# = GetMatElement( Entity, Axis, 0 ) VY# = GetMatElement( Entity, Axis, 1 ) VZ# = GetMatElement( Entity, Axis, 2 ) Return Sqr( VX#*VX# + VY#*VY# + VZ#*VZ# ) End Function
Global HSV#[2], RGB#[2]
Function Math_MaxMin#(Value#, Max#, Min#) If Value> Max Then Return Max If Value < Min Then Return Min Return Value End Function Function Math_Max#(Value#, Max#) If Value> Max Then Return Max Return Value End Function Function Math_Min#(Value#, Min#) If Value < Min Then Return Min Return Value End Function Function Math_Clip#(Value#, Low#, High#) Local Out#, Diff# Diff = High-Low:Out = Value-Low If (Out >= Diff) Then Out = Out - Floor(Out/Diff)*Diff If (Out < 0) Then Out = Out - Floor(Out/Diff)*Diff Return Low+Out End Function Function Math_RGBHSV(R,G,B) Local maxC#, minC#, delta#, dr#, dg#, db# R = R/255.0:G = G/255.0:B = B/255.0 maxC = Math_Min(Math_Min(R,G),B) minC = Math_Max(Math_Max(R,G),B) delta = maxC - minC HSV[0] = 0:HSV[1] = 0:HSV[2] = maxC If delta = 0 HSV[0] = 0:HSV[1] = 0 Else HSV[1] = delta / maxC dr = 60*(maxC - R)/delta + 180 dg = 60*(maxC - G)/delta + 180 db = 60*(maxC - B)/delta + 180 If R = maxC HSV[0] = db - dg ElseIf G = maxC HSV[0] = 120 + dr - db Else HSV[0] = 240 + dg - dr EndIf EndIf HSV[0] = Math_Clp(HSV[0],0,360) End Function Function Math_HSVRGB(H#,S#,V#) Local m#, n#, f#, i H = Math_Clp(H,0,360)/60.0 If H = S And S = 0 RGB[0] = V RGB[1] = V RGB[2] = V EndIf i = Floor(H) f = H - i If Not (i Mod 2) Then f = 1 - f m = V * (1-S) n = V * (1-S*f) Select i Case 6,0 RGB[0] = V*255 RGB[1] = n*255 RGB[2] = m*255 Case 1 RGB[0] = n*255 RGB[1] = V*255 RGB[2] = m*255 Case 2 RGB[0] = m*255 RGB[1] = V*255 RGB[2] = n*255 Case 3 RGB[0] = m*255 RGB[1] = n*255 RGB[2] = V*255 Case 4 RGB[0] = n*255 RGB[1] = m*255 RGB[2] = V*255 Case 5 RGB[0] = V*255 RGB[1] = m*255 RGB[2] = n*255 End Select End Function
Dim SplittedString$(1) Global SplitCount
Function SplitString(In$, StringSplitter$ = "|") Local InLength% = Len(In) Local SplitLength% = Len(StringSplitter) Local CountPos%, InPos%, SplitIndex% Local SplitTest$, LineText$ SplitCount = 0 For CountPos = 1 To InLength-(SplitLength-1) SplitTest = Mid(In,CountPos,1) If SplitTest = StringSplitter Then SplitCount = SplitCount + 1 Next Dim SplittedString(SplitCount) While Not InPos = Len(In) InPos = InPos + 1 SplitTest = Mid(In, InPos, SplitLength) Local Char$ = Left(SplitTest, 1) If SplitTest = StringSplitter Or InPos = InLength If InPos = InLength And SplitTest <> StringSplitter Then LineText = LineText + Char SplittedString(SplitIndex) = LineText SplitIndex = SplitIndex + 1 LineText = "" Else LineText = LineText + Char EndIf Wend End Function
Function SafeText$(sText$) Local sSafeText$ = sText For i = 0 To 31 sSafeText = Replace(sSafeText,Chr(i),"["+i+"]") Next Return sSafeText End Function
~Fixes~
Replace$ ( String$, From$, To$ )
->Behebt den Chr(0) Bug.
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN] Function Replace$(S$,F$,T$,CaseSensitive=0) Local LF = Len(F), Pos Pos = 1 While Not Pos > Len(S)-LF+1 Local Check$ = Mid(S,Pos,LF) If Lower(F) = Lower(Check) And (F = Check Or CaseSensitive=0) S = Left(S,Pos-1)+T+Mid(S,Pos+LF,-1) Pos = Pos + Len(T) EndIf Pos = Pos + 1 Wend Return S End Function
~Changelog~
08.02.2014 00:14 - SplitString ünterstützt nun längere Zeilentrenner
11.12.2011 10:34 - Fixed Math_Clip
29.08.2010 13:18 - Added (Helper) SplitString
29.08.2010 00:53 - Fixed (Helper) EntityScale
28.08.2010 20:58 - Fixed (Fix) Replace
|