-
Posts
902 -
Cadastrado em
-
Última visita
Tipo de conteúdo
Artigos
Selos
Livros
Cursos
Análises
Fórum
Tudo que Cambalinho postou
-
Visual Basic Visual Basic 6: Como evitar o overflow?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
mesmo assim ainda dá erro de overloading... então, parece instavel, meti o 'on error resume next'... não é correto, mas ajuda e muito -
Visual Basic Visual Basic 6: como desenhar vários quadrados deixando 1 espaço entre eles?
Cambalinho postou um tópico em Programação - outros
imagine que temos 1 array de 8X8 de quadrados e cada quadrado tem 64 de tamanho e quer 2 pixels de espaço entre eles. agora como posso desenhar esses quadrados com espaço? Private Sub DrawMap() Dim X As Integer Dim Y As Integer Dim X0 As Integer Dim Y0 As Integer Dim Spaces As Integer 'MapResolution=64 'LevelMapHeight and LevelMapWidth are 8 Spaces = 5 For Y = 0 To LevelMapHeight - 1 For X = 0 To LevelMapWidth - 1 X0 = X * MapResolution Y0 = Y * MapResolution 'Line Method: 'Line(X0,Y0) - (X1,Y2), côr 'Square Method: 'Line(X0,Y0) - (X1,Y2), côr, BF 'X0 e Y0 é o ponto superior esquerdo e X1, Y1 é ponto inferior direito If (LevelMap(Y)(X) = 0) Then Me.Line (X0 + Spaces, Y0 + Spaces - 1)-(X0 + MapResolution - Spaces, Y0 + MapResolution - Spaces - 1), vbBlack, BF Else Me.Line (X0 + Spaces, Y0 + Spaces - 1)-(X0 + MapResolution - Spaces, Y0 + MapResolution - Spaces - 1), vbWhite, BF End If Next X Next Y o meu problema é não ter o mesmo espaço entre os quadrados e vejo isso na altura :( como posso resolver esse bug? -
Visual Basic Visual Basic 6: Como evitar o overflow?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
muito obrigado por tudo e entendi sim. é pena o VB6 ter algumas limitações de funções de Matemática e operadores bits ;) -
Visual Basic Visual Basic 6: Como evitar o overflow?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
@Diego voltei a pensar e só alterei do 'Integer' para 'Long' e já não dá o erro. no VB6 é melhor usarmos o 'Long' em vez do 'Integer'? -
Visual Basic Visual Basic 6: Como evitar o overflow?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
vendo bem eu posso ter 1 erro da calculos para fazer o RayCasting :( Private Sub RayCasting() Dim r As Integer Dim mx As Integer Dim my As Integer Dim mp As Integer Dim mapx As Double Dim mapy As Double Dim dof 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 10 'Debug.Print "raycsting" 'check Horizontal Lines: dof = 0 Dim atan As Double If (Tan(ra) > 0) Then atan = -1 / Tan(ra) Else atan = -1 End If If (ra > PI) Then ry = (CInt(ShiftLeft(ShiftRight(PlayerY, 6), 6) - 0.0001)) rx = (PlayerY - ry) * atan + PlayerX y0 = -64 x0 = -y0 * atan End If If (ra < PI) Then ry = (CLng(ShiftLeft(ShiftRight(PlayerY, 6), 6) + 64)) rx = (PlayerY - ry) * atan + PlayerX y0 = 64 x0 = -y0 * atan End If If (ra = 0 Or ra = PI) Then rx = PlayerX ry = PlayerY dof = 8 End If While (dof < 8) mx = Cnt(ShiftLeft(rx, 6)) 'overflow error my = CLng(ShiftLeft(ry, 6)) mp = mx * mapx + mx If (LevelMap(mapy)(mapx) = 1) Then dof = 8 Else rx = rx + x0 ry = ry + y0 dof = dof + 1 End If Me.Line (PlayerX, PlayerY)-(rx, ry), vbRed Wend Next r End Sub -
Visual Basic Visual Basic 6: Como evitar o overflow?
Cambalinho postou um tópico em Programação - outros
como evitar o overflow no Visual Basic 6? Function ShiftRight(ByVal lngNumber As Long, ByVal intNumBits As Integer) As Long '-------------- 'BIT SHIFT RIGHT >> '-------------- ShiftRight = lngNumber \ 2 ^ intNumBits 'note the integer division op End Function Function ShiftLeft(ByVal lngNumber As Long, ByVal intNumBits As Integer) As Long '-------------- 'BIT SHIFT LEFT << '-------------- ShiftLeft = lngNumber * 2 ^ intNumBits End Function '............ Dim mx As Integer mx = Cnt(ShiftLeft(rx, 6)) 'overflow error o 'mx' dá me o erro de overflow runtime error '6'. como posso evitar esse erro? -
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 :(
-
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?
-
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....
-
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
-
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?
-
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
-
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?
-
estou a ver os videos.. muito obrigado por tudo
-
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?
-
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?
-
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)
-
C++ Matemática: como se move 1 ponto no Espaço?
Cambalinho respondeu ao tópico de Cambalinho em C/C#/C++
muito obrigado -
C++ GDI: como posso recriar o TransparentBlt()?
Cambalinho respondeu ao tópico de Cambalinho em C/C#/C++
muito obrigado por tudo -
C++ GDI: como posso recriar o TransparentBlt()?
Cambalinho respondeu ao tópico de Cambalinho em C/C#/C++
muito obrigado a todos. já agora: eu mais ou menos conheço o DirectX.. mas o que é SFML? é parecida ou mais simples? -
C++ GDI: como posso recriar o TransparentBlt()?
Cambalinho respondeu ao tópico de Cambalinho em C/C#/C++
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? -
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?
-
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)
-
windows 98: porque o MS-DOS só detecta, mais ou menos, 555KB's of ram?
Cambalinho respondeu ao tópico de Cambalinho em Versões até Windows 8
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.
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