Axis/Angle Rotation[erledigt]

Übersicht BlitzBasic Blitz3D

Neue Antwort erstellen

Foppele

Betreff: Axis/Angle Rotation[erledigt]

BeitragMo, Dez 24, 2007 1:43
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi,
wenn sich jemand mit alternativen Rotationsmöglichkeiten, in diesem Fall Axis/Angle auskennt, wäre es nett er würde mal einen Blick hierdrauf werfen.

[EDIT] Ich hab den Code nochmal geändert, das Kreuzprodukt wird nicht mehr normalisiert. Es funktioniert
leider nur für Rotationsachsen wie 0,0,1 oder 1,0,0 oder 0,-1,0 u.s.w.
Kippt man die Achse, geht's nicht mehr.


Schaut's euch einfach mal an, ich hab die Formel hierher:
http://homepages.inf.ed.ac.uk/...ation.html

Und hier der Code, ich hab mich bemüht es anschaulich zu gestalten:
Code: [AUSKLAPPEN]

Graphics3D 640,480,32,2
SetBuffer BackBuffer()
frametimer= CreateTimer(30)


light=CreateLight(2)
LightColor light,50,50,50
RotateEntity light,0,0,0
PositionEntity light,0,5,-2


Global dummy=CreatePivot()
Global cam=CreateCamera(dummy)
CameraClsColor cam,12,12,100
PositionEntity cam,0,0,-10
PointEntity cam,dummy

CameraZoom cam,4


Type lineType
Field mesh
Field alpha#
Field destroy
End Type
Global l.lineType






angle#=0
achsenneigung#=0


While Not KeyHit(1)


   
If KeyDown(30)  Then TurnEntity dummy,0,1,0
If KeyDown(32)  Then TurnEntity dummy,0,-1,0

   
If KeyDown(200)   Then achsenneigung = achsenneigung+0.05
If KeyDown(208) Then achsenneigung = achsenneigung-0.05


;------------------------------------------------

angle = (angle+5) Mod 360   ; Rotationswinkel


vec1X# = 1     ;Erster Vektor der rotiert wird
vec1Y# = 1
vec1Z# = 0
TFormNormal vec1X,vec1Y,vec1Z,0,0
vec1X = TFormedX#()
vec1Y = TFormedY#()
vec1Z = TFormedZ#()


vec2X# = 1      ; Rotationsachse
vec2Y# = achsenneigung
vec2Z# = 0
TFormNormal vec2X,vec2Y,vec2Z,0,0
vec2X = TFormedX#()
vec2Y = TFormedY#()
vec2Z = TFormedZ#()




crossX# = vec1Y*vec2Z - vec2Y*vec1Z  ; Kreuzprodukt vec1 + Achse
crossY# = vec1Z*vec2X - vec2Z*vec1X
crossZ# = vec1X*vec2Y - vec2X*vec1Y




vec1X = vec1X*Cos#(angle) + vec2X*(vec2X*vec1X)*(1-Cos#(angle)) + crossX*Sin#(angle) ; Axis/Angle Rotation
vec1Y = vec1Y*Cos#(angle) + vec2Y*(vec2Y*vec1Y)*(1-Cos#(angle)) + crossY*Sin#(angle)
vec1Z = vec1Z*Cos#(angle) + vec2Z*(vec2Z*vec1Z)*(1-Cos#(angle)) + crossZ*Sin#(angle)
TFormNormal vec1X,vec1Y,vec1Z,0,0
vec1X = TFormedX#()
vec1Y = TFormedY#()
vec1Z = TFormedZ#()



;------------------------------------------------------------------------------------


vec3X# = 0.5    ; Zweiter Vektor der rotiert wird
vec3Y# = -1
vec3Z# = 0
TFormNormal vec3X,vec3Y,vec3Z,0,0
vec3X = TFormedX#()
vec3Y = TFormedY#()
vec3Z = TFormedZ#()


cross2X# = vec3Y*vec2Z - vec2Y*vec3Z   ; Kreuzprodukt vec3 + Achse
cross2Y# = vec3Z*vec2X - vec2Z*vec3X
cross2Z# = vec3X*vec2Y - vec2X*vec3Y




vec3X = vec3X*Cos#(angle) + vec2X*(vec2X*vec3X)*(1-Cos#(angle)) + cross2X*Sin#(angle)   ; Axis/Angle Rotation
vec3Y = vec3Y*Cos#(angle) + vec2Y*(vec2Y*vec3Y)*(1-Cos#(angle)) + cross2Y*Sin#(angle)
vec3Z = vec3Z*Cos#(angle) + vec2Z*(vec2Z*vec3Z)*(1-Cos#(angle)) + cross2Z*Sin#(angle)
TFormNormal vec3X,vec3Y,vec3Z,0,0
vec3X = TFormedX#()
vec3Y = TFormedY#()
vec3Z = TFormedZ#()





