bsptracer

package
v0.0.0-...-eed3b2b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2022 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package bsptracer implements Ray-Tracing / Ray-Casting on top of github.com/Galaco/bsp. This is a port of https://github.com/ReactiioN1337/valve-bsp-parser.

Index

Examples

Constants

View Source
const (
	SolidNone     = 0
	SolidBSP      = 1
	SolidBBox     = 2
	SolidOBB      = 3
	SolidOBBYaw   = 4
	SolidCustom   = 5
	SolidVPhysics = 6
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map struct {
	// contains filtered or unexported fields
}

Map is a loaded BSP map.

func LoadMap

func LoadMap(bspfile *bsp.Bsp, vpks ...*vpk.VPK) (Map, error)

LoadMap loads a map from a BSP file and VPKs. May return MissingModelsError if models can't be found - this is not fatal and the map can still be used.

func LoadMapFromFileSystem

func LoadMapFromFileSystem(mapPath string, vpkPaths ...string) (Map, error)

LoadMapFromFileSystem loads a BSP map from the file system. vpkPaths is a list of paths to either single or multi VPKs to load models, in order of priority. for CS:GO, vpkPaths should be paths to ("SteamLibrary/steamapps/common/Counter-Strike Global Offensive/csgo/pak01", "SteamLibrary/steamapps/common/Counter-Strike Global Offensive/platform/platform_pak01") See also LoadMap()

func (Map) IsVisible

func (m Map) IsVisible(origin, destination mgl32.Vec3) bool

IsVisible returns true if destination is visible from origin, as computed by a ray trace.

Example
package main

import (
	"fmt"
	"os"

	"github.com/go-gl/mathgl/mgl32"

	"github.com/saiko-tech/bsp-tracer/pkg/bsptracer"
)

func main() {
	csgoDir := os.Getenv("CSGO_DIR") // should point to "SteamLibrary/steamapps/common/Counter-Strike Global Offensive"

	m, err := bsptracer.LoadMapFromFileSystem(csgoDir+"/csgo/maps/de_cache.bsp", csgoDir+"/csgo/pak01", csgoDir+"/platform/platform_pak01")
	if err != nil {
		panic(err)
	}

	fmt.Println("A site -> A site, open:", m.IsVisible(mgl32.Vec3{-12, 1444, 1751}, mgl32.Vec3{-233, 1343, 1751})) // true
	fmt.Println("T spawn -> A site:", m.IsVisible(mgl32.Vec3{3306, 431, 1723}, mgl32.Vec3{-233, 1343, 1751}))      // false
	fmt.Println("mid through box:", m.IsVisible(mgl32.Vec3{-94, 452, 1677}, mgl32.Vec3{138, 396, 1677}))           // false
	fmt.Println("T spawn -> T spawn:", m.IsVisible(mgl32.Vec3{3306, 431, 1723}, mgl32.Vec3{3300, 400, 1720}))      // true
}
Output:

func (Map) TraceRay

func (m Map) TraceRay(origin, destination mgl32.Vec3) *Trace

TraceRay traces a ray from origin to destination and returns the result.

type MissingModelsError

type MissingModelsError struct {
	// contains filtered or unexported fields
}

func (MissingModelsError) Error

func (m MissingModelsError) Error() string

type Trace

type Trace struct {
	AllSolid          bool
	StartSolid        bool
	Fraction          float32
	FractionLeftSolid float32
	EndPos            mgl32.Vec3
	Contents          int32
	Brush             *brush.Brush
	NumBrushSides     int32
}

Trace captures the result of a ray trace.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL