Re: trigonometry in audio games, how do I apply the concept?

Depends. Generally you'd have variables to store position and rotation, and then set the listener/objects position and rotation based on those stored variables. In the case of my Minecraft Prototype, whenever the mouse is moved it stores that movement in a rotation variable, then it uses that variable to move the perspective of the window and/or listener:

    def on_mouse_motion(self, x, y, dx, dy):
        """ Called when the player moves the mouse.

        Parameters
        ----------
        x, y : int
            The coordinates of the mouse click. Always center of the screen if
            the mouse is captured.
        dx, dy : float
            The movement of the mouse.

        """
        if self.exclusive:
            m = 0.15
            x, y = self.rotation
            x, y = x + dx * m, y + dy * m
            y = max(-90, min(90, y))
            if x < -360:
                x += 360
            elif x > 360:
                x -= 360
            self.rotation = [x, y]

    def set_3d(self):
        """ Configure OpenGL to draw in 3d.

        """
        width, height = self.get_size()
        glEnable(GL_DEPTH_TEST)
        glViewport(0, 0, width, height)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(65.0, width / float(height), 0.1, 20.0)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        x, y = self.rotation
        glRotatef(x, 0, 1, 0)
        glRotatef(-y, math.cos(math.radians(x)), 0, math.sin(math.radians(x)))
        x, y, z = self.position
        glTranslatef(-x, -y, -z)

Since the position of the listener is changing, you don't really need to calculate the distance between the two, unless you want some sort of special interaction or behavior you want to trigger as a result. In the Minexcraft prototype I calculated the distance between the player and a block and adjusted the volume of a sound to represent that distance, the little bit of code for that is here:

#used to calculate distance between player and block
def calculateDistance(x1,y1,x2,y2):
    return math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : momo7807 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : momo7807 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Kyleman123 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : thggamer via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : momo7807 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : momo7807 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : momo7807 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : momo7807 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : momo7807 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : momo7807 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : lukas via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : momo7807 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : momo7807 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : stewie via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Aprone via Audiogames-reflector

Reply via email to