

It's pretty easy (once you understand) to convert quaternions into a rot matrix for opengl and then send the matrix to opengl.
Hi Netmaestro,netmaestro wrote:You can ZoomSprite3D() them to a much larger size and if you use Sprite3DQuality(1) they will look quite nice. How much bigger do you need them?
Maybe this is enoughSeregaZ wrote:anybody knows how to make some group of sprites?
i have 2 images. one is body, second is some item over this body. centres of this images is not the same:
how to correctly rotate both of them?
Code: Select all
;
; modified PB Sprite3D example
;
If InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester("Error", "Sprite system can't be initialized", 0)
End
EndIf
If InitSprite3D() = 0
MessageRequester("Error", "Sprite3D system can't be initialized correctly", 0)
End
EndIf
Procedure DisplaySprite3DRotatedAround(sprite3D,centerX,centerY,angle.f,translate=0)
RotateSprite3D(sprite3D,angle,#PB_Absolute)
DisplaySprite3D(sprite3D,
Sin(Radian(angle))*translate + centerX - SpriteWidth (sprite3D)*0.5,
-Cos(Radian(angle))*translate + centerY - SpriteHeight(sprite3D)*0.5)
EndProcedure
If OpenWindow(0, 0, 0, 800, 600, "Rotate Sprite3D",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0),0,0,800,600)
CreateSprite(0, 128,128, #PB_Sprite_Texture)
If StartDrawing(SpriteOutput(0))
Box(0,0,SpriteWidth(0),SpriteHeight(0),RGB(0,0,255))
StopDrawing()
EndIf
CreateSprite3D(0, 0)
CreateSprite(1, 32,32, #PB_Sprite_Texture)
If StartDrawing(SpriteOutput(1))
Box(0,0,SpriteWidth(1),SpriteHeight(1),RGB(0,128,0))
StopDrawing()
EndIf
CreateSprite3D(1, 1)
CreateSprite(2, 32,32, #PB_Sprite_Texture)
If StartDrawing(SpriteOutput(2))
Box(0,0,SpriteWidth(2),SpriteHeight(2),RGB(255,255,0))
StopDrawing()
EndIf
CreateSprite3D(2, 2)
Sprite3DQuality(#PB_Sprite3D_BilinearFiltering)
Define angle.f
Repeat
Repeat
Event = WindowEvent()
If Event = #PB_Event_CloseWindow
Quit = #True
EndIf
Until Event = 0
FlipBuffers()
ClearScreen(RGB(0,50,128))
; Draw our sprites
;
If Start3D()
DisplaySprite3DRotatedAround(0,400,300,angle) ; rotate blue box around middle of screen
DisplaySprite3DRotatedAround(1,400,300,angle,64) ; rotate green box around middle of screen + offset 64
DisplaySprite3DRotatedAround(1,400,300,angle,150) ; rotate green box around middle of screen + offset 150
DisplaySprite3DRotatedAround(2,400,300,angle,-64) ; rotate yellow box around middle of screen - offset 64
DisplaySprite3DRotatedAround(2,400,300,-angle ,115) ; rotate yellow box around middle of screen + offset 115, negative angle
DisplaySprite3DRotatedAround(2,400,300,-angle+20,115) ; rotate yellow box around middle of screen + offset 115, negative angle + 20 degree
DisplaySprite3DRotatedAround(2,400,300,-angle+40,115) ; rotate yellow box around middle of screen + offset 115, negative angle + 40 degree
DisplaySprite3DRotatedAround(2,400,300,-angle+60,115) ; rotate yellow box around middle of screen + offset 115, negative angle + 60 degree
DisplaySprite3DRotatedAround(0,150,150,angle) ; rotate blue box around 150,150
DisplaySprite3DRotatedAround(2,150,150,angle ,64) ; rotate yellow box around 150,150 + offset 64
DisplaySprite3DRotatedAround(2,150,150,angle+ 90,64) ; rotate yellow box around 150,150 + offset 64 + 90 degree
DisplaySprite3DRotatedAround(2,150,150,angle+180,64) ; rotate yellow box around 150,150 + offset 64 +180 degree
DisplaySprite3DRotatedAround(2,150,150,angle+270,64) ; rotate yellow box around 150,150 + offset 64 +270 degree
Stop3D()
EndIf
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf
angle + 1
Until Quit = #True
Else
MessageRequester("Error", "Can't open screen !", 0)
EndIf
EndIf
Ahh, OK. You want to get middle point of the green box after blue box got rotated. Use GetRotatedPointX() and GetRotatedPointY():SeregaZ wrote:code is awesome! but it means center of this two images must be the same (coordinates)? in my case centres of images is individual. how to use this code for rotation blue object to right and green object to left?
Code: Select all
;
; modified PB Sprite3D example
;
If InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester("Error", "Sprite system can't be initialized", 0)
End
EndIf
If InitSprite3D() = 0
MessageRequester("Error", "Sprite3D system can't be initialized correctly", 0)
End
EndIf
Procedure DisplaySprite3DRotatedAround(sprite3D,centerX,centerY,angle.f,translate=0, transparency=255)
RotateSprite3D(sprite3D,angle,#PB_Absolute)
DisplaySprite3D(sprite3D,
Sin(Radian(angle))*translate + centerX - SpriteWidth (sprite3D)*0.5,
-Cos(Radian(angle))*translate + centerY - SpriteHeight(sprite3D)*0.5,
transparency)
EndProcedure
Procedure DisplaySprite3DAround(sprite3D, centerX, centerY, Transparency=255)
DisplaySprite3D(sprite3D, centerX - SpriteWidth (sprite3D)*0.5, centerY - SpriteHeight(sprite3D)*0.5, Transparency)
EndProcedure
Macro GetRotatedPoint(centerX, centerY, angle, translateX, translateY)
(centerX + (translateX)*Cos(Radian(angle)) - (translateY) * Sin(Radian(angle))),
(centerY + (translateX)*Sin(Radian(angle)) + (translateY) * Cos(Radian(angle)))
EndMacro
Procedure GetRotatedPointX(centerX, centerY, angle.f, translateX, translateY)
ProcedureReturn centerX + (translateX)*Cos(Radian(angle)) - (translateY) * Sin(Radian(angle))
EndProcedure
Procedure GetRotatedPointY(centerX, centerY, angle.f, translateX, translateY)
ProcedureReturn centerY + (translateX)*Sin(Radian(angle)) + (translateY) * Cos(Radian(angle))
EndProcedure
If OpenWindow(0, 0, 0, 800, 600, "Rotate Sprite3D",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0),0,0,800,600)
CreateSprite(0, 128,128, #PB_Sprite_Texture)
If StartDrawing(SpriteOutput(0))
Box(0,0,SpriteWidth(0),SpriteHeight(0),RGB(0,0,255))
StopDrawing()
EndIf
CreateSprite3D(0, 0)
CreateSprite(1, 32,32, #PB_Sprite_Texture)
If StartDrawing(SpriteOutput(1))
Box(0,0,SpriteWidth(1),SpriteHeight(1),RGB(0,128,0))
StopDrawing()
EndIf
CreateSprite3D(1, 1)
CreateSprite(2, 32,32, #PB_Sprite_Texture)
If StartDrawing(SpriteOutput(2))
Box(0,0,SpriteWidth(2),SpriteHeight(2),RGB(255,255,0))
StopDrawing()
EndIf
CreateSprite3D(2, 2)
Sprite3DQuality(#PB_Sprite3D_BilinearFiltering)
Define angle.f
Repeat
Repeat
Event = WindowEvent()
If Event = #PB_Event_CloseWindow
Quit = #True
EndIf
Until Event = 0
FlipBuffers()
ClearScreen(RGB(0,50,128))
; Draw our sprites
;
If Start3D()
DisplaySprite3DRotatedAround(0,400,300,angle) ; rotate blue box around middle of screen
DisplaySprite3DRotatedAround(1,400,300,angle,64) ; rotate green box around middle of screen + offset 64
DisplaySprite3DRotatedAround(1,400,300,angle,150) ; rotate green box around middle of screen + offset 150
DisplaySprite3DRotatedAround(2,400,300,angle,-64) ; rotate yellow box around middle of screen - offset 64
DisplaySprite3DRotatedAround(2,400,300,-angle ,115) ; rotate yellow box around middle of screen + offset 115, negative angle
DisplaySprite3DRotatedAround(2,400,300,-angle+20,115) ; rotate yellow box around middle of screen + offset 115, negative angle + 20 degree
DisplaySprite3DRotatedAround(2,400,300,-angle+40,115) ; rotate yellow box around middle of screen + offset 115, negative angle + 40 degree
DisplaySprite3DRotatedAround(2,400,300,-angle+60,115) ; rotate yellow box around middle of screen + offset 115, negative angle + 60 degree
DisplaySprite3DRotatedAround(0,150,150,angle) ; rotate blue box around 150,150
DisplaySprite3DRotatedAround(2,150,150,angle ,64) ; rotate yellow box around 150,150 + offset 64
DisplaySprite3DRotatedAround(2,150,150,angle+ 90,64) ; rotate yellow box around 150,150 + offset 64 + 90 degree
DisplaySprite3DRotatedAround(2,150,150,angle+180,64) ; rotate yellow box around 150,150 + offset 64 +180 degree
DisplaySprite3DRotatedAround(2,150,150,angle+270,64) ; rotate yellow box around 150,150 + offset 64 +270 degree
DisplaySprite3DRotatedAround(0,650,450,angle) ; blue box ...
x = GetRotatedPointX(650,450,angle,0,-64) ; and some small boxes at the border of blue box
y = GetRotatedPointY(650,450,angle,0,-64)
DisplaySprite3DRotatedAround(1,x,y,-angle*2)
x = GetRotatedPointX(650,450,angle,0, 64)
y = GetRotatedPointY(650,450,angle,0, 64)
DisplaySprite3DRotatedAround(1,x,y, angle*2)
x = GetRotatedPointX(650,450,angle,-64,0)
y = GetRotatedPointY(650,450,angle,-64,0)
DisplaySprite3DRotatedAround(1,x,y,angle,0,128)
x = GetRotatedPointX(650,450,angle,64,0)
y = GetRotatedPointY(650,450,angle,64,0)
DisplaySprite3DRotatedAround(1,x,y,angle,0,128)
DisplaySprite3DRotatedAround(2,GetRotatedPoint(650,450,angle, 64,-64), angle*2.5,0,128)
DisplaySprite3DRotatedAround(2,GetRotatedPoint(650,450,angle,-64, 64),-angle*0.5,0,128)
RotateSprite3D(2,0,#PB_Absolute)
DisplaySprite3DAround(2,GetRotatedPoint(650,450,angle, 64, 64))
DisplaySprite3DAround(2,GetRotatedPoint(650,450,angle,-64,-64))
;DisplaySprite3DRotatedAround(0,650,450,angle,0,64)
Stop3D()
EndIf
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf
angle + 1
Until Quit = #True
Else
MessageRequester("Error", "Can't open screen !", 0)
EndIf
EndIf
Code: Select all
;
; modified PB Sprite3D example
;
If InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester("Error", "Sprite system can't be initialized", 0)
End
EndIf
;If InitSprite3D() = 0
; MessageRequester("Error", "Sprite3D system can't be initialized correctly", 0)
; End
;EndIf
Procedure DisplaySprite3DRotatedAround(sprite3D,centerX,centerY,angle.f,translate=0, transparency=255)
RotateSprite(sprite3D,angle,#PB_Absolute)
DisplayTransparentSprite(sprite3D,
Sin(Radian(angle))*translate + centerX - SpriteWidth (sprite3D)*0.5,
-Cos(Radian(angle))*translate + centerY - SpriteHeight(sprite3D)*0.5,
transparency)
EndProcedure
Procedure DisplaySprite3DAround(sprite3D, centerX, centerY, Transparency=255)
DisplayTransparentSprite(sprite3D, centerX - SpriteWidth (sprite3D)*0.5, centerY - SpriteHeight(sprite3D)*0.5, Transparency)
EndProcedure
Macro GetRotatedPoint(centerX, centerY, angle, translateX, translateY)
(centerX + (translateX)*Cos(Radian(angle)) - (translateY) * Sin(Radian(angle))),
(centerY + (translateX)*Sin(Radian(angle)) + (translateY) * Cos(Radian(angle)))
EndMacro
Procedure GetRotatedPointX(centerX, centerY, angle.f, translateX, translateY)
ProcedureReturn centerX + (translateX)*Cos(Radian(angle)) - (translateY) * Sin(Radian(angle))
EndProcedure
Procedure GetRotatedPointY(centerX, centerY, angle.f, translateX, translateY)
ProcedureReturn centerY + (translateX)*Sin(Radian(angle)) + (translateY) * Cos(Radian(angle))
EndProcedure
If OpenWindow(0, 0, 0, 800, 600, "Rotate Sprite3D",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0),0,0,800,600)
CreateSprite(0, 128,128, #PB_Sprite_AlphaBlending)
If StartDrawing(SpriteOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,SpriteWidth(0),SpriteHeight(0),RGBA(0,0,255,255))
StopDrawing()
EndIf
;CreateSprite3D(0, 0)
CreateSprite(1, 32,32, #PB_Sprite_AlphaBlending)
If StartDrawing(SpriteOutput(1))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,SpriteWidth(1),SpriteHeight(1),RGBA(0,128,0,255))
StopDrawing()
EndIf
;CreateSprite3D(1, 1)
CreateSprite(2, 32,32, #PB_Sprite_AlphaBlending)
If StartDrawing(SpriteOutput(2))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,SpriteWidth(2),SpriteHeight(2),RGBA(255,255,0,255))
StopDrawing()
EndIf
;CreateSprite3D(2, 2)
;Sprite3DQuality(#PB_Sprite3D_BilinearFiltering)
SpriteQuality(#PB_Sprite_BilinearFiltering)
Define angle.f
Repeat
Repeat
Event = WindowEvent()
If Event = #PB_Event_CloseWindow
Quit = #True
EndIf
Until Event = 0
FlipBuffers()
ClearScreen(RGB(0,50,128))
; Draw our sprites
;
;If Start3D()
DisplaySprite3DRotatedAround(0,400,300,angle) ; rotate blue box around middle of screen
DisplaySprite3DRotatedAround(1,400,300,angle,64) ; rotate green box around middle of screen + offset 64
DisplaySprite3DRotatedAround(1,400,300,angle,150) ; rotate green box around middle of screen + offset 150
DisplaySprite3DRotatedAround(2,400,300,angle,-64) ; rotate yellow box around middle of screen - offset 64
DisplaySprite3DRotatedAround(2,400,300,-angle ,115) ; rotate yellow box around middle of screen + offset 115, negative angle
DisplaySprite3DRotatedAround(2,400,300,-angle+20,115) ; rotate yellow box around middle of screen + offset 115, negative angle + 20 degree
DisplaySprite3DRotatedAround(2,400,300,-angle+40,115) ; rotate yellow box around middle of screen + offset 115, negative angle + 40 degree
DisplaySprite3DRotatedAround(2,400,300,-angle+60,115) ; rotate yellow box around middle of screen + offset 115, negative angle + 60 degree
DisplaySprite3DRotatedAround(0,150,150,angle) ; rotate blue box around 150,150
DisplaySprite3DRotatedAround(2,150,150,angle ,64) ; rotate yellow box around 150,150 + offset 64
DisplaySprite3DRotatedAround(2,150,150,angle+ 90,64) ; rotate yellow box around 150,150 + offset 64 + 90 degree
DisplaySprite3DRotatedAround(2,150,150,angle+180,64) ; rotate yellow box around 150,150 + offset 64 +180 degree
DisplaySprite3DRotatedAround(2,150,150,angle+270,64) ; rotate yellow box around 150,150 + offset 64 +270 degree
DisplaySprite3DRotatedAround(0,650,450,angle) ; blue box ...
x = GetRotatedPointX(650,450,angle,0,-64) ; and some small boxes at the border of blue box
y = GetRotatedPointY(650,450,angle,0,-64)
DisplaySprite3DRotatedAround(1,x,y,-angle*2)
x = GetRotatedPointX(650,450,angle,0, 64)
y = GetRotatedPointY(650,450,angle,0, 64)
DisplaySprite3DRotatedAround(1,x,y, angle*2)
x = GetRotatedPointX(650,450,angle,-64,0)
y = GetRotatedPointY(650,450,angle,-64,0)
DisplaySprite3DRotatedAround(1,x,y,angle,0,128)
x = GetRotatedPointX(650,450,angle,64,0)
y = GetRotatedPointY(650,450,angle,64,0)
DisplaySprite3DRotatedAround(1,x,y,angle,0,128)
DisplaySprite3DRotatedAround(2,GetRotatedPoint(650,450,angle, 64,-64), angle*2.5,0,128)
DisplaySprite3DRotatedAround(2,GetRotatedPoint(650,450,angle,-64, 64),-angle*0.5,0,128)
RotateSprite(2,0,#PB_Absolute)
DisplaySprite3DAround(2,GetRotatedPoint(650,450,angle, 64, 64))
DisplaySprite3DAround(2,GetRotatedPoint(650,450,angle,-64,-64))
;DisplaySprite3DRotatedAround(0,650,450,angle,0,64)
;Stop3D()
;EndIf
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf
angle + 1
Until Quit = #True
Else
MessageRequester("Error", "Can't open screen !", 0)
EndIf
EndIf