dot1to2# = (vec1X*vec2X) + (vec1Y*vec2Y) + (vec1Z*vec2Z)   ; Dotproduct vec1 + Achse

dot3to2# = (vec3X*vec2X) + (vec3Y*vec2Y) + (vec3Z*vec2Z)   ; Dotproduct vec3 + Achse

dot3to1# = (vec3X*vec1X) + (vec3Y*vec1Y) + (vec3Z*vec1Z)   ; Dotproduct vec3 + vec1






l.lineType = New lineType                           ; Zeichne Vektoren
l\mesh = createLine(0,0,0,vec1X,vec1Y,vec1Z,255,0,0)
l\destroy = 20
l\alpha = 1

l.lineType = New lineType
l\mesh = createLine(0,0,0,vec2X,vec2Y,vec2Z,255,255,0)
l\destroy = 20
l\alpha = 1


l.lineType = New lineType
l\mesh = createLine(0,0,0,vec3X,vec3Y,vec3Z,0,255,0)
l\destroy = 20
l\alpha = 1


For l.lineType = Each lineType

   l\alpha = l\alpha - 0.05
   EntityAlpha l\mesh,l\alpha
   l\destroy = l\destroy - 1
   If l\destroy = 0 Then
      FreeEntity l\mesh
      Delete l
   EndIf
   
Next



   CameraClsMode(cam,1,1)
   WireFrame(0)
   RenderWorld()


   CameraClsMode(cam,0,0)
   WireFrame(1)
   RenderWorld()
   
   
   
   
   
Text 10,10, "Winkel vec1 (rot)  -> Achse (gelb)"
Text 10,25, "Winkel vec3 (grün) -> Achse (gelb)"
Text 10,40, "Winkel vec3 (grün) -> vec1 (rot)"

Text 300,10, ACos(dot1to2)
Text 300,25, ACos(dot3to2)
Text 300,40, ACos(dot3to1)   

Text 250,400, " Kamerasteuerung a,d"
Text 250,415, " Achse kippen Pfeiltasten"
   



   WaitTimer frametimer
   
   Flip 0
   
   
Wend   



;------------------------------------------------------------------

Function createLine(x1#,y1#,z1#, x2#,y2#,z2#, r,b,g, mesh=0)
   
   If mesh = 0 Then
      mesh=CreateMesh()
      EntityFX(mesh,16)
      surf=CreateSurface(mesh)   
      verts = 0   
   
      AddVertex surf,x1#,y1#,z1#,0,0
   Else
      surf = GetSurface(mesh,1)
      verts = CountVertices(surf)-1
   End If
   
   AddVertex surf,(x1#+x2#)/2,(y1#+y2#)/2,(z1#+z2#)/2,0,0

   AddVertex surf,x2#,y2#,z2#,1,0
   
   AddTriangle surf,verts,verts+2,verts+1
   
   EntityColor mesh,r,b,g

   
   Return mesh
End Function


[EDIT2]
Laut diesem Beispiel...
http://local.wasp.uwa.edu.au/~...ry/rotate/
funktioniert es auch nur wenn die Rotationsachse auf einer der Hauptachsen liegt...
  • Zuletzt bearbeitet von Foppele am Mi, Dez 26, 2007 3:16, insgesamt 2-mal bearbeitet

hectic

Sieger des IS Talentwettbewerb 2006

BeitragMo, Dez 24, 2007 2:07
Antworten mit Zitat
Benutzer-Profile anzeigen
Du könntest z.B. deine 3D-Linien an ein Pivot hängen und dieses dann drehen. Dann hättest du das Problem nicht mehr. Die Positionen der Linien kannst du dann normal (unabhängig der Pivotrotation) bewegen.
Download der Draw3D2 V.1.1 für schnelle Echtzeiteffekte über Blitz3D

Foppele

BeitragMo, Dez 24, 2007 2:14
Antworten mit Zitat
Benutzer-Profile anzeigen
Aber ich will doch keine Linien rotieren Wink
Die dienen nur der Veranschaulichung.
(Ich will eigentlich eine funktionierende Axis/Angle Rotationsfunktion)

Neue Antwort erstellen


Übersicht BlitzBasic Blitz3D

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group