Ir ao conteúdo
  • Cadastre-se

Cambalinho

Membro Pleno
  • Posts

    942
  • Cadastrado em

  • Última visita

Tudo que Cambalinho postou

  1. já consegui meter o codigo a funcionar: Option Explicit Private Type POINTAPI x As Long y As Long End Type Private Declare Function LineTo Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Declare Function MoveToEx Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByRef lpPoint As POINTAPI) As Long Dim ScreenWidth As Integer Dim ScreenHeight As Integer Dim ScreenHalfHeight As Integer Dim RenderDelay As Integer Dim RayCastingPrecision As Integer Dim PlayerFOV As Integer Dim PlayerPosX As Integer Dim PlayerPosY As Integer Dim PlayerAngle As Double Dim PlayerSpeedMovement As Double Dim PlayerSpeedRotation As Double Dim LevelMap(10) As Variant Dim blnGameLoop As Boolean Const PI As Double = 3.14159265359 Private Function DegreesToRadians(Degrees As Double) As Double DegreesToRadians = Degrees * (PI / 180) End Function Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Dim PlayerCos As Double Dim PlayerSin As Double Dim NewX As Integer Dim NewY As Integer If (KeyCode = vbKeyEscape) Then blnGameLoop = False End ElseIf (KeyCode = vbKeyUp) Then PlayerCos = Cos(DegreesToRadians(PlayerAngle)) * PlayerSpeedMovement PlayerSin = Sin(DegreesToRadians(PlayerAngle)) * PlayerSpeedMovement NewX = PlayerPosX + PlayerCos NewY = PlayerPosY + PlayerSin 'Verficia colisão do player If (LevelMap(Fix(NewY))(Fix(NewX)) = 0) Then PlayerPosX = NewX PlayerPosY = NewY End If ElseIf (KeyCode = vbKeyDown) Then PlayerCos = Cos(DegreesToRadians(PlayerAngle)) * PlayerSpeedMovement PlayerSin = Sin(DegreesToRadians(PlayerAngle)) * PlayerSpeedMovement NewX = PlayerPosX - PlayerCos NewY = PlayerPosY - PlayerSin 'Verficia colisão do player If (LevelMap(Fix(NewY))(Fix(NewX)) = 0) Then PlayerPosX = NewX PlayerPosY = NewY End If ElseIf (KeyCode = vbKeyLeft) Then PlayerAngle = PlayerAngle - PlayerSpeedRotation ElseIf (KeyCode = vbKeyRight) Then PlayerAngle = PlayerAngle + PlayerSpeedRotation End If End Sub Private Sub drawLine(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer, color As ColorConstants) Me.Line (x1, y1)-(x2, y2), color End Sub Private Sub RayCasting() Dim RayAngle As Double Dim RayCos As Double Dim RaySin As Double RayAngle = PlayerAngle - PlayerFOV / 2 RayCos = Cos(DegreesToRadians(RayAngle)) / RayCastingPrecision RaySin = Sin(DegreesToRadians(RayAngle)) / RayCastingPrecision Dim RayCount As Integer For RayCount = 0 To ScreenWidth Dim RayX As Double Dim RayY As Double RayX = PlayerPosX RayY = PlayerPosY 'Detectar se atinge a parede: Dim blnWallHit As Variant blnWallHit = 0 While (blnWallHit < 1) RayX = RayX + RayCos RayY = RayY + RaySin blnWallHit = LevelMap(Fix(RayY))(Fix(RayX)) Wend 'calcular a distancia a tamanho da linha: Dim Distance As Double Distance = Sqr((PlayerPosX - RayX) ^ 2 + (PlayerPosY - RayY) ^ 2) Distance = Distance * Cos(DegreesToRadians(RayAngle - PlayerAngle)) Dim WallHeight As Double WallHeight = Fix(ScreenHalfHeight / Distance) If (WallHeight > ScreenHalfHeight) Then WallHeight = ScreenHalfHeight 'Desenhar a linha da parede: If (blnWallHit = 1) Then drawLine RayCount, ScreenHalfHeight - WallHeight, RayCount, ScreenHalfHeight + WallHeight, vbYellow ElseIf (blnWallHit = 2) Then drawLine RayCount, ScreenHalfHeight - WallHeight, RayCount, ScreenHalfHeight + WallHeight, vbGreen End If blnWallHit = 0 'Incrementar RayAngle = RayAngle + PlayerFOV / ScreenWidth Next RayCount End Sub Private Sub Form_Load() ScreenWidth = 300 ScreenHeight = 200 ScreenHalfHeight = ScreenHeight / 2 RenderDelay = 16 RayCastingPrecision = 10 PlayerFOV = 60 PlayerPosX = 5 PlayerPosY = 3 PlayerAngle = 0 PlayerSpeedMovement = 0.5 PlayerSpeedRotation = 0.2 LevelMap(0) = Array(1, 2, 1, 2, 1, 2, 1, 2, 1, 2) LevelMap(1) = Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 1) LevelMap(2) = Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 1) LevelMap(3) = Array(1, 0, 0, 0, 2, 0, 0, 0, 0, 1) LevelMap(4) = Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 1) LevelMap(5) = Array(1, 0, 0, 1, 0, 0, 1, 0, 0, 1) LevelMap(6) = Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 1) LevelMap(7) = Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 1) LevelMap(8) = Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 1) LevelMap(9) = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1) Me.Show blnGameLoop = True While (blnGameLoop = True) Me.Cls RayCasting DoEvents Wend End Sub Private Sub Form_Unload(Cancel As Integer) blnGameLoop = False End Sub mas noto 2 erros: 1 - o efeito de peixe não foi resolvido; 2 - o que se passa com este 'while' e 'if'? Private Sub RayCasting() Dim RayAngle As Double Dim RayCos As Double Dim RaySin As Double RayAngle = PlayerAngle - PlayerFOV / 2 RayCos = Cos(DegreesToRadians(RayAngle)) / RayCastingPrecision RaySin = Sin(DegreesToRadians(RayAngle)) / RayCastingPrecision Dim RayCount As Integer For RayCount = 0 To ScreenWidth Dim RayX As Double Dim RayY As Double RayX = PlayerPosX RayY = PlayerPosY 'Detectar se atinge a parede: Dim blnWallHit As Variant blnWallHit = 0 While (blnWallHit < 1) RayX = RayX + RayCos RayY = RayY + RaySin blnWallHit = LevelMap(Fix(RayY))(Fix(RayX)) Wend 'calcular a distancia a tamanho da linha: Dim Distance As Double Distance = Sqr((PlayerPosX - RayX) ^ 2 + (PlayerPosY - RayY) ^ 2) Distance = Distance * Cos(DegreesToRadians(RayAngle - PlayerAngle)) Dim WallHeight As Double WallHeight = Fix(ScreenHalfHeight / Distance) If (WallHeight > ScreenHalfHeight) Then WallHeight = ScreenHalfHeight 'Desenhar a linha da parede: If (blnWallHit = 1) Then drawLine RayCount, ScreenHalfHeight - WallHeight, RayCount, ScreenHalfHeight + WallHeight, vbYellow ElseIf (blnWallHit = 2) Then drawLine RayCount, ScreenHalfHeight - WallHeight, RayCount, ScreenHalfHeight + WallHeight, vbGreen End If blnWallHit = 0 'Incrementar RayAngle = RayAngle + PlayerFOV / ScreenWidth Next RayCount End Sub porque não consigo meter 2 linhas verticais com cores diferentes... fica tudo de 1 cor(mesmo o anterior) :( só se os cálculos estão errados :(
  2. estou a tentar implementar o raycasting, mas ainda tenho maus resultados :( Public Sub RayCasting() Dim r As Integer Dim mx As Integer Dim my As Integer Dim mp As Integer Dim dof As Integer Dim mapx As Integer Dim mapy As Integer Dim rx As Double Dim ry As Double Dim ra As Double Dim x0 As Double Dim y0 As Double ra = PlayerAngle For r = 0 To 0.9 'Check Horizontal Lines: dof = 0 Dim aTan As Double aTan = -1 / Tan(ra) If (ra > PI) Then 'Loking up ry = BitShiftLeft(BitShiftRight(Floor(PlayerPosY), 6), 6) - 0.0001 rx = (PlayerPosX - ry) * aTan + PlayerPosX y0 = -MapResolution x0 = -y0 * aTan End If If (ra < PI) Then 'Loking down ry = BitShiftLeft(BitShiftRight(Floor(PlayerPosY), 6), 6) + MapResolution rx = (PlayerPosX - ry) * aTan + PlayerPosX y0 = MapResolution x0 = y0 * aTan End If If (ra = 0 Or ra = PI) Then 'Loking straight left or right: rx = PlayerPosX ry = PlayerPosY dof = 8 End If While (dof < 8) mx = BitShiftRight(rx, 6) my = BitShiftRight(ry, 6) mp = my * mapx + mx Debug.Print CStr(mapx) If ((mp < (mapx * mapy)) And MapLevel(mapy, mapx) = 1) Then 'hit wall dof = 8 Else rx = rx + x0 ry = ry + y0 dof = dof + 1 End If Me.Line (PlayerPosX, PlayerPosY)-(rx, ry), vbRed Wend Next End Sub este código é VB6... mas fora isso.... eu ainda não entendi como se calcula isto... alguém me pode explicar melhor?
  3. eu consigo criar 1 linha e aumentar o seu comprimento, mantendo a sua direção.. honestamente são muitos videos... alguém me pode explicar como posso calcular os comprimentos? eu percebi que usamos triangulos e Hipotenusa, mas ainda não entendi....
  4. resolvi.. muito obrigado. 'o ponto roda em torno do player: PointX = intPlayerPosX + Cos(Radians) * 100 PointY = intPlayerPosY + Sin(Radians) * 100 tenho de calcular para o Y também. este foi o mesmo erro. este calculo faz com que o Point rode em torno do player, mas com distancia de 100. este ponto serve para saber para onde o player esta virado. muito obrigado. se quiser mover um objecto\player consoante o angulo, temos de multiplicar o movimento pelo Sin(Y) e Cos(X) pelo Radiano... sim o computador usa Radianos em vez de Graus. muito obrigado por tudo
  5. ao fazer mais pesquisas eu encontrei a formula: //O X0 e Y0 são as coordenadas do centro da rotação: x' = (x-x0)*cos(a) - (y-y0)*sin(a) + x0 y' = (x-x0)*sin(a) + (y-y0)*cos(a) + y0 //eis o codigo que fiz: intPlayerAngle = intPlayerAngle + 1 Radians = (intPlayerAngle * PI) / 180 //faço a rotação(X0 e Y0 são as coordenadas do centro da rotação): //x ' = (x-x0)*cos(a) - (y-y0)*sin(a) + x0 //y ' = (x-x0)*sin(a) + (y-y0)*cos(a) + y0 PointX = (PointX - intPlayerPosX) * Cos(Radians) - (PointY - intPlayerPosY) * Sin(Radians) + intPlayerPosX PointY = (PointX - intPlayerPosX) * Sin(Radians) + (PointY - intPlayerPosY) * Cos(Radians) + intPlayerPosY as coordenadas intPlayerPosX e intPlayerPosY não estão a ser alteradas, mas o PointX e PointY foram inicializados: PointX = intPlayerPosX + 100 PointY = intPlayerPosY a pergunta: porque o centro da rotação está sempre a variar se eu nem estou a alterar as coordenadas intPlayerPosX e intPlayerPosY?
  6. tenho isto dentro de 1 ciclo, mas o raio da rotação não é constante :( //fora do loop: //o ponto roda em torno do player: PointX = intPlayerPosX + 100 //fica á frente do Player 100 pixels PointY = intPlayerPosY //dentro do loop de draw: //O PointX e PointY são os pontos do pixel que quero rodar em volta do Player... //retiro a posição do player, pois é o ceentro da rotação: PointX = PointX - intPlayerPosX PointY = PointY - intPlayerPosY //faço a rotação: PointX = PointX * Cos(Radians) - PointY * Sin(Radians) PointY = PointX * Sin(Radians) + PointY * Cos(Radians) //adiciono a posição do Player: PointX = PointX + intPlayerPosX PointY = PointY + intPlayerPosY //desenhar o pixel na posição rotacionada: DrawPixel (PointX, PointY, vbBlack) (isto não é código C, mas simplifiquei) PS: ao alterar o angulo eu já o converto para Radianos: Const Double PI = 3.14159265359 Radians = (intPlayerAngle * PI) / 180
  7. em Matemática como se roda um ponto? ao pesquisar eu notei que para calcular a rotação de 1 ponto fazemos: x’ = x . cos α - y .sin α y’ = x . sin α + y .cos α agora vamos falar de 2 pontos importantes: 1 - o computador usa Radianos e não Graus.. por isso temos de converter Graus em Radianos: PI = 3,14159265358979323846 Radians = ( Angulo* PI) / 180 2 - esta rotação usa a origem(0,0) como ponto de rotação... O que ainda estou com dificuldade em entender é: como posso rodar um ponto a partir de outro ponto?
  8. Existe alguma versão, do Windows XP, com drivers de som(mesmo que emulado.. o Windows 98 instala o SoundBlaster emulado) para MS-DOS? sem usar o DOSBox...
  9. estou a ver os videos.. muito obrigado por tudo
  10. lamento mas não encontro algumas respostas gostava de entender 1 coisa: quantas linhas(ou rotação) tenho de usar para verificar a visualização?
  11. como funciona o Raycasting? parece que usam 1 mapa 2D para desenhar o 3D.. mas ainda não entendi algumas coisas: 1 - tenho de dividir o mapa por grids de 30X30(ou isso)? 2 - para verificar onde estão as paredes, tenho de verificar se ponta da linha colide com a parede... aumento a linha pelo tamanho do grid, certo? 3 - a verificação, usando a linha, é de 180 graus?(-90 a 90) 4 - quando a linha colide com a parede: - com saber onde tocou para entender que linha, vertical, da imagem devo desenhar? - o zoom é o comprimento da linha, mas como fazer esses cálculos para poder esticar a linha? estes cálculos são dependentes da resolução do jogo?
  12. No Windows XP, como posso usar as strings nas propriedades dos atalhos do MS-DOS? a string: - "%systemroot%" me dá o caminho da pasta do Windows; - "%temp%" dá-me o caminho da pasta temp do Windows(ou penso que sim); - mas qual é a string que me dá a pasta atual?(refiro-me a pasta aberta no Explorer)
  13. muito obrigado a todos. já agora: eu mais ou menos conheço o DirectX.. mas o que é SFML? é parecida ou mais simples?
  14. ou seja: para obter rapidez gráfica ou uso Assembler ou Directx.. a funcionalidade DIB's é rápida mas limitada... e pode ser má para jogos 2D/3D simples(Wolf3d ou mesmo Duke 1)... certo?
  15. Pensando em velocidade, como posso recriar a função TransparentBlt()? Gostava de entender como esta função funciona e como pode ser rápida na execução. Será que usa DIB's ou é mesmo Assembler?
  16. eu estou a usar o SoundFX: http://www.softsystem.co.uk/products/soundfx.htm mas gostava de saber: 1 - usando linha de comandos, como o posso desativar? 2 - como desativar a janela de execução do SoundFX?(é 1 janela de informação)
  17. o EMS Magic ajuda e muito resolver esses problemas: https://www.emsmagic.com/ penso que funciona no Windows 98. e o SoundFX funciona como emulador de som.
  18. melhorei após limpar as pastas: 'temp', '%temp%' e 'prefetch'(pastas e ficheiros, alguns ficheiros estão a ser usados). muito obrigado
  19. o portatil é: E5-573G-324X ao menos é 'saudável'
  20. Fora isso, pode ser algum problema no sistema? A minha mulher tinha um problema idêntico mas o técnico resolveu sem trocar o disco. Então o problema é só disco? Uma formatação? Ou existe mais do que não sei?
  21. eu tenho o Windows 10 instalado e actualizado. e com os drivers da marca. mas no arranque demora muito... parece que demora 5 minutos a chegar ao Ambiente de trabalho.. o disco é 1 HDD... mas não deveria ser assim lento. no arranque tenho aquase tudo desativado. mas posso ter mais problemas e não saber. o que me aconselham além da formatação?(mesmo que use de baixo nivel)
  22. em MS-DOS nós escrevemos 'sod' ou 'wolf3d' para executa o jogo... mas preciso de ajuda: 1 - sei que existe 1 ficheiro que me permite executar no Windows 9X... mas o perdi alguém me pode ajudar? sim já tentei e retentei várias pesquisas sem sucesso 2 - quais são os comandos de execução do jogo? 'wolf3d -debugmode'... o meu objectivo é evitar o ecra preto.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!