forum.boolean.name

forum.boolean.name (http://forum.boolean.name/index.php)
-   С# (http://forum.boolean.name/forumdisplay.php?f=128)
-   -   из C++ в C# (http://forum.boolean.name/showthread.php?t=20004)

SOmar 15.09.2015 11:14

из C++ в C#
 
Помогите перевести с С++ на С#
PHP код:

class FormationManager:

# Holds the assignment of a single character to a slot
struct SlotAssignment:      Вот это я понял
character
slotNumber

# Holds a list of slots assignments.
slotAssignments         Это скорее всего List<>

# Holds a Static structure (i.e., position and orientation)
# representing the drift offset for the currently filled
# slots.
driftOffset            Это переменная типа трансформ или вектор хотя не  уверен

# Holds the formation pattern
pattern                                     

# Updates the assignment of characters to slots
def updateSlotAssignments():

# A very simply assignment algorithm: we simply go through
# each assignment in the list and assign sequential slot
# numbers
for i in 0..slotAssignments.length():        Я так понял это цикл for но как то 
slotAssignments
[i].slotNumber i           странно записан

# Update the drift offset
driftOffset pattern.getDriftOffset(slotAssignments)

# Add a new character to the first available slot. Returns
# false if no more slots are available.
def addCharacter(character):

# Find out how many slots we have occupied
occupiedSlots slotAssignments.length()

# Check if the pattern supports more slots
if pattern.supportsSlots(occupiedSlots 1):

# Add a new slot assignment
slotAssignment = new SlotAssignment()
slotAssignment.character character
slotAssignments
.append(slotAssignment)

# Update the slot assignments and return success
updateSlotAssignments()
return 
true

# Otherwise we’ve failed to add the character
return false

# Removes a character from its slot.
def removeCharacter(character):

# Find the character’s slot
slot charactersInSlots.find(character)

# Make sure we’ve found a valid result
if slot in 0..slotAssignments.length():

# Remove the slot
slotAssignments.removeElementAt(slot)

# Update the assignments
updateSlotAssignments()

# Write new slot locations to each character
def updateSlots():

# Find the anchor point
anchor getAnchorPoint()

# Get the orientation of the anchor point as a matrix
orientationMatrix anchor.orientation.asMatrix()

# Go through each character in turn
for i in 0..slotAssignments.length():

# Ask for the location of the slot relative to the
# anchor point. This should be a Static structure
relativeLoc pattern.getSlotLocation(slotAssignments[i].slotNumber)

#Transform it by the anchor point’s position and
#orientation
location = new Static()
location.position relativeLoc.position orientationMatrix anchor.position
location
.orientation anchor.orientation relativeLoc.orientation

#    And add the drift component location.position -= driftOffset.position location.orientation -= driftOffset.orientation

#    Write the static to the character slotAssignments[i].character.setTarget(location) 


Andvrok 15.09.2015 11:47

Ответ: из C++ в C#
 
Это не С++
На питон похоже, но я не эксперт.

В любом случае, здесь нет объявлений типов "formation pattern" и "Static", это просто огрызок кода, выдранный из контекста.

UPD: Нашёл эту книжку (Artificial Intelligence for Games), цитирую:

Цитата:

Alghoritms in this book are presented in pseudo-code for brevity and simplicity.
Так что это даже не питон.

SOmar 15.09.2015 16:48

Ответ: из C++ в C#
 
Цитата:

Сообщение от Andvrok (Сообщение 299679)
Это не С++
На питон похоже, но я не эксперт.

В любом случае, здесь нет объявлений типов "formation pattern" и "Static", это просто огрызок кода, выдранный из контекста.

UPD: Нашёл эту книжку (Artificial Intelligence for Games), цитирую:



Так что это даже не питон.

Понятно! В любом случаи придумал уже свой алгоритм :P


Часовой пояс GMT +4, время: 14:46.

vBulletin® Version 3.6.5.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Перевод: zCarot