This topic is 2589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

[font="Arial"][color="#333333"]
Hello! I am developing a 2D graphics engine in Visual Basic DirectX8 and I wanted to do a query.

I came to the following system of dynamic shadows, the lighting system I have it done, would fail to handle vertex shadows.

I know they are trigonometric functions but could not achieve yet.

The video shows the effect is as follows:

Pseudo-code:

1 - Check that the distance between the light and character, so I think it would be:

Sqr (((Y1 - Y2) ^ 2 + (X1 - X2) ^ 2))[/quote]

2 - Angle Light that looks like Cut Off.

I use this function:

Public Function Engine_GetAngle(ByVal centerX As Integer, ByVal centerY As Integer, ByVal TargetX As Integer, ByVal TargetY As Integer) As Single
'************************************************************
'Gets the angle between two points in a 2d plane
'************************************************************
Dim SideA As Single
Dim SideC As Single

On Error GoTo ErrOut

'Check for horizontal lines (90 or 270 degrees)
If centerY = TargetY Then

'Check for going right (90 degrees)
If centerX < TargetX Then
Engine_GetAngle = 90

'Check for going left (270 degrees)
Else
Engine_GetAngle = 270
End If

'Exit the function
Exit Function

End If

'Check for horizontal lines (360 or 180 degrees)
If centerX = TargetX Then

'Check for going up (360 degrees)
If centerY > TargetY Then
Engine_GetAngle = 360

'Check for going down (180 degrees)
Else
Engine_GetAngle = 180
End If

'Exit the function
Exit Function

End If

'Calculate Side C
SideC = Sqr(Abs(TargetX - centerX) ^ 2 + Abs(TargetY - centerY) ^ 2)

'Side B = CenterY

'Calculate Side A
SideA = Sqr(Abs(TargetX - centerX) ^ 2 + TargetY ^ 2)

'Calculate the angle
Engine_GetAngle = (SideA ^ 2 - centerY ^ 2 - SideC ^ 2) / (centerY * SideC * -2)
Engine_GetAngle = (Atn(-Engine_GetAngle / Sqr(-Engine_GetAngle * Engine_GetAngle + 1)) + 1.5708) * 57.29583

'If the angle is >180, subtract from 360
If TargetX < centerX Then Engine_GetAngle = 360 - Engine_GetAngle

'Exit function

Exit Function

'Check for error
ErrOut:

'Return a 0 saying there was an error
Engine_GetAngle = 0

Exit Function

End Function[/quote]

Do not know if it might be possible to give me a hand with the formulas thatgo in the vertex, the textures load as follows:[/font]
[font="Arial"][color="#333333"] [/font]
[font="Arial"][color="#333333"]
' * v1 * v3
' |\ |
' | \ |
' | \ |
' | \ |
' | \|
' * v0 * v2
Thank you very much everyone for your time!

[font="Arial"][color="#333333"] [/font]
[font="Arial"][color="#333333"]POST ORIGINAL EN ESPAÑOL:[/font]
[font="Arial"][color="#333333"]

Hola! Estoy desarrollando un motor gráfico en 2D con DirectX8 en Visual Basic y les quería hacer una consulta.

Se me ocurrió hacer el siguiente sistema de sombras dinámicas, el sistema de luces ya lo tengo hecho, faltaría manejar los vertex para hacer las sombras.

Sé que son funciones trigonométricas pero no lo pude lograr aún.

El video que muestra el efecto es el siguiente:

Pseudo-código:

1 - Averiguar que distancia hay entre la luz y el personaje, sería así creo:

Sqr(((Y1 - Y2) ^ 2 + (X1 - X2) ^ 2))

2 - Angulo al que mira la Luz estilo Cut Off.

Utilizo esta función:

No se si podría ser posible que me den una mano con las fórmulas que irían en los vertex, las texturas las carga de la siguiente manera:

Muchas gracias a todos por su tiempo!

[/font]

##### Share on other sites
I removed the embedded YouTube, as it was generating a page redirect for some reason.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633704
• Total Posts
3013460
